Skip to content

Instantly share code, notes, and snippets.

@seddi
Created August 11, 2011 19:24
Show Gist options
  • Save seddi/1140520 to your computer and use it in GitHub Desktop.
Save seddi/1140520 to your computer and use it in GitHub Desktop.
Pisi pspec.xml dosyasından paket bagımlılıklarını versiyonları ile beraber parse ederek gosterir.
#!/usr/bin/perl -w
package Build::Pisi;
use Data::Dumper;
use strict;
sub parsexml {
my ($xml) = @_;
my @nodestack;
my $node = {};
my $c = '';
$xml =~ s/^\s*\<\?.*?\?\>//s;
while ($xml =~ /^(.*?)\</s) {
if ($1 ne '') {
$c .= $1;
$xml = substr($xml, length($1));
}
if (substr($xml, 0, 4) eq '<!--') {
$xml =~ s/.*?-->//s;
next;
}
die("bad xml\n") unless $xml =~ /(.*?\>)/s;
my $tag = $1;
$xml = substr($xml, length($tag));
my $mode = 0;
if ($tag =~ s/^\<\///s) {
chop $tag;
$mode = 1; # end
} elsif ($tag =~ s/\/\>$//s) {
$mode = 2; # start & end
$tag = substr($tag, 1);
} else {
$tag = substr($tag, 1);
chop $tag;
}
my @tag = split(/(=(?:\"[^\"]*\"|\'[^\']*\'|[^\"\s]*))?\s+/, "$tag ");
$tag = shift @tag;
shift @tag;
push @tag, undef if @tag & 1;
my %atts = @tag;
for (values %atts) {
next unless defined $_;
s/^=\"([^\"]*)\"$/=$1/s or s/^=\'([^\']*)\'$/=$1/s;
s/^=//s;
s/&lt;/</g;
s/&gt;/>/g;
s/&amp;/&/g;
s/&apos;/\'/g;
s/&quot;/\"/g;
}
if ($mode == 0 || $mode == 2) {
my $n = {};
push @{$node->{$tag}}, $n;
for (sort keys %atts) {
$n->{$_} = $atts{$_};
}
if ($mode == 0) {
push @nodestack, [ $tag, $node, $c ];
$c = '';
$node = $n;
}
} else {
die("element '$tag' closes without open\n") unless @nodestack;
die("element '$tag' closes, but I expected '$nodestack[-1]->[0]'\n") unless $nodestack[-1]->[0] eq $tag;
$c =~ s/^\s*//s;
$c =~ s/\s*$//s;
$node->{'_content'} = $c if $c ne '';
$node = $nodestack[-1]->[1];
$c = $nodestack[-1]->[2];
pop @nodestack;
}
}
$c .= $xml;
$c =~ s/^\s*//s;
$c =~ s/\s*$//s;
$node->{'_content'} = $c if $c ne '';
return $node;
}
sub unify {
my %h = map {$_ => 1} @_;
return grep(delete($h{$_}), @_);
}
sub pisiparse {
my ($xml) = @_;
my @packdeps;
my $ret = {};
my @keys;
my @values;
my $val;
my %hash = ('version' => '=', 'versionFrom' => '>=', 'versionTo' => '<=');
# Parse XML file using internal parser
my $pspec = parsexml($xml);
$pspec = $pspec ->{'PISI'}->[0];
if ($pspec->{'Source'}) {
my $source = (($pspec->{'Source'} || [])->[0] || {});
# Get BuildDependencies
my @build_deps;
@build_deps = @{$source->{'BuildDependencies'}->[0]->{'Dependency'}};
foreach my $deps (@build_deps){
while( my ($k, $v) = each %$deps) {
if (my $opr = $hash{$k}){
pop @keys;
$val = (pop @values)." ".$opr." ".$v;
push @packdeps, $val;
}
else{
push @keys, $k;
push @values, $v;
}
}
}
foreach my $value (@values){
push @packdeps, $value;
}
}
@packdeps = sort(@packdeps);
print Dumper(@packdeps);
$ret->{'deps'} = [ unify(@packdeps) ];
return $ret;
}
# Read xml file and parse using pisiparse subroutine
sub parse {
my ($fn) = @_;
local *F;
open(F, '<', $fn) || die("$fn: $!\n");
my $xml = '';
1 while sysread(F, $xml, 4096, length($xml)) > 0;
close F;
my $d;
eval {
$d = pisiparse($xml);
};
if ($@) {
my $err = $@;
$err =~ s/^\n$//s;
return {'error' => $err};
}
return $d;
}
parse("pspec.xml");
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pardus.org.tr/projeler/pisi/pisi-spec.dtd">
<PISI>
<Source>
<Name>elementary</Name>
<Homepage>http://trac.enlightenment.org/e/wiki/Elementary</Homepage>
<Packager>
<Name>H. İbrahim Güngör</Name>
<Email>[email protected]</Email>
</Packager>
<License>BSD</License>
<IsA>app:gui</IsA>
<IsA>library</IsA>
<Summary>Enlightenment widget set for touch screen devices</Summary>
<Description>Elementary is a basic widget set that is easy to use with EFL for mobile touch screen devices.</Description>
<!--<Archive sha1sum="01d36732a2dc32472eb7132914b777922cee49f5" type="tarbz2">http://cekirdek.pardus.org.tr/~ibrahim/dist/efl/elementary-0.7.0_52995.tar.bz2</Archive>-->
<Archive sha1sum="bde5f743edd971974e0cbd0cf8adc4515b762ebb" type="tarbz2">http://download.enlightenment.org/snapshots/2010-12-03/elementary-0.7.0.55225.tar.bz2</Archive>
<BuildDependencies>
<Dependency versionFrom="1.0.0_beta3">eina-devel</Dependency>
<Dependency versionFrom="1.4.0_beta3">eet-devel</Dependency>
<Dependency>evas-devel</Dependency>
<Dependency versionFrom="1.0.0_beta3">ecore-devel</Dependency>
<Dependency versionTo="1.0.0_beta3">edje-devel</Dependency>
<Dependency versionFrom="1.0.0_beta3">efreet-devel</Dependency>
<Dependency versionTo="1.0.0_beta3">eft-devel</Dependency>
<Dependency versionFrom="1.0.0_beta3">e_dbus-devel</Dependency>
<Dependency>ethumb-devel</Dependency>
</BuildDependencies>
</Source>
<Package>
<Name>elementary</Name>
<RuntimeDependencies>
<Dependency versionFrom="1.0.0_beta3">eina</Dependency>
<Dependency versionFrom="1.4.0_beta3">eet</Dependency>
<Dependency versionFrom="1.0.0_beta3">evas</Dependency>
<Dependency versionFrom="1.0.0_beta3">ecore</Dependency>
<Dependency versionFrom="1.0.0_beta3">edje</Dependency>
<Dependency versionFrom="1.0.0_beta3">efreet</Dependency>
<Dependency versionFrom="1.0.0_beta3">e_dbus</Dependency>
<Dependency versionFrom="0.1.1_55225">ethumb</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="executable">/usr/bin</Path>
<Path fileType="library">/usr/lib</Path>
<Path fileType="data">/usr/share/applications</Path>
<Path fileType="data">/usr/share/elementary</Path>
<Path fileType="data">/usr/share/icons</Path>
<Path fileType="doc">/usr/share/doc</Path>
</Files>
</Package>
<Package>
<Name>elementary-devel</Name>
<Summary>Development files for elementary</Summary>
<RuntimeDependencies>
<Dependency versionFrom="1.0.0_beta2">eina-devel</Dependency>
<Dependency versionFrom="1.4.0_beta2">eet-devel</Dependency>
<Dependency versionFrom="1.0.0_beta2">evas-devel</Dependency>
<Dependency versionFrom="1.0.0_beta2">ecore-devel</Dependency>
<Dependency versionFrom="1.0.0_beta2">edje-devel</Dependency>
<Dependency versionFrom="1.0.0_beta2">efreet-devel</Dependency>
<Dependency versionFrom="1.0.0_beta2">e_dbus-devel</Dependency>
<Dependency versionFrom="0.1.1_54472">ethumb-devel</Dependency>
<Dependency release="current">elementary</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="header">/usr/include</Path>
<Path fileType="data">/usr/lib/pkgconfig</Path>
</Files>
</Package>
<History>
<Update release="5">
<Date>2010-12-09</Date>
<Version>0.7.0_55225</Version>
<Comment>Version bump.</Comment>
<Requires>
<Action>reverseDependencyUpdate</Action>
</Requires>
<Name>H. İbrahim Güngör</Name>
<Email>[email protected]</Email>
</Update>
<Update release="4">
<Date>2010-11-13</Date>
<Version>0.7.0_54504</Version>
<Comment>Version bump.</Comment>
<Name>H. İbrahim Güngör</Name>
<Email>[email protected]</Email>
</Update>
<Update release="3">
<Date>2010-10-12</Date>
<Version>0.7.0_52995</Version>
<Comment>Mass rebuild for Pardus 2011 Beta</Comment>
<Name>Fatih Aşıcı</Name>
<Email>[email protected]</Email>
</Update>
<Update release="2">
<Date>2010-10-03</Date>
<Version>0.7.0_52995</Version>
<Comment>Version bump.</Comment>
<Requires>
<Action>reverseDependencyUpdate</Action>
</Requires>
<Name>H. İbrahim Güngör</Name>
<Email>[email protected]</Email>
</Update>
<Update release="1">
<Date>2010-06-07</Date>
<Version>0.7.0.49539</Version>
<Comment>First release</Comment>
<Name>H. İbrahim Güngör</Name>
<Email>[email protected]</Email>
</Update>
</History>
</PISI>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment