equal
deleted
inserted
replaced
|
1 #!/usr/bin/perl -w |
|
2 use XML::Simple; |
|
3 |
|
4 my $file = shift || die "Usage: $0 [install.rdf|somefile.xpi]\n"; |
|
5 my $xml; |
|
6 |
|
7 if ($file =~ /\.xpi$/) { |
|
8 use Archive::Zip qw/:ERROR_CODES :CONSTANTS/; |
|
9 my $zip = Archive::Zip->new(); |
|
10 if ( $zip->read($file) != AZ_OK ) { |
|
11 die "zip file read error\n"; |
|
12 } |
|
13 my $data = $zip->contents("install.rdf"); |
|
14 die "missing install.rdf in $file\n" unless $data; |
|
15 $xml = XMLin($data) || die "$!\n"; |
|
16 } elsif ($file =~ /install.rdf/) { |
|
17 $xml = XMLin($file) || die "$!\n"; |
|
18 } else { |
|
19 die "unsupported file format\n"; |
|
20 } |
|
21 |
|
22 my $desc; |
|
23 for my $tag (qw/RDF:Description Description/) { |
|
24 if (exists $xml->{$tag}) { |
|
25 if (ref $xml->{$tag} eq 'ARRAY') { |
|
26 $desc = $xml->{$tag}; |
|
27 } else { |
|
28 $desc = [ $xml->{$tag} ]; |
|
29 } |
|
30 } |
|
31 } |
|
32 |
|
33 my $uuid; |
|
34 my $id; |
|
35 for my $x (@$desc) { |
|
36 if ($x->{"em:id"} =~ /{[[:xdigit:]]+-/) { |
|
37 print STDERR "Warning: multiple uuids!\n" if defined $uuid; |
|
38 $uuid = $x->{"em:id"}; |
|
39 } elsif ($x->{"em:id"} =~ /@/) { |
|
40 print STDERR "Warning: multiple ids!\n" if defined $id; |
|
41 $id = $x->{"em:id"}; |
|
42 } |
|
43 } |
|
44 |
|
45 if (defined $id) { |
|
46 print "$id\n"; |
|
47 } elsif (defined $uuid) { |
|
48 print "$uuid\n"; |
|
49 } else { |
|
50 exit 1; |
|
51 } |