From 5f6bb6d74a46e28181ea04e03582254efc793a58 Mon Sep 17 00:00:00 2001 From: Torsten Veller Date: Sun, 16 Jan 2011 10:50:03 +0100 Subject: [PATCH] Import PortageXS-0.02.07 --- Changes | 5 + lib/PortageXS.pm | 4 +- lib/PortageXS/Core.pm | 121 +++++++++++++----- lib/PortageXS/examples/getParamFromFile.pl | 2 +- lib/PortageXS/examples/searchPackageByHerd.pl | 16 +++ .../examples/searchPackageByMaintainer.pl | 16 +++ 6 files changed, 130 insertions(+), 34 deletions(-) create mode 100755 lib/PortageXS/examples/searchPackageByHerd.pl create mode 100755 lib/PortageXS/examples/searchPackageByMaintainer.pl diff --git a/Changes b/Changes index e969c7f..25aace7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Changes ------- +0.02.07 + - Optional parameter repo: getAvailableEbuilds() + - New functions: searchPackageByHerd(), searchPackageByMaintainer() + - Fixed bug #178745 - Affected function: getParamFromFile() + 0.02.06 - fileBelongsToPackage(): Do not die if CONTENTS file is missing. (Reported by Michael Cummings ) - Speedup functions getFilesOfInstalledPackage(), fileBelongsToPackage() diff --git a/lib/PortageXS.pm b/lib/PortageXS.pm index 4ed8bff..59adf86 100644 --- a/lib/PortageXS.pm +++ b/lib/PortageXS.pm @@ -6,7 +6,7 @@ package PortageXS; # # author : Christian Hartmann # license : GPL-2 -# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS.pm,v 1.12 2007/04/19 09:07:09 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS.pm,v 1.13 2007/05/20 14:17:40 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -17,7 +17,7 @@ package PortageXS; # # ----------------------------------------------------------------------------- -$VERSION='0.02.06'; +$VERSION='0.02.07'; use PortageXS::Core; use PortageXS::System; diff --git a/lib/PortageXS/Core.pm b/lib/PortageXS/Core.pm index 80f4030..f167675 100644 --- a/lib/PortageXS/Core.pm +++ b/lib/PortageXS/Core.pm @@ -6,7 +6,7 @@ package PortageXS::Core; # # author : Christian Hartmann # license : GPL-2 -# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Core.pm,v 1.16 2007/04/19 09:05:16 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Core.pm,v 1.17 2007/05/20 14:17:40 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -45,6 +45,8 @@ our @EXPORT = qw( getPackagesFromWorld recordPackageInWorld removePackageFromWorld + searchPackageByMaintainer + searchPackageByHerd ); # Description: @@ -314,20 +316,16 @@ sub getParamFromFile { # - remove comments > $lines[$c]=~s/#(.*)//g; - if ($lines[$c]=~/$param="(.*)"/) { + # - remove leading whitespaces and tabs > + $lines[$c]=~s/^[ |\t]+//; + + if ($lines[$c]=~/^$param="(.*)"/) { # single-line with quotationmarks > $value=$1; - if ($mode eq 'firstseen') { - # - 6. clean up value > - $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs - $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs - $value=~s/\t/ /g; # replace tabs with whitespaces - $value=~s/ {2,}/ /g; # replace 1+ whitespaces with 1 whitespace - return $value; - } + last if ($mode eq 'firstseen'); } - elsif ($lines[$c]=~/$param="(.*)/) { + elsif ($lines[$c]=~/^$param="(.*)/) { # multi-line with quotationmarks > $value=$1.' '; for($d=$c+1;$d<=$#lines;$d++) { @@ -343,27 +341,13 @@ sub getParamFromFile { } } - if ($mode eq 'firstseen') { - # - clean up value > - $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs - $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs - $value=~s/\t/ /g; # replace tabs with whitespaces - $value=~s/ {2,}/ /g; # replace 1+ whitespaces with 1 whitespace - return $value; - } + last if ($mode eq 'firstseen'); } - elsif ($lines[$c]=~/$param=(.*)/) { + elsif ($lines[$c]=~/^$param=(.*)/) { # - single-line without quotationmarks > $value=$1; - if ($mode eq 'firstseen') { - # - 6. clean up value > - $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs - $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs - $value=~s/\t/ /g; # replace tabs with whitespaces - $value=~s/ {2,}/ /g; # replace 1+ whitespaces with 1 whitespace - return $value; - } + last if ($mode eq 'firstseen'); } } @@ -417,15 +401,19 @@ sub getUseSettingsOfInstalledPackage { } # Description: -# @listOfEbuilds=$pxs->getAvailableEbuilds(category/packagename); +# @listOfEbuilds=$pxs->getAvailableEbuilds(category/packagename,[$repo]); sub getAvailableEbuilds { my $self = shift; my $catPackage = shift; + my $repo = shift; my @packagelist = (); - if (-e $self->{PORTDIR}.'/'.$catPackage) { + $repo=$self->{'PORTDIR'} if (!$repo); + if (!-d $repo) { return (); } + + if (-e $repo.'/'.$catPackage) { # - get list of ebuilds > - my $dh = new DirHandle($self->{PORTDIR}.'/'.$catPackage); + my $dh = new DirHandle($repo.'/'.$catPackage); while (defined($_ = $dh->read)) { if ($_ =~ m/(.+)\.ebuild$/) { push(@packagelist,$_); @@ -733,4 +721,75 @@ sub resetCaches { return 1; } +# Description: +# Search packages by maintainer. Returns an array of packages. +# @packages=$pxs->searchPackageByMaintainer($searchString,[$repo]); +# Example: +# @packages=$pxs->searchPackageByMaintainer('ian@gentoo.org'); +# @packages=$pxs->searchPackageByMaintainer('ian@gentoo.org','/usr/local/portage/'); +sub searchPackageByMaintainer { + my $self = shift; + my $searchString = shift; + my $repo = shift; + my $dhc; + my $dhp; + my $tc; + my $tp; + my @matches = (); + my @fields = (); + + if (!$mode) { $mode='like'; } + $repo=$self->{'PORTDIR'} if (!$repo); + if (!-d $repo) { return (); } + + # - read categories > + foreach ($self->searchPackage('','like',$repo)) { + if (-e $repo.'/'.$_.'/metadata.xml') { + my $buffer=$self->getFileContents($repo.'/'.$_.'/metadata.xml'); + if ($buffer =~ m/$searchString(.*)?<\/email>/i) { + push(@matches,$_); + } + elsif ($buffer =~ m/$searchString(.*)?<\/name>/i) { + push(@matches,$_); + } + } + } + + return (sort @matches); +} + +# Description: +# Search packages by herd. Returns an array of packages. +# @packages=$pxs->searchPackageByHerd($searchString,[$repo]); +# Example: +# @packages=$pxs->searchPackageByHerd('perl'); +# @packages=$pxs->searchPackageByHerd('perl','/usr/local/portage/'); +sub searchPackageByHerd { + my $self = shift; + my $searchString = shift; + my $repo = shift; + my $dhc; + my $dhp; + my $tc; + my $tp; + my @matches = (); + my @fields = (); + + if (!$mode) { $mode='like'; } + $repo=$self->{'PORTDIR'} if (!$repo); + if (!-d $repo) { return (); } + + # - read categories > + foreach ($self->searchPackage('','like',$repo)) { + if (-e $repo.'/'.$_.'/metadata.xml') { + my $buffer=$self->getFileContents($repo.'/'.$_.'/metadata.xml'); + if ($buffer =~ m/$searchString(.*)?<\/herd>/i) { + push(@matches,$_); + } + } + } + + return (sort @matches); +} + 1; diff --git a/lib/PortageXS/examples/getParamFromFile.pl b/lib/PortageXS/examples/getParamFromFile.pl index 17cdf9f..416b1be 100755 --- a/lib/PortageXS/examples/getParamFromFile.pl +++ b/lib/PortageXS/examples/getParamFromFile.pl @@ -8,4 +8,4 @@ my $pxs=PortageXS->new(); print "CFLAGS are set to: "; -print join(' ',$pxs->getParamFromFile($pxs->getFileContents('/etc/make.globals').$pxs->getFileContents('/etc/make.conf'),'CFLAGS','LASTSEEN'))."\n"; +print join(' ',$pxs->getParamFromFile($pxs->getFileContents('/etc/make.globals').$pxs->getFileContents('/etc/make.conf'),'CFLAGS','lastseen'))."\n"; diff --git a/lib/PortageXS/examples/searchPackageByHerd.pl b/lib/PortageXS/examples/searchPackageByHerd.pl new file mode 100755 index 0000000..39f65b6 --- /dev/null +++ b/lib/PortageXS/examples/searchPackageByHerd.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use lib '../..'; +use PortageXS; + +my $pxs=PortageXS->new(); + +my @repos=(); + +push(@repos,$pxs->getPortdir()); +push(@repos,$pxs->getPortdirOverlay()); + +foreach (@repos) { + print "Repo: ".$_.":\n"; + print join("\n",$pxs->searchPackageByMaintainer($ARGV[0],$_))."\n\n"; +} diff --git a/lib/PortageXS/examples/searchPackageByMaintainer.pl b/lib/PortageXS/examples/searchPackageByMaintainer.pl new file mode 100755 index 0000000..39f65b6 --- /dev/null +++ b/lib/PortageXS/examples/searchPackageByMaintainer.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use lib '../..'; +use PortageXS; + +my $pxs=PortageXS->new(); + +my @repos=(); + +push(@repos,$pxs->getPortdir()); +push(@repos,$pxs->getPortdirOverlay()); + +foreach (@repos) { + print "Repo: ".$_.":\n"; + print join("\n",$pxs->searchPackageByMaintainer($ARGV[0],$_))."\n\n"; +}