line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Fedora::Packages; |
2
|
2
|
|
|
2
|
|
2020
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
917
|
use Archive::Extract; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use XML::Simple qw(XMLin); |
7
|
|
|
|
|
|
|
use Data::Dumper qw(Dumper); |
8
|
|
|
|
|
|
|
use Carp qw(); |
9
|
|
|
|
|
|
|
use LWP::UserAgent; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Parse::Fedora::Packages - Parse Fedora package information |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Parse::Fedora::Packages; |
21
|
|
|
|
|
|
|
my $p = Parse::Fedora::Packages->new; |
22
|
|
|
|
|
|
|
$p->parse_primary("primary.xml"); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @all = $p->list_packages(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
print $all[0]->{name}; |
27
|
|
|
|
|
|
|
print $all[0]->{version}; |
28
|
|
|
|
|
|
|
print $all[0]->{summary}; |
29
|
|
|
|
|
|
|
print $all[0]->{description}; |
30
|
|
|
|
|
|
|
print $all[0]->{url}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Constructor |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $p = Parse::Fedora::Packages->new |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my ($class) = @_; |
47
|
|
|
|
|
|
|
my $self = bless {}, $class; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 parse_primary |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Given a primary.xml file it will read it into memory and parse it. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Returns nothing. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Throws exception if the file is invalid xml. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$p->parse_primary("primary.xml"); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub parse_primary { |
65
|
|
|
|
|
|
|
my ($self, $filename) = @_; |
66
|
|
|
|
|
|
|
#if (-e $filename |
67
|
|
|
|
|
|
|
$self->{xml} = XMLin($filename, ForceArray => 1, KeyAttr => []); |
68
|
|
|
|
|
|
|
# keys of xml: packages, xmlns, xmlns:rpm package |
69
|
|
|
|
|
|
|
# value of package is an array |
70
|
|
|
|
|
|
|
#print "$xml->{package}\n"; |
71
|
|
|
|
|
|
|
#print join "\n", keys %{ $xml->{packages} }; |
72
|
|
|
|
|
|
|
#print Dumper $self->{xml}->{package}; |
73
|
|
|
|
|
|
|
#print join "\n", @{ $xml->{package} }; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 parse_primary_gz |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Given a primary.xml.gz file it will read it into memory and parse it. If a URL is passed as argument, it will download it. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns nothing. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$p->parse_primary_gz('primary.xml'); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Or |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$p->parse_primary_gz('http://mirror.yandex.ru/fedora/tigro/non-free/11/i386/repodata/primary.xml.gz'); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub parse_primary_gz { |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my ($self, $gz) = @_; |
95
|
|
|
|
|
|
|
my $gz_file; |
96
|
|
|
|
|
|
|
if ($gz =~ /^(?:https?)|(?:ftps?):\/\//) { |
97
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
98
|
|
|
|
|
|
|
$ua->agent("Parse::Fedora::Packages $VERSION"); |
99
|
|
|
|
|
|
|
($gz_file) = $gz =~ /.+\/(.*?\.gz)$/; |
100
|
|
|
|
|
|
|
my $response = $ua->get($gz,':content_file' => $gz_file); # File is created here |
101
|
|
|
|
|
|
|
if (!$response->is_success) { Carp::croak $response->status_line; } |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
else { $gz_file = $gz; } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $ae = Archive::Extract->new( archive => $gz_file); |
107
|
|
|
|
|
|
|
my $ok = $ae->extract or Carp::croak $ae->error; |
108
|
|
|
|
|
|
|
my $file_list = $ae->files; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $xml_file = @$file_list[0]; |
111
|
|
|
|
|
|
|
$self->{xml} = XMLin($xml_file, ForceArray => 1, KeyAttr => []); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
### Cleaning up mess |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
unlink($gz_file); |
116
|
|
|
|
|
|
|
for (@$file_list) { unlink $_; } |
117
|
|
|
|
|
|
|
return; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 reported_count_packages |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
returns list of packages (sub xml) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub reported_count_packages { |
133
|
|
|
|
|
|
|
my ($self) = @_; |
134
|
|
|
|
|
|
|
return $self->{xml}{packages}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 count_packages |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
returns number of packages |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub count_packages { |
144
|
|
|
|
|
|
|
my ($self) = @_; |
145
|
|
|
|
|
|
|
return scalar @{ $self->{xml}{package} }; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=begin doc |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
{ |
152
|
|
|
|
|
|
|
'location' => [ |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
'href' => 'Fedora/RPMS/perl-IO-Socket-INET6-2.51-2.fc6.noarch.rpm' |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
], |
157
|
|
|
|
|
|
|
'time' => [ |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
'file' => '1160093979', |
160
|
|
|
|
|
|
|
'build' => '1152725912' |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
], |
163
|
|
|
|
|
|
|
'version' => [ |
164
|
|
|
|
|
|
|
{ |
165
|
|
|
|
|
|
|
'rel' => '2.fc6', |
166
|
|
|
|
|
|
|
'epoch' => '0', |
167
|
|
|
|
|
|
|
'ver' => '2.51' |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
], |
170
|
|
|
|
|
|
|
'arch' => [ |
171
|
|
|
|
|
|
|
'noarch' |
172
|
|
|
|
|
|
|
], |
173
|
|
|
|
|
|
|
'name' => [ |
174
|
|
|
|
|
|
|
'perl-IO-Socket-INET6' |
175
|
|
|
|
|
|
|
], |
176
|
|
|
|
|
|
|
'packager' => [ |
177
|
|
|
|
|
|
|
'Red Hat, Inc. ' |
178
|
|
|
|
|
|
|
], |
179
|
|
|
|
|
|
|
'description' => [ |
180
|
|
|
|
|
|
|
'Perl Object interface for AF_INET|AF_INET6 domain sockets' |
181
|
|
|
|
|
|
|
], |
182
|
|
|
|
|
|
|
'size' => [ |
183
|
|
|
|
|
|
|
{ |
184
|
|
|
|
|
|
|
'archive' => '23524', |
185
|
|
|
|
|
|
|
'installed' => '22457', |
186
|
|
|
|
|
|
|
'package' => '13579' |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
], |
189
|
|
|
|
|
|
|
'checksum' => [ |
190
|
|
|
|
|
|
|
{ |
191
|
|
|
|
|
|
|
'pkgid' => 'YES', |
192
|
|
|
|
|
|
|
'content' => '2bd89bfbb33a979ed0555c4def384dfe58d5f989', |
193
|
|
|
|
|
|
|
'type' => 'sha' |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
], |
196
|
|
|
|
|
|
|
'format' => [ |
197
|
|
|
|
|
|
|
{ |
198
|
|
|
|
|
|
|
'rpm:provides' => [ |
199
|
|
|
|
|
|
|
{ |
200
|
|
|
|
|
|
|
'rpm:entry' => [ |
201
|
|
|
|
|
|
|
{ |
202
|
|
|
|
|
|
|
'epoch' => '0', |
203
|
|
|
|
|
|
|
'flags' => 'EQ', |
204
|
|
|
|
|
|
|
'ver' => '2.51', |
205
|
|
|
|
|
|
|
'name' => 'perl(IO::Socket::INET6)' |
206
|
|
|
|
|
|
|
}, |
207
|
|
|
|
|
|
|
{ |
208
|
|
|
|
|
|
|
'rel' => '2.fc6', |
209
|
|
|
|
|
|
|
'epoch' => '0', |
210
|
|
|
|
|
|
|
'flags' => 'EQ', |
211
|
|
|
|
|
|
|
'ver' => '2.51', |
212
|
|
|
|
|
|
|
'name' => 'perl-IO-Socket-INET6' |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
] |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
], |
217
|
|
|
|
|
|
|
'rpm:buildhost' => [ |
218
|
|
|
|
|
|
|
'ia64-1.build.redhat.com' |
219
|
|
|
|
|
|
|
], |
220
|
|
|
|
|
|
|
'rpm:vendor' => [ |
221
|
|
|
|
|
|
|
'Red Hat, Inc.' |
222
|
|
|
|
|
|
|
], |
223
|
|
|
|
|
|
|
'rpm:license' => [ |
224
|
|
|
|
|
|
|
'Artistic or GPL' |
225
|
|
|
|
|
|
|
], |
226
|
|
|
|
|
|
|
'rpm:group' => [ |
227
|
|
|
|
|
|
|
'Development/Libraries' |
228
|
|
|
|
|
|
|
], |
229
|
|
|
|
|
|
|
'rpm:requires' => [ |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
'rpm:entry' => [ |
232
|
|
|
|
|
|
|
{ |
233
|
|
|
|
|
|
|
'name' => 'perl(:MODULE_COMPAT_5.8.8)' |
234
|
|
|
|
|
|
|
}, |
235
|
|
|
|
|
|
|
{ |
236
|
|
|
|
|
|
|
'rel' => '1', |
237
|
|
|
|
|
|
|
'epoch' => '0', |
238
|
|
|
|
|
|
|
'flags' => 'LE', |
239
|
|
|
|
|
|
|
'pre' => '1', |
240
|
|
|
|
|
|
|
'ver' => '4.0', |
241
|
|
|
|
|
|
|
'name' => 'rpmlib(PayloadFilesHavePrefix)' |
242
|
|
|
|
|
|
|
}, |
243
|
|
|
|
|
|
|
{ |
244
|
|
|
|
|
|
|
'name' => 'perl(Exporter)' |
245
|
|
|
|
|
|
|
}, |
246
|
|
|
|
|
|
|
{ |
247
|
|
|
|
|
|
|
'rel' => '1', |
248
|
|
|
|
|
|
|
'epoch' => '0', |
249
|
|
|
|
|
|
|
'flags' => 'LE', |
250
|
|
|
|
|
|
|
'pre' => '1', |
251
|
|
|
|
|
|
|
'ver' => '3.0.3', |
252
|
|
|
|
|
|
|
'name' => 'rpmlib(VersionedDependencies)' |
253
|
|
|
|
|
|
|
}, |
254
|
|
|
|
|
|
|
{ |
255
|
|
|
|
|
|
|
'name' => 'perl(Socket6)' |
256
|
|
|
|
|
|
|
}, |
257
|
|
|
|
|
|
|
{ |
258
|
|
|
|
|
|
|
'name' => 'perl(Carp)' |
259
|
|
|
|
|
|
|
}, |
260
|
|
|
|
|
|
|
{ |
261
|
|
|
|
|
|
|
'name' => 'perl(IO::Socket)' |
262
|
|
|
|
|
|
|
}, |
263
|
|
|
|
|
|
|
{ |
264
|
|
|
|
|
|
|
'name' => 'perl(Errno)' |
265
|
|
|
|
|
|
|
}, |
266
|
|
|
|
|
|
|
{ |
267
|
|
|
|
|
|
|
'rel' => '1', |
268
|
|
|
|
|
|
|
'epoch' => '0', |
269
|
|
|
|
|
|
|
'flags' => 'LE', |
270
|
|
|
|
|
|
|
'pre' => '1', |
271
|
|
|
|
|
|
|
'ver' => '3.0.4', |
272
|
|
|
|
|
|
|
'name' => 'rpmlib(CompressedFileNames)' |
273
|
|
|
|
|
|
|
}, |
274
|
|
|
|
|
|
|
{ |
275
|
|
|
|
|
|
|
'name' => 'perl(Socket)' |
276
|
|
|
|
|
|
|
}, |
277
|
|
|
|
|
|
|
{ |
278
|
|
|
|
|
|
|
'name' => 'perl(strict)' |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
] |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
], |
283
|
|
|
|
|
|
|
'rpm:sourcerpm' => [ |
284
|
|
|
|
|
|
|
'perl-IO-Socket-INET6-2.51-2.fc6.src.rpm' |
285
|
|
|
|
|
|
|
], |
286
|
|
|
|
|
|
|
'rpm:header-range' => [ |
287
|
|
|
|
|
|
|
{ |
288
|
|
|
|
|
|
|
'end' => '3228', |
289
|
|
|
|
|
|
|
'start' => '440' |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
] |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
], |
294
|
|
|
|
|
|
|
'summary' => [ |
295
|
|
|
|
|
|
|
'Perl Object interface for AF_INET|AF_INET6 domain sockets' |
296
|
|
|
|
|
|
|
], |
297
|
|
|
|
|
|
|
'url' => [ |
298
|
|
|
|
|
|
|
'http://search.cpan.org/~mondejar/IO-Socket-INET6/' |
299
|
|
|
|
|
|
|
], |
300
|
|
|
|
|
|
|
'type' => 'rpm' |
301
|
|
|
|
|
|
|
}, |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=end doc |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub list_packages { |
308
|
|
|
|
|
|
|
my ($self, %args) = @_; |
309
|
|
|
|
|
|
|
my $name = qr//; |
310
|
|
|
|
|
|
|
if ($args{name}) { |
311
|
|
|
|
|
|
|
if (ref $args{name}) { |
312
|
|
|
|
|
|
|
if (ref($args{name}) eq 'REF') { |
313
|
|
|
|
|
|
|
$name = $args{name}; |
314
|
|
|
|
|
|
|
} else { |
315
|
|
|
|
|
|
|
Carp::croak("name must be either a simple string or a regular expression created by qr//"); |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
} else { |
318
|
|
|
|
|
|
|
$name = qr/$args{name}/; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
#return grep { print STDERR "$_->{name}[0]\n" } @{ $self->{xml}{package} }; |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
return map { { |
324
|
|
|
|
|
|
|
name => $_->{name}[0], |
325
|
|
|
|
|
|
|
version => $_->{version}[0]{ver}, |
326
|
|
|
|
|
|
|
description => eval { |
327
|
|
|
|
|
|
|
$_->{description}[0] =~ s/\n/\ /g; |
328
|
|
|
|
|
|
|
return $_->{description}[0]; |
329
|
|
|
|
|
|
|
}, |
330
|
|
|
|
|
|
|
summary => $_->{summary}[0], |
331
|
|
|
|
|
|
|
url => $_->{url}[0], |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
} } |
334
|
|
|
|
|
|
|
grep { $_->{name}[0] =~ /$name/ } @{ $self->{xml}{package} }; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=head1 WARNING |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
This is an alpha relese, The API will change. |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 TODO |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Provide parse_primary_gz("primary.xml.gz"); |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 AUTHORS |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
Gabor Szabo, Egabor@pti.co.ilE |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Currently maintained by rarbox, Erarbox@cpan.orgE |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head1 COPYRIGHT |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Copyright (C) 2007-2008 Gabor Szabo . All Rights Reserverd. |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head1 SEE ALSO |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
L, L, L |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=cut |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
1; |