Skip to content

Commit

Permalink
Import PortageXS-0.02.09
Browse files Browse the repository at this point in the history
  • Loading branch information
Torsten Veller committed Jan 16, 2011
1 parent 5f6bb6d commit efcaa15
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 27 deletions.
10 changes: 9 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>)
- Speedup functions getFilesOfInstalledPackage(), fileBelongsToPackage()
Expand Down
4 changes: 2 additions & 2 deletions lib/PortageXS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package PortageXS;
#
# author : Christian Hartmann <[email protected]>
# 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 $
#
# -----------------------------------------------------------------------------
#
Expand All @@ -17,7 +17,7 @@ package PortageXS;
#
# -----------------------------------------------------------------------------

$VERSION='0.02.07';
$VERSION='0.02.09';

use PortageXS::Core;
use PortageXS::System;
Expand Down
86 changes: 72 additions & 14 deletions lib/PortageXS/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package PortageXS::Core;
#
# author : Christian Hartmann <[email protected]>
# 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 $
#
# -----------------------------------------------------------------------------
#
Expand All @@ -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
Expand Down Expand Up @@ -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!');
Expand All @@ -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:
Expand Down
45 changes: 35 additions & 10 deletions lib/PortageXS/Useflags.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package PortageXS::Useflags;
#
# author : Christian Hartmann <[email protected]>
# 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 $
#
# -----------------------------------------------------------------------------
#
Expand All @@ -25,6 +25,7 @@ our @EXPORT = qw(
getUsedescs
sortUseflags
getUsemasksFromProfile
getUsemasksFromProfileHelper
);

# Description:
Expand Down Expand Up @@ -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.
#
Expand All @@ -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)) {
Expand Down
10 changes: 10 additions & 0 deletions lib/PortageXS/examples/getPortageMakeParam.pl
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit efcaa15

Please sign in to comment.