diff --git a/Changes b/Changes index ed20a10..e969c7f 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,23 @@ Changes ------- +0.02.06 + - fileBelongsToPackage(): Do not die if CONTENTS file is missing. (Reported by Michael Cummings ) + - Speedup functions getFilesOfInstalledPackage(), fileBelongsToPackage() + - Source cleanups + - New functions: disableColors(), getPackagesFromWorld(), recordPackageInWorld(), removePackageFromWorld() + - formatUseflags(): Also handle suffixes (% and *) + - added .cache dir to EXCLUDE_DIRS for use with paludis + - removed virtual dir from EXCLUDE_DIRS - we actually want virtuals in + - getPackagesFromCategory(): + - Use PORTDIR by default + - New optional parameter to set the repository to use + - Check for dirs before trying to access them + - searchPackage(): Works - Feel free to use it now. + - Fixed bug #175175 - getArch() was not able to resolve the profile path if make.profile was an absolute path + - Apply fixes from bug #175175 to getProfilePath(); refactored getArch() and getUsemasksFromProfile() + - Make test getPortageXScategorylist() more robust + 0.02.05 - New functions: getEbuildName(), getUsedescs(), getCategories(), formatUseflags() (from demerge 0.032), sortUseflags(), getUsemasksFromProfile(), getProfilePath(), resetCaches() - Fixed some function descriptions @@ -23,7 +40,7 @@ Changes - Initscript for the server - Runtime optimizations - Basic server and client implemented - + 0.02.02 - New functions: searchPackage(), getReponame(), resolveMirror(), getUsedesc() - New example: searchPackage.pl, resolveMirror.pl, getUsedesc.pl diff --git a/lib/PortageXS.pm b/lib/PortageXS.pm index da817c0..4ed8bff 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.9 2007/04/07 20:09:16 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS.pm,v 1.12 2007/04/19 09:07:09 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -17,7 +17,7 @@ package PortageXS; # # ----------------------------------------------------------------------------- -$VERSION='0.02.05'; +$VERSION='0.02.06'; use PortageXS::Core; use PortageXS::System; @@ -61,7 +61,8 @@ sub new { $self->{'VERSION'} = $VERSION; $self->{'PORTDIR'} = $self->getPortdir(); - $self->{'PKG_DB_DIR'} = "/var/db/pkg/"; + $self->{'PKG_DB_DIR'} = '/var/db/pkg/'; + $self->{'PATH_TO_WORLDFILE'} = '/var/lib/portage/world'; $self->{'IS_INITIALIZED'} = 1; $self->{'EXCLUDE_DIRS'}{'.'} = 1; @@ -70,25 +71,25 @@ sub new { $self->{'EXCLUDE_DIRS'}{'licenses'} = 1; $self->{'EXCLUDE_DIRS'}{'eclass'} = 1; $self->{'EXCLUDE_DIRS'}{'distfiles'} = 1; - $self->{'EXCLUDE_DIRS'}{'virtual'} = 1; $self->{'EXCLUDE_DIRS'}{'profiles'} = 1; $self->{'EXCLUDE_DIRS'}{'CVS'} = 1; + $self->{'EXCLUDE_DIRS'}{'.cache'} = 1; - $self->{'PORTAGEXS_ETC_DIR'} = "/etc/pxs/"; - $self->{'ETC_DIR'} = "/etc/"; - $self->{'MAKE_PROFILE_PATH'} = "/etc/make.profile"; + $self->{'PORTAGEXS_ETC_DIR'} = '/etc/pxs/'; + $self->{'ETC_DIR'} = '/etc/'; + $self->{'MAKE_PROFILE_PATH'} = '/etc/make.profile'; # - init colors > - $self->{'COLORS'}{'YELLOW'} = color("bold yellow"); - $self->{'COLORS'}{'GREEN'} = color("green"); - $self->{'COLORS'}{'LIGHTGREEN'} = color("bold green"); - $self->{'COLORS'}{'WHITE'} = color("bold white"); - $self->{'COLORS'}{'CYAN'} = color("bold cyan"); - $self->{'COLORS'}{'RED'} = color("bold red"); - $self->{'COLORS'}{'BLUE'} = color("bold blue"); - $self->{'COLORS'}{'RESET'} = color("reset"); + $self->{'COLORS'}{'YELLOW'} = color('bold yellow'); + $self->{'COLORS'}{'GREEN'} = color('green'); + $self->{'COLORS'}{'LIGHTGREEN'} = color('bold green'); + $self->{'COLORS'}{'WHITE'} = color('bold white'); + $self->{'COLORS'}{'CYAN'} = color('bold cyan'); + $self->{'COLORS'}{'RED'} = color('bold red'); + $self->{'COLORS'}{'BLUE'} = color('bold blue'); + $self->{'COLORS'}{'RESET'} = color('reset'); - if (lc($self->getParamFromFile($self->getFileContents('/etc/make.conf'),"NOCOLOR","lastseen")) eq 'true') { + if (lc($self->getParamFromFile($self->getFileContents('/etc/make.conf'),'NOCOLOR','lastseen')) eq 'true') { $self->{'COLORS'}{'YELLOW'} = ''; $self->{'COLORS'}{'GREEN'} = ''; $self->{'COLORS'}{'LIGHTGREEN'} = ''; diff --git a/lib/PortageXS/Core.pm b/lib/PortageXS/Core.pm index b9a2912..80f4030 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.12 2007/04/09 15:03:51 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Core.pm,v 1.16 2007/04/19 09:05:16 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -42,6 +42,9 @@ our @EXPORT = qw( getCategories getProfilePath resetCaches + getPackagesFromWorld + recordPackageInWorld + removePackageFromWorld ); # Description: @@ -51,17 +54,17 @@ our @EXPORT = qw( # $arch=$pxs->getArch(); sub getArch { my $self = shift; - my $curPath = ""; + my $curPath = ''; my @files = (); - my $parent = ""; - my $buffer = ""; + my $parent = ''; + my $buffer = ''; if(!-e $self->{'MAKE_PROFILE_PATH'}) { $self->print_err('Profile not set!'); exit(0); } else { - $curPath=$self->{'ETC_DIR'}.readlink($self->{'MAKE_PROFILE_PATH'}); + $curPath=$self->getProfilePath(); } while(1) { @@ -74,7 +77,7 @@ sub getArch { $curPath.='/'.$parent; } - $buffer.=$self->getFileContents("/etc/make.conf").$self->getFileContents("/etc/make.globals"); + $buffer.=$self->getFileContents('/etc/make.conf').$self->getFileContents('/etc/make.globals'); foreach(@files) { $buffer.=$self->getFileContents($_); } @@ -103,7 +106,7 @@ sub getPortdir { return $self->{'PORTDIR'}; } else { - $self->{'PORTDIR'}=$self->getParamFromFile($self->getFileContents("/etc/make.globals").$self->getFileContents("/etc/make.conf"),"PORTDIR","lastseen"); + $self->{'PORTDIR'}=$self->getParamFromFile($self->getFileContents('/etc/make.globals').$self->getFileContents('/etc/make.conf'),'PORTDIR','lastseen'); return $self->{'PORTDIR'}; } } @@ -127,7 +130,7 @@ sub getPortdirOverlay { # Returnvalue is the content of the given file. # $filecontent=$pxs->getFileContents($file); sub getFileContents { - open(FH,"<".$_[1]) or die('Cannot open file '.$_[1]); + open(FH,'<'.$_[1]) or die('Cannot open file '.$_[1]); my $content = do{local $/; }; close(FH); return $content; @@ -139,7 +142,6 @@ sub getFileContents { sub searchInstalledPackage { my $self = shift; my $searchString = shift; if (! $searchString) { $searchString=''; } - my $int_c = 0; my @matches = (); my $s_cat = ''; my $s_pak = ''; @@ -183,7 +185,7 @@ sub searchInstalledPackage { while (defined($tp = $dhp->read)) { # - check if packagename matches # (faster if we already check it now) > - if ($tp =~m/$s_pak/i || $s_pak eq "") { + if ($tp =~m/$s_pak/i || $s_pak eq '') { # - not excluded and $_ is a dir? if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $self->{'PKG_DB_DIR'}.'/'.$tc.'/'.$tp) { if (($s_cat ne '') && ($m_cat)) { @@ -205,84 +207,84 @@ sub searchInstalledPackage { } # Description: -# DO NOT USE THIS FUNCTION AS IT WILL MOST PROBABLY CHANGE IN THE FUTURE! -# TODO +# Search for packages in given repository. +# @packages=$pxs->searchPackage($searchString [,$mode, $repo] ); +# +# Parameters: +# searchString: string to search for # mode: like || exact +# repo: repository to search in +# +# Examples: +# @packages=$pxs->searchPackage('perl'); +# @packages=$pxs->searchPackage('perl','exact'); +# @packages=$pxs->searchPackage('perl','like','/usr/portage'); +# @packages=$pxs->searchPackage('git','exact','/usr/local/portage'); sub searchPackage { my $self = shift; my $searchString = shift; my $mode = shift; - my $int_c = 0; + my $repo = shift; my $dhc; my $dhp; my $tc; my $tp; my @matches = (); - my @repos = (); - my $repo_name = ''; if (!$mode) { $mode='like'; } - - # - get all repos > - push(@repos,$self->{'PORTDIR'}); - push(@repos,$self->getPortdirOverlay()); + $repo=$self->{'PORTDIR'} if (!$repo); + if (!-d $repo) { return (); } # - escape special chars > if ($mode eq 'like') { $searchString =~ s/\+/\\\+/g; # - read categories > - foreach $this_repodir (@repos) { - $repo_name = $self->getReponame($this_repodir); - $dhc = new DirHandle($this_repodir); - if (defined $dhc) { - while (defined($tc = $dhc->read)) { - # - not excluded and $_ is a dir? - if (! $self->{'EXCLUDE_DIRS'}{$tc} && -d $this_repodir.'/'.$tc) { - $dhp = new DirHandle($this_repodir.'/'.$tc); - while (defined($tp = $dhp->read)) { - # - look up if entry matches the search - # (much faster if we already check now) > - if ($tp =~m/$searchString/i) { - # - not excluded and $_ is a dir? - if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $this_repodir.'/'.$tc.'/'.$tp) { - push(@matches,$repo_name.':'.$tc.'/'.$tp); - } + $dhc = new DirHandle($repo); + if (defined $dhc) { + while (defined($tc = $dhc->read)) { + # - not excluded and $_ is a dir? + if (! $self->{'EXCLUDE_DIRS'}{$tc} && -d $repo.'/'.$tc) { + $dhp = new DirHandle($repo.'/'.$tc); + while (defined($tp = $dhp->read)) { + # - look up if entry matches the search + # (much faster if we already check now) > + if ($tp =~m/$searchString/i) { + # - not excluded and $_ is a dir? + if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $repo.'/'.$tc.'/'.$tp) { + push(@matches,$tc.'/'.$tp); } } - undef $dhp; } + undef $dhp; } } - undef $dhc; } + undef $dhc; } elsif ($mode eq 'exact') { # - read categories > - foreach $this_repodir (@repos) { - $repo_name = $self->getReponame($this_repodir); - $dhc = new DirHandle($this_repodir); - if (defined $dhc) { - while (defined($tc = $dhc->read)) { - # - not excluded and $_ is a dir? - if (! $self->{'EXCLUDE_DIRS'}{$tc} && -d $this_repodir.'/'.$tc) { - $dhp = new DirHandle($this_repodir.'/'.$tc); - while (defined($tp = $dhp->read)) { - # - look up if entry matches the search - # (much faster if we already check now) > - if ($tp eq $searchString) { - # - not excluded and $_ is a dir? - if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $this_repodir.'/'.$tc.'/'.$tp) { - push(@matches,$repo_name.':'.$tc.'/'.$tp); - } + $dhc = new DirHandle($repo); + if (defined $dhc) { + while (defined($tc = $dhc->read)) { + # - not excluded and $_ is a dir? + if (! $self->{'EXCLUDE_DIRS'}{$tc} && -d $repo.'/'.$tc) { + $dhp = new DirHandle($repo.'/'.$tc); + while (defined($tp = $dhp->read)) { + # - look up if entry matches the search + # (much faster if we already check now) > + if ($tp eq $searchString) { + # - not excluded and $_ is a dir? + if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $repo.'/'.$tc.'/'.$tp) { + push(@matches,$tc.'/'.$tp); } } - undef $dhp; } + undef $dhp; } } - undef $dhc; } + undef $dhc; } return (sort @matches); @@ -301,7 +303,7 @@ sub getParamFromFile { my $c = 0; my $d = 0; my @lines = (); - my $value = ""; # value of $param + my $value = ''; # value of $param # - split file in lines > @lines = split(/\n/,$file); @@ -316,7 +318,7 @@ sub getParamFromFile { # single-line with quotationmarks > $value=$1; - if ($mode eq "firstseen") { + if ($mode eq 'firstseen') { # - 6. clean up value > $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs @@ -327,7 +329,7 @@ sub getParamFromFile { } elsif ($lines[$c]=~/$param="(.*)/) { # multi-line with quotationmarks > - $value=$1." "; + $value=$1.' '; for($d=$c+1;$d<=$#lines;$d++) { # - look for quotationmark > if ($lines[$d]=~/(.*)"?/) { @@ -337,11 +339,11 @@ sub getParamFromFile { } else { # - no quotationmark found; append line contents to $value > - $value.=$lines[$d]." "; + $value.=$lines[$d].' '; } } - if ($mode eq "firstseen") { + if ($mode eq 'firstseen') { # - clean up value > $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs @@ -354,7 +356,7 @@ sub getParamFromFile { # - single-line without quotationmarks > $value=$1; - if ($mode eq "firstseen") { + if ($mode eq 'firstseen') { # - 6. clean up value > $value=~s/^[ |\t]+//; # remove leading whitespaces and tabs $value=~s/[ |\t]+$//; # remove trailing whitespaces and tabs @@ -380,7 +382,7 @@ sub getParamFromFile { sub getUseSettingsOfInstalledPackage { my $self = shift; my $package = shift; - my $tmp_filecontents = ""; + my $tmp_filecontents = ''; my @package_IUSE = (); my @package_USE = (); my @USEs = (); @@ -393,7 +395,7 @@ sub getUseSettingsOfInstalledPackage { } $tmp_filecontents =~s/\n//g; @package_IUSE = split(/ /,$tmp_filecontents); - if (-e $self->{'PKG_DB_DIR'}."/".$package."/USE") { + if (-e $self->{'PKG_DB_DIR'}.'/'.$package.'/USE') { $tmp_filecontents = $self->getFileContents($self->{'PKG_DB_DIR'}.'/'.$package.'/USE'); } $tmp_filecontents =~s/\n//g; @@ -453,26 +455,30 @@ sub getPortageXScategorylist { # Description: # Returns all available packages from the given category. -# @listOfPackages=$pxs->getPackagesFromCategory($category); +# @listOfPackages=$pxs->getPackagesFromCategory($category,[$repo]); # E.g.: -# @listOfPackages=$pxs->getPackagesFromCategory("dev-perl"); +# @listOfPackages=$pxs->getPackagesFromCategory("dev-perl","/usr/portage"); sub getPackagesFromCategory { my $self = shift; my $category = shift; + my $repo = shift; my $dhp; my $tp; my @packages = (); return () if !$category; + $repo=$self->{'PORTDIR'} if (!$repo); - $dhp = new DirHandle($self->{'PORTDIR'}.'/'.$category); - while (defined($tp = $dhp->read)) { - # - not excluded and $_ is a dir? - if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $self->{'PORTDIR'}.'/'.$category.'/'.$tp) { - push(@packages,$tp); + if (-d $repo.'/'.$category) { + $dhp = new DirHandle($repo.'/'.$category); + while (defined($tp = $dhp->read)) { + # - not excluded and $_ is a dir? + if (! $self->{'EXCLUDE_DIRS'}{$tp} && -d $repo.'/'.$category.'/'.$tp) { + push(@packages,$tp); + } } + undef $dhp; } - undef $dhp; return @packages; } @@ -485,7 +491,6 @@ sub fileBelongsToPackage { my $self = shift; my $file = shift; - my $int_c = 0; my @matches = (); my $dhc; my $dhp; @@ -500,17 +505,14 @@ sub fileBelongsToPackage { if (! $self->{EXCLUDE_DIRS}{$tc} && -d $self->{'PKG_DB_DIR'}.'/'.$tc) { $dhp = new DirHandle($self->{'PKG_DB_DIR'}.'/'.$tc); while (defined($tp = $dhp->read)) { - # - not excluded and $_ is a dir? - if (! $self->{EXCLUDE_DIRS}{$tp} && -d $self->{'PKG_DB_DIR'}.'/'.$tc.'/'.$tp) { - my $data = $self->getFileContents($self->{'PKG_DB_DIR'}.'/'.$tc.'/'.$tp.'/CONTENTS'); - my @lines = split(/\n/,$data); - foreach (@lines) { - my $thisfile = (split(/ /,$_))[1]; - if ($thisfile eq $file) { - push(@matches,$tc.'/'.$tp); - } + open(FH,'<'.$self->{'PKG_DB_DIR'}.'/'.$tc.'/'.$tp.'/CONTENTS') or next; + while () { + if ($_=~m/$file/) { + push(@matches,$tc.'/'.$tp); + last; } } + close(FH); } undef $dhp; } @@ -531,9 +533,7 @@ sub getFilesOfInstalledPackage { # - find installed versions & loop > foreach ($self->searchInstalledPackage($package)) { - my $data = $self->getFileContents($self->{PKG_DB_DIR}.'/'.$_.'/CONTENTS'); - my @lines = split(/\n/,$data); - foreach (@lines) { + foreach (split(/\n/,$self->getFileContents($self->{PKG_DB_DIR}.'/'.$_.'/CONTENTS'))) { push(@files,(split(/ /,$_))[1]); } } @@ -613,7 +613,6 @@ sub resolveMirror { sub getCategories { my $self = shift; my $repo = shift; - my @categories = (); if (-e $repo.'/profiles/categories') { return split(/\n/,$self->getFileContents($repo.'/profiles/categories')); @@ -627,7 +626,80 @@ sub getCategories { # $path=$pxs->getProfilePath(); sub getProfilePath { my $self = shift; - return $self->{'ETC_DIR'}.readlink($self->{'MAKE_PROFILE_PATH'}); + + if (-e $self->{'ETC_DIR'}.readlink($self->{'MAKE_PROFILE_PATH'})) { + return $self->{'ETC_DIR'}.readlink($self->{'MAKE_PROFILE_PATH'}); + } + elsif (-e readlink($self->{'MAKE_PROFILE_PATH'})) { + return readlink($self->{'MAKE_PROFILE_PATH'}); + } + + return undef; +} + +# Description: +# Returns all packages that are in the world file. +# @packages=$pxs->getPackagesFromWorld(); +sub getPackagesFromWorld { + my $self = shift; + + if (-e $self->{'PATH_TO_WORLDFILE'}) { + return split(/\n/,$self->getFileContents($self->{'PATH_TO_WORLDFILE'})); + } + + return (); +} + +# Description: +# Records package in world file. +# $pxs->recordPackageInWorld($package); +sub recordPackageInWorld { + my $self = shift; + my $package = shift; + my %world = (); + + # - get packages already recorded in world > + foreach ($self->getPackagesFromWorld()) { + $world{$_}=1; + } + + # - add $package > + $world{$package}=1; + + # - write world file > + open(FH,'>'.$self->{'PATH_TO_WORLDFILE'}) or die('Cannot write to world file!'); + foreach (keys %world) { + print FH $_,"\n"; + } + close(FH); + + return 1; +} + +# Description: +# Removes package from world file. +# $pxs->removePackageFromWorld($package); +sub removePackageFromWorld { + my $self = shift; + my $package = shift; + my %world = (); + + # - get packages already recorded in world > + foreach ($self->getPackagesFromWorld()) { + $world{$_}=1; + } + + # - remove $package > + $world{$package}=0; + + # - write world file > + open(FH,'>'.$self->{'PATH_TO_WORLDFILE'}) or die('Cannot write to world file!'); + foreach (keys %world) { + print FH $_,"\n" if ($world{$_}); + } + close(FH); + + return 1; } # Description: diff --git a/lib/PortageXS/UI/Console.pm b/lib/PortageXS/UI/Console.pm index 59e077d..e18d88d 100644 --- a/lib/PortageXS/UI/Console.pm +++ b/lib/PortageXS/UI/Console.pm @@ -6,7 +6,7 @@ package PortageXS::UI::Console; # # author : Christian Hartmann # license : GPL-2 -# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/UI/Console.pm,v 1.6 2007/04/09 15:03:51 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/UI/Console.pm,v 1.9 2007/04/15 11:13:25 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -27,6 +27,7 @@ our @EXPORT = qw( setPrintColor cmdAskUser formatUseflags + disableColors ); # Description: @@ -84,7 +85,7 @@ sub cmdAskUser { # - loop until user has entered a valid option > do { - print " ".$question." (".join("/",@options)."): "; + print ' '.$question.' ('.join('/',@options).'): '; chomp($userInput = ); foreach $this_option (@options) { if (lc($this_option) eq lc($userInput)) { @@ -107,18 +108,20 @@ sub formatUseflags { my @use1 = (); # + my @use2 = (); # - my %masked = (); + my %c = (); + my $this_use = ''; foreach ($self->getUsemasksFromProfile()) { $masked{$_}=1; } # - Sort - Needed for the right display order > - for (my $x=0;$x<=$#useflags;$x++) { - if (substr($useflags[$x],0,1) eq '-') { - push(@use2,$useflags[$x]); + foreach $this_use (@useflags) { + if ($this_use=~m/^-/) { + push(@use2,$this_use); } else { - push(@use1,$useflags[$x]); + push(@use1,$this_use); } } @useflags=(); @@ -128,26 +131,60 @@ sub formatUseflags { @use2=(); # - Apply colors and use.mask > - for (my $x=0;$x<=$#useflags;$x++) { - if (substr($useflags[$x],0,1) eq '-') { - if ($masked{substr($useflags[$x],1,length($useflags[$x])-1)}) { - push(@use2,'('.$self->{'COLORS'}{'BLUE'}.$useflags[$x].$self->{'COLORS'}{'RESET'}.')'); - } - else { - push(@use2,$self->{'COLORS'}{'BLUE'}.$useflags[$x].$self->{'COLORS'}{'RESET'}); - } + foreach $this_use (@useflags) { + if ($this_use=~m/^-/) { + $c{'color'}='BLUE'; + $c{'useflag'}=substr($this_use,1,length($this_use)-1); + $c{'prefix'}='-'; + $c{'suffix'}=''; + $c{'sort'}=2; } else { - if ($masked{$useflags[$x]}) { - push(@use1,'('.$self->{'COLORS'}{'RED'}.$useflags[$x].$self->{'COLORS'}{'RESET'}.')'); - } - else { - push(@use1,$self->{'COLORS'}{'RED'}.$useflags[$x].$self->{'COLORS'}{'RESET'}); - } + $c{'color'}='RED'; + $c{'useflag'}=$this_use; + $c{'prefix'}=''; + $c{'suffix'}=''; + $c{'sort'}=1; + } + + if ($this_use=~m/%/) { + $c{'color'}='YELLOW'; + $c{'suffix'}.='%'; + $c{'useflag'}=~s/%//g; + } + + if ($this_use=~m/\*/) { + $c{'color'}='YELLOW'; + $c{'suffix'}.='*'; + $c{'useflag'}=~s/\*//g; + } + + $c{'compiled'}=$self->{'COLORS'}{$c{'color'}}.$c{'prefix'}.$c{'useflag'}.$self->{'COLORS'}{'RESET'}.$c{'suffix'}; + + if ($masked{$c{'useflag'}}) { + $c{'compiled'}='('.$c{'compiled'}.')'; + } + + if ($c{'sort'}==1) { + push (@use1,$c{'compiled'}); + } + else { + push (@use2,$c{'compiled'}); } } return @use1,@use2; } +# Description: +# Disables colors. / Unsets set colors in PortageXS.pm +# $pxs->disableColors(); +sub disableColors { + my $self = shift; + foreach my $k1 (keys %{$self->{'COLORS'}}) { + $self->{'COLORS'}{$k1}=undef; + } + return 1; +} + 1; diff --git a/lib/PortageXS/Useflags.pm b/lib/PortageXS/Useflags.pm index 11e86ee..dced3d0 100644 --- a/lib/PortageXS/Useflags.pm +++ b/lib/PortageXS/Useflags.pm @@ -6,7 +6,7 @@ package PortageXS::Useflags; # # author : Christian Hartmann # license : GPL-2 -# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Useflags.pm,v 1.4 2007/04/09 15:03:51 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Useflags.pm,v 1.6 2007/04/19 09:05:16 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -132,7 +132,7 @@ sub getUsemasksFromProfile { exit(0); } else { - $curPath=$self->{'ETC_DIR'}.readlink($self->{'MAKE_PROFILE_PATH'}); + $curPath=$self->getProfilePath(); } while(1) { @@ -156,7 +156,7 @@ sub getUsemasksFromProfile { for($c=0;$c<=$#lines;$c++) { next if $lines[$c]=~m/^#/; next if $lines[$c] eq "\n"; - next if $lines[$c] eq ""; + next if $lines[$c] eq ''; if (substr($lines[$c],0,1) eq '-') { # - unmask use > @@ -174,7 +174,7 @@ sub getUsemasksFromProfile { } # - Setup cache > - $self->{'CACHE'}{'Useflags'}{'getUsemasksFromProfile'}{'useflags'}=join(" ",@useflags); + $self->{'CACHE'}{'Useflags'}{'getUsemasksFromProfile'}{'useflags'}=join(' ',@useflags); } else { @useflags=split(/ /,$self->{'CACHE'}{'Useflags'}{'getUsemasksFromProfile'}{'useflags'}); diff --git a/lib/PortageXS/examples/consolePrintDemo.pl b/lib/PortageXS/examples/consolePrintDemo.pl index 0d539d5..2f7f9b1 100755 --- a/lib/PortageXS/examples/consolePrintDemo.pl +++ b/lib/PortageXS/examples/consolePrintDemo.pl @@ -15,4 +15,14 @@ $pxs->setPrintColor('YELLOW'); print "This is yellow. "; $pxs->setPrintColor('RESET'); print "This is normal.\n"; +print "\ncalling disableColors();\n"; +$pxs->disableColors(); + +$pxs->print_ok("This is ok.\n"); +$pxs->print_info("This is a warning.\n"); +$pxs->print_err("This is an error.\n"); +$pxs->setPrintColor('RED'); print "This is red. "; +$pxs->setPrintColor('BLUE'); print "This is blue. "; +$pxs->setPrintColor('YELLOW'); print "This is yellow. "; +$pxs->setPrintColor('RESET'); print "This is normal.\n"; diff --git a/lib/PortageXS/examples/formatUseflags.pl b/lib/PortageXS/examples/formatUseflags.pl index fa39526..3ce7aa8 100755 --- a/lib/PortageXS/examples/formatUseflags.pl +++ b/lib/PortageXS/examples/formatUseflags.pl @@ -12,7 +12,12 @@ my $package = "perl"; $package = $ARGV[0] if $ARGV[0]; ($package)=$pxs->searchPackage($package,'exact'); -$package=(split(/:/,$package))[1]; print "Package ".$package." has been compiled with useflags set: "; print join(" ",$pxs->formatUseflags($pxs->getUseSettingsOfInstalledPackage($pxs->searchInstalledPackage($package))))."\n"; + +print "\nMore examples:\n"; +print join(" ",$pxs->formatUseflags(qw(abc abc% abc* abc%* -abc -abc* -abc% -abc*%)))."\n"; +my $umasked=($pxs->getUsemasksFromProfile())[0]; +print join(" ",$pxs->formatUseflags(($umasked,$umasked.'%',$umasked.'*',$umasked.'%*','-'.$umasked,'-'.$umasked.'*','-'.$umasked.'%','-'.$umasked.'*%')))."\n"; + diff --git a/lib/PortageXS/examples/getPackagesFromCategory.pl b/lib/PortageXS/examples/getPackagesFromCategory.pl index c9eee77..4f32304 100755 --- a/lib/PortageXS/examples/getPackagesFromCategory.pl +++ b/lib/PortageXS/examples/getPackagesFromCategory.pl @@ -7,5 +7,8 @@ use PortageXS; my $pxs=PortageXS->new(); -print "List of available packages in category $ARGV[0]:\n"; -print join("\n",$pxs->getPackagesFromCategory($ARGV[0]))."\n"; +my $repo=$pxs->getPortdir(); +exit(0) if !$ARGV[0]; +$repo=$ARGV[1] if $ARGV[1]; +print "List of available packages in category $ARGV[0] in repo $repo:\n"; +print join("\n",$pxs->getPackagesFromCategory($ARGV[0],$repo))."\n"; diff --git a/lib/PortageXS/examples/getPackagesFromWorld.pl b/lib/PortageXS/examples/getPackagesFromWorld.pl new file mode 100755 index 0000000..e56dc87 --- /dev/null +++ b/lib/PortageXS/examples/getPackagesFromWorld.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use lib '../..'; +use PortageXS; + +my $pxs=PortageXS->new(); + +print "Packages recorded in ".$pxs->{'PATH_TO_WORLDFILE'}."\n"; +print join("\n",$pxs->getPackagesFromWorld())."\n"; + diff --git a/lib/PortageXS/examples/recordAndRemovePackageFromWorld.pl b/lib/PortageXS/examples/recordAndRemovePackageFromWorld.pl new file mode 100755 index 0000000..dcde60a --- /dev/null +++ b/lib/PortageXS/examples/recordAndRemovePackageFromWorld.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use lib "../.."; +use PortageXS; + +my $pxs=PortageXS->new(); + +if ($pxs->cmdAskUser('Do you really want to execute this example? A package called test/test will be added to the world file and removed afterwards.','y,n') eq 'y') { + print "Recording package test/test in world..\n"; + $pxs->recordPackageInWorld("test/test"); + + print "Removing package test/test from world..\n"; + $pxs->removePackageFromWorld("test/test"); +} + diff --git a/t/01_Core.t b/t/01_Core.t index 1d9df59..799cefc 100644 --- a/t/01_Core.t +++ b/t/01_Core.t @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Simple tests => 31; +use Test::Simple tests => 32; use lib '../lib/'; use lib 'lib/'; @@ -45,9 +45,7 @@ ok(-d $pxs->getPortdir(),'getPortdir: '.$pxs->getPortdir()); # - getPortageXScategorylist > { my $oldpath = $pxs->{'PORTAGEXS_ETC_DIR'}; - if (!-d $pxs->{'PORTAGEXS_ETC_DIR'}) { - $pxs->{'PORTAGEXS_ETC_DIR'}="./".$pxs->{'PORTAGEXS_ETC_DIR'}; - } + $pxs->{'PORTAGEXS_ETC_DIR'}="./".$pxs->{'PORTAGEXS_ETC_DIR'}; my @entries = $pxs->getPortageXScategorylist('perl'); ok($#entries>0,'getPortageXScategorylist - perl: '.join(' ',@entries)); $pxs->{'PORTAGEXS_ETC_DIR'}=$oldpath; @@ -116,6 +114,12 @@ ok(!$pxs->fileBelongsToPackage('/this/path/most/likely/does/not/exist'),'fileBel ok(($#cats+1),'Categories found: '.($#cats+1)); } +# - getPackagesFromWorld > +{ + my @packages = $pxs->getPackagesFromWorld(); + ok(($#packages+1),'Packages found in world: '.($#packages+1)); +} + # - getEbuildName > { ok($pxs->getEbuildName('mozilla-firefox-2.0_beta2.ebuild') eq 'mozilla-firefox','getEbuildName test 1');