annotate translate.pl @ 7:29309bc8d932

initial objects to work with bugzilla web service
author cin
date Fri, 04 Sep 2015 19:41:28 +0300
parents 2a5f38eb25a9
children cc7244ab1b9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
1 #!/usr/bin/perl -w
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
2
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
3 use JSON;
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
4 use YAML::XS qw(LoadFile Dump);
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
5 use URI;
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
6 use XML::Writer;
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
7 use IPC::Run qw(start finish);
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
8
1
d1400de5832b improved xsl
cin
parents: 0
diff changeset
9 our @ClassPath = qw(
d1400de5832b improved xsl
cin
parents: 0
diff changeset
10 /usr/share/java/xalan-j2-serializer.jar
d1400de5832b improved xsl
cin
parents: 0
diff changeset
11 /usr/share/java/xalan-j2.jar
d1400de5832b improved xsl
cin
parents: 0
diff changeset
12 /usr/share/java/xerces-j2.jar
d1400de5832b improved xsl
cin
parents: 0
diff changeset
13 /usr/share/java/xml-commons-resolver.jar
d1400de5832b improved xsl
cin
parents: 0
diff changeset
14 .
d1400de5832b improved xsl
cin
parents: 0
diff changeset
15 );
d1400de5832b improved xsl
cin
parents: 0
diff changeset
16
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
17 my $config = LoadFile("config.yaml");
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
18
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
19 if ( !( $config->{bugzilla}{url} =~ /\/$/ ) ) {
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
20 $config->{bugzilla}{url} .= "/";
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
21 }
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
22
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
23 my $bz = BzRest->new(
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
24 url => $config->{bugzilla}{url},
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
25 apikey => $config->{bugzilla}{apikey}
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
26 );
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
27
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
28 my @fields = qw(
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
29 id
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
30 summary
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
31 creation_time
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
32 last_change_time
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
33 creator
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
34 assigned_to
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
35
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
36 status
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
37 resolution
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
38
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
39 priority
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
40 severity
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
41 url
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
42
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
43 blocks
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
44 depends_on
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
45 cc
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
46
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
47 component
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
48 product
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
49 classification
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
50 version
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
51
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
52 actual_time
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
53 estimated_time
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
54 remainig_time
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
55 deadline
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
56 );
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
57
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
58 my %fieldsMap = (
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
59 summary => 'short_desc',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
60 id => 'bug_id',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
61 creator => 'reporter',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
62 status => 'bug_status',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
63 severity => 'bug_severity',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
64 blocks => 'blocked',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
65 depends_on => 'dependson',
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
66 creation_time => 'creation_ts',
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
67 last_change_time => 'delta_ts'
1
d1400de5832b improved xsl
cin
parents: 0
diff changeset
68 );
0
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
69
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
70 local (*HIN);
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
71
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
72 my $proc = start( [ 'saxon8', '-novw', '-', 'bug-list.xsl' ],
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
73 '<pipe', \*HIN, '>', \*STDOUT )
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
74 or die "failed to create pipe: $!";
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
75
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
76 my $writer = XML::Writer->new( OUTPUT => \*HIN, ENCODING => 'utf-8' );
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
77
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
78 $writer->xmlDecl("UTF-8");
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
79 $writer->startTag("bugzilla");
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
80
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
81 my %visited;
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
82 my @queue = (283);
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
83
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
84 while (@queue) {
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
85 @queue = grep not( $visited{$_}++ ), @queue;
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
86
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
87 last unless @queue;
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
88
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
89 print "#Fetching: ", join( ', ', @queue ), "\n";
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
90
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
91 my $bugs = $bz->GetBugs( { ids => \@queue } );
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
92
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
93 @queue = ();
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
94
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
95 foreach my $bug (@$bugs) {
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
96
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
97 push @queue, @{ $bug->{depends_on} }
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
98 if ( $bug->{depends_on} );
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
99
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
100 $writer->startTag("bug");
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
101 foreach my $field (@fields) {
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
102 next unless $bug->{$field};
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
103
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
104 my $tagName = $fieldsMap{$field} || $field;
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
105 my @values =
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
106 ref( $bug->{$field} )
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
107 && ref( $bug->{$field} ) eq 'ARRAY'
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
108 ? @{ $bug->{$field} }
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
109 : $bug->{$field};
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
110
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
111 foreach my $v (@values) {
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
112 $writer->dataElement( $tagName, $v );
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
113 }
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
114 }
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
115 $writer->endTag();
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
116
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
117 }
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
118 }
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
119
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
120 $writer->endTag();
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
121
6
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
122 close HIN;
2a5f38eb25a9 migrated to saxon8 as xslt processor
cin
parents: 5
diff changeset
123 finish($proc);
5
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
124
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
125 package BzRest;
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
126
d2efec56373f working buglist transform and bugs fetching
cin
parents: 1
diff changeset
127
0
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
128
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
129 __END__
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
130
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
131 =pod
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
132
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
133 =head1 NAME
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
134
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
135 C<translate.pl> - translates bugzilla xml buglist to TaskJuggler format
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
136
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
137 =head1 METHODS
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
138
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
139 =head2 xalan(%args)
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
140
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
141 =over
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
142
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
143 =item * -IN
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
144
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
145 Input file
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
146
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
147 =item * -OUT
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
148
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
149 Output file
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
150
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
151 =item * -XSL
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
152
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
153 XSLT file
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
154
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
155 =back
8cae44c166d3 initial xslt and sample xml
cin
parents:
diff changeset
156
1
d1400de5832b improved xsl
cin
parents: 0
diff changeset
157 =cut