- Recognize <Description> XML tags with arbitrary namespace
prefixes OBS-URL: https://build.opensuse.org/package/show/mozilla:addons/mozaddon-devel?expand=0&rev=4
This commit is contained in:
parent
190cf8d02d
commit
81a4534b9d
@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed Aug 5 09:41:47 UTC 2015 - jengelh@inai.de
|
||||
|
||||
- Recognize <Description> XML tags with arbitrary namespace
|
||||
prefixes
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Mon Apr 1 20:36:52 UTC 2013 - jengelh@inai.de
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# spec file for package mozaddon-devel
|
||||
#
|
||||
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
|
||||
#
|
||||
# All modifications and additions to the file contributed by third parties
|
||||
# remain the property of their copyright owners, unless otherwise agreed
|
||||
|
@ -3,53 +3,82 @@
|
||||
# authored by Jan Engelhardt, 2011-03-24
|
||||
# released into the Public Domain
|
||||
#
|
||||
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
|
||||
use XML::Simple;
|
||||
&main();
|
||||
|
||||
my $file = shift || die "Usage: $0 [install.rdf|somefile.xpi]\n";
|
||||
my $xml;
|
||||
sub get_rdf
|
||||
{
|
||||
my $file = shift @_;
|
||||
|
||||
if ($file =~ /\.xpi$/) {
|
||||
use Archive::Zip qw/:ERROR_CODES :CONSTANTS/;
|
||||
my $zip = Archive::Zip->new();
|
||||
if ( $zip->read($file) != AZ_OK ) {
|
||||
die "zip file read error\n";
|
||||
if ($file eq "install.rdf") {
|
||||
return XMLin($file);
|
||||
}
|
||||
if (substr($file, -4, 4) eq ".xpi") {
|
||||
my $zip = Archive::Zip->new();
|
||||
if ($zip->read($file) != AZ_OK) {
|
||||
die "zip file read error\n";
|
||||
}
|
||||
my $data = $zip->contents("install.rdf");
|
||||
die "missing install.rdf in $file\n" unless $data;
|
||||
return XMLin($data);
|
||||
}
|
||||
my $data = $zip->contents("install.rdf");
|
||||
die "missing install.rdf in $file\n" unless $data;
|
||||
$xml = XMLin($data) || die "$!\n";
|
||||
} elsif ($file =~ /install.rdf/) {
|
||||
$xml = XMLin($file) || die "$!\n";
|
||||
} else {
|
||||
die "unsupported file format\n";
|
||||
}
|
||||
|
||||
my $desc;
|
||||
for my $tag (qw/RDF:Description Description/) {
|
||||
if (exists $xml->{$tag}) {
|
||||
if (ref $xml->{$tag} eq 'ARRAY') {
|
||||
$desc = $xml->{$tag};
|
||||
} else {
|
||||
$desc = [ $xml->{$tag} ];
|
||||
sub get_desc
|
||||
{
|
||||
my $xml = shift @_;
|
||||
my $desc;
|
||||
foreach my $tag (keys %$xml) {
|
||||
if ($tag !~ m{^(\w+:)?Description$}) {
|
||||
next;
|
||||
}
|
||||
if (ref($xml->{$tag}) eq "ARRAY") {
|
||||
return $xml->{$tag};
|
||||
}
|
||||
return [$xml->{$tag}];
|
||||
}
|
||||
}
|
||||
|
||||
sub get_id
|
||||
{
|
||||
my $desc = shift @_;
|
||||
my $id;
|
||||
|
||||
foreach (qw(id em:id)) {
|
||||
if (exists($desc->{$_})) {
|
||||
$id = $desc->{$_};
|
||||
last;
|
||||
}
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
my $uuid;
|
||||
my $id;
|
||||
for my $x (@$desc) {
|
||||
if ($x->{"em:id"} =~ /{[[:xdigit:]]+-/) {
|
||||
print STDERR "Warning: multiple uuids!\n" if defined $uuid;
|
||||
$uuid = $x->{"em:id"};
|
||||
} elsif ($x->{"em:id"} =~ /@/) {
|
||||
print STDERR "Warning: multiple ids!\n" if defined $id;
|
||||
$id = $x->{"em:id"};
|
||||
sub main
|
||||
{
|
||||
my $file = shift @ARGV;
|
||||
if (!defined($file)) {
|
||||
print "Usage: $0 {install.rdf|something.xpi}\n";
|
||||
exit 1;
|
||||
}
|
||||
my $xml = get_rdf($file);
|
||||
if (!defined($xml)) {
|
||||
die "xml: $!\n";
|
||||
}
|
||||
my $desc_list = &get_desc($xml);
|
||||
my $id;
|
||||
foreach my $one_desc (@$desc_list) {
|
||||
my $value = &get_id($one_desc);
|
||||
if ($value =~ /\@|{[[:xdigit:]]+-/) {
|
||||
if (defined($id)) {
|
||||
print STDERR "Warning: multiple IDs/UUIDs!\n";
|
||||
}
|
||||
$id = $value;
|
||||
}
|
||||
}
|
||||
if (!defined($id)) {
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $id) {
|
||||
print "$id\n";
|
||||
} elsif (defined $uuid) {
|
||||
print "$uuid\n";
|
||||
} else {
|
||||
exit 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user