diff --git a/Changes b/Changes index 25aace7..4c7e0e8 100644 --- a/Changes +++ b/Changes @@ -1,11 +1,19 @@ Changes ------- +0.02.09 + - Fixed bugs that occured when using new profiles (2008.0+) + - Implemented getPortageMakeParam() + - getArch() is now a wrapper for getPortageMakeParam() only + +0.02.08 + - Fixed bug #216484 - Affected function: getArch() + 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 59adf86..66d6235 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.13 2007/05/20 14:17:40 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS.pm,v 1.14 2008/12/01 19:53:27 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -17,7 +17,7 @@ package PortageXS; # # ----------------------------------------------------------------------------- -$VERSION='0.02.07'; +$VERSION='0.02.09'; use PortageXS::Core; use PortageXS::System; diff --git a/lib/PortageXS/Core.pm b/lib/PortageXS/Core.pm index f167675..03e6083 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.17 2007/05/20 14:17:40 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Core.pm,v 1.19 2008/12/01 19:53:27 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -18,10 +18,13 @@ package PortageXS::Core; # ----------------------------------------------------------------------------- use DirHandle; +use Shell::EnvImporter; require Exporter; our @ISA = qw(Exporter PortageXS); our @EXPORT = qw( getArch + getPortageMakeParam + getPortageMakeParamHelper getPortdir getPortdirOverlay getFileContents @@ -51,15 +54,50 @@ our @EXPORT = qw( # Description: # Returnvalue is ARCH set in the system-profile. +# Wrapper for old getArch()-version. Use getPortageMakeParam() instead. # # Example: # $arch=$pxs->getArch(); sub getArch { my $self = shift; - my $curPath = ''; + return $self->getPortageMakeParam('ARCH'); +} + +# Description: +# Helper for getPortageMakeParam() +sub getPortageMakeParamHelper { + my $self = shift; + my $curPath = shift; my @files = (); my $parent = ''; - my $buffer = ''; + + if (-e $curPath.'/make.defaults') { + push(@files,$curPath.'/make.defaults'); + } + if (! -e $curPath.'/parent') { + return @files; + } + $parent=$self->getFileContents($curPath.'/parent'); + foreach (split(/\n/,$parent)) { + push(@files,$self->getPortageMakeParamHelper($curPath.'/'.$_)); + } + + return @files; +} + +# Description: +# Returnvalue is $PARAM set in the system-profile. +# +# Example: +# $arch=$pxs->getPortageMakeParam(); +sub getPortageMakeParam { + my $self = shift; + my $param = shift; + my @files = (); + my @etcfiles = qw(/etc/make.globals /etc/make.conf); + my @profilefiles = (); + my $v = ''; + my $parent = ''; if(!-e $self->{'MAKE_PROFILE_PATH'}) { $self->print_err('Profile not set!'); @@ -69,22 +107,42 @@ sub getArch { $curPath=$self->getProfilePath(); } - while(1) { - if (-e $curPath.'/make.defaults') { - push(@files,$curPath.'/make.defaults'); + @profilefiles=$self->getPortageMakeParamHelper($curPath); + push(@files,reverse(@profilefiles)); + push(@files,@etcfiles); + + foreach (@files) { + my $importer = Shell::EnvImporter->new( shell => "bash", + file => $_, + auto_run => 1, + auto_import => 1 + ); + + $importer->shellobj->envcmd('set'); + $importer->run(); + + if ($ENV{$param} ne '') { + $v=$ENV{$param}; + $v=~s/\\t/ /g; + $v=~s/\t/ /g; + $v=~s/^\$'(.*)'$/$1/m; + $v=~s/^'(.*)'$/$1/m; + $v=~s/\\n/ /g; + $v=~s/\\|\'|\\'|\$//gmxs; + $v=~s/^\s//; + $v=~s/\s$//; + $v=~s/\s{2,}/ /g; } - if (! -e $curPath.'/parent') { last; } - $parent=$self->getFileContents($curPath.'/parent'); - chomp($parent); - $curPath.='/'.$parent; + + $importer->restore_env(); } - $buffer.=$self->getFileContents('/etc/make.conf').$self->getFileContents('/etc/make.globals'); - foreach(@files) { - $buffer.=$self->getFileContents($_); + # - Defaults > + if ($param eq 'PORTDIR' && !$v) { + $v='/usr/portage'; } - return $self->getParamFromFile($buffer,'ARCH','firstseen'); + return $v; } # Description: diff --git a/lib/PortageXS/Useflags.pm b/lib/PortageXS/Useflags.pm index dced3d0..a657ae1 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.6 2007/04/19 09:05:16 ian Exp $ +# header : $Header: /srv/cvsroot/portagexs/trunk/lib/PortageXS/Useflags.pm,v 1.7 2008/12/01 20:30:23 ian Exp $ # # ----------------------------------------------------------------------------- # @@ -25,6 +25,7 @@ our @EXPORT = qw( getUsedescs sortUseflags getUsemasksFromProfile + getUsemasksFromProfileHelper ); # Description: @@ -110,6 +111,28 @@ sub sortUseflags { return sort(@use1),sort(@use2); } +# Description: +# Helper for getUsemasksFromProfile() +sub getUsemasksFromProfileHelper { + my $self = shift; + my $curPath = shift; + my @files = (); + my $parent = ''; + + if (-e $curPath.'/use.mask') { + push(@files,$curPath.'/use.mask'); + } + if (! -e $curPath.'/parent') { + return @files; + } + $parent=$self->getFileContents($curPath.'/parent'); + foreach (split(/\n/,$parent)) { + push(@files,$self->getUsemasksFromProfileHelper($curPath.'/'.$_)); + } + + return @files; +} + # Description: # Returnvalue is an array containing all masked useflags set in the system-profile. # @@ -135,15 +158,17 @@ sub getUsemasksFromProfile { $curPath=$self->getProfilePath(); } - while(1) { - if (-e $curPath.'/use.mask') { - push(@files,$curPath.'/use.mask'); - } - if (! -e $curPath.'/parent') { last; } - $parent=$self->getFileContents($curPath.'/parent'); - chomp($parent); - $curPath.='/'.$parent; - } +# while(1) { +# print "-->".$curPath."<--\n"; +# if (-e $curPath.'/use.mask') { +# push(@files,$curPath.'/use.mask'); +# } +# if (! -e $curPath.'/parent') { last; } +# $parent=$self->getFileContents($curPath.'/parent'); +# chomp($parent); +# $curPath.='/'.$parent; +# } + @files = $self->getUsemasksFromProfileHelper($curPath); $buffer.=$self->getFileContents($self->{'PORTDIR'}.'/profiles/base/use.mask')."\n"; foreach(reverse(@files)) { diff --git a/lib/PortageXS/examples/getPortageMakeParam.pl b/lib/PortageXS/examples/getPortageMakeParam.pl new file mode 100755 index 0000000..942b34c --- /dev/null +++ b/lib/PortageXS/examples/getPortageMakeParam.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use lib '../..'; +use PortageXS; + +my $pxs=PortageXS->new(); +print "Arch: ".$pxs->getPortageMakeParam('ARCH')."\n";