move get_package_names and include_file to imgutils.pm
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6687 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
ecc824658f
commit
829df7a25e
@ -6,6 +6,9 @@ package imgutils;
|
||||
use strict;
|
||||
use warnings "all";
|
||||
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
|
||||
sub get_profile_def_filename {
|
||||
my $osver = shift;
|
||||
my $profile = shift;
|
||||
@ -32,4 +35,93 @@ sub get_profile_def_filename {
|
||||
return "";
|
||||
}
|
||||
|
||||
sub include_file
|
||||
{
|
||||
my $file = shift;
|
||||
my $idir = shift;
|
||||
my @text = ();
|
||||
unless ($file =~ /^\//) {
|
||||
$file = $idir."/".$file;
|
||||
}
|
||||
|
||||
open(INCLUDE,$file) || \
|
||||
return "#INCLUDEBAD:cannot open $file#";
|
||||
|
||||
while(<INCLUDE>) {
|
||||
chomp($_);
|
||||
s/\s+$//; #remove trailing spaces
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
push(@text, $_);
|
||||
}
|
||||
|
||||
close(INCLUDE);
|
||||
|
||||
return join(',', @text);
|
||||
}
|
||||
|
||||
sub get_package_names {
|
||||
my $plist_file_name=shift;
|
||||
my %pkgnames=();
|
||||
my @tmp_array=();
|
||||
|
||||
|
||||
if ($plist_file_name) {
|
||||
my $pkgfile;
|
||||
open($pkgfile,"<","$plist_file_name");
|
||||
while (<$pkgfile>) {
|
||||
chomp;
|
||||
s/\s+$//; #remove trailing white spaces
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
push(@tmp_array,$_);
|
||||
}
|
||||
close($pkgfile);
|
||||
|
||||
if ( @tmp_array > 0) {
|
||||
my $pkgtext=join(',',@tmp_array);
|
||||
|
||||
#handle the #INLCUDE# tag recursively
|
||||
my $idir = dirname($plist_file_name);
|
||||
my $doneincludes=0;
|
||||
while (not $doneincludes) {
|
||||
$doneincludes=1;
|
||||
if ($pkgtext =~ /#INCLUDE:[^#^\n]+#/) {
|
||||
$doneincludes=0;
|
||||
$pkgtext =~ s/#INCLUDE:([^#^\n]+)#/include_file($1,$idir)/eg;
|
||||
}
|
||||
}
|
||||
|
||||
#print "pkgtext=$pkgtext\n";
|
||||
my @tmp=split(',', $pkgtext);
|
||||
my $pass=1;
|
||||
foreach (@tmp) {
|
||||
my $idir;
|
||||
if (/^--/) {
|
||||
$idir="POST_REMOVE"; #line starts with -- means the package should be removed after otherpkgs are installed
|
||||
s/^--//;
|
||||
} elsif (/^-/) {
|
||||
$idir="PRE_REMOVE"; #line starts with single - means the package should be removed before otherpkgs are installed
|
||||
s/^-//;
|
||||
} elsif (/^#NEW_INSTALL_LIST#/) {
|
||||
$pass++;
|
||||
next;
|
||||
} elsif (/^#/) {
|
||||
# ignore all other comment lines
|
||||
next;
|
||||
} else {
|
||||
$idir=dirname($_);
|
||||
}
|
||||
my $fn=basename($_);
|
||||
if (exists($pkgnames{$pass}{$idir})) {
|
||||
my $pa=$pkgnames{$pass}{$idir};
|
||||
push(@$pa, $fn);
|
||||
} else {
|
||||
$pkgnames{$pass}{$idir}=[$fn];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return %pkgnames;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -281,7 +281,7 @@ unless ($onlyinitrd) {
|
||||
exit 1;
|
||||
}
|
||||
|
||||
my %pkg_hash=get_package_names($pkglist);
|
||||
my %pkg_hash=imgutils::get_package_names($pkglist);
|
||||
my $index=1;
|
||||
my $pass;
|
||||
foreach $pass (sort (keys(%pkg_hash))) {
|
||||
@ -307,7 +307,7 @@ unless ($onlyinitrd) {
|
||||
}
|
||||
my %extra_hash=();
|
||||
if ($otherpkglist) {
|
||||
%extra_hash=get_package_names($otherpkglist);
|
||||
%extra_hash=imgutils::get_package_names($otherpkglist);
|
||||
}
|
||||
my %extrapkgnames;
|
||||
|
||||
@ -1309,95 +1309,3 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
|
||||
copy(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel"); }
|
||||
|
||||
sub get_package_names {
|
||||
my $plist_file_name=shift;
|
||||
my %pkgnames=();
|
||||
my @tmp_array=();
|
||||
|
||||
|
||||
if ($plist_file_name) {
|
||||
my $pkgfile;
|
||||
open($pkgfile,"<","$plist_file_name");
|
||||
while (<$pkgfile>) {
|
||||
chomp;
|
||||
s/\s+$//; #remove trailing white spaces
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
push(@tmp_array,$_);
|
||||
}
|
||||
close($pkgfile);
|
||||
|
||||
if ( @tmp_array > 0) {
|
||||
my $pkgtext=join(',',@tmp_array);
|
||||
|
||||
#handle the #INLCUDE# tag recursively
|
||||
my $idir = dirname($plist_file_name);
|
||||
my $doneincludes=0;
|
||||
while (not $doneincludes) {
|
||||
$doneincludes=1;
|
||||
if ($pkgtext =~ /#INCLUDE:[^#^\n]+#/) {
|
||||
$doneincludes=0;
|
||||
$pkgtext =~ s/#INCLUDE:([^#^\n]+)#/include_file($1,$idir)/eg;
|
||||
}
|
||||
}
|
||||
|
||||
#print "pkgtext=$pkgtext\n";
|
||||
my @tmp=split(',', $pkgtext);
|
||||
my $pass=1;
|
||||
foreach (@tmp) {
|
||||
my $idir;
|
||||
if (/^--/) {
|
||||
$idir="POST_REMOVE"; #line starts with -- means the package should be removed after otherpkgs are installed
|
||||
s/^--//;
|
||||
} elsif (/^-/) {
|
||||
$idir="PRE_REMOVE"; #line starts with single - means the package should be removed before otherpkgs are installed
|
||||
s/^-//;
|
||||
} elsif (/^#NEW_INSTALL_LIST#/) {
|
||||
$pass++;
|
||||
next;
|
||||
} elsif (/^#/) {
|
||||
# ignore all other comment lines
|
||||
next;
|
||||
} else {
|
||||
$idir=dirname($_);
|
||||
}
|
||||
my $fn=basename($_);
|
||||
if (exists($pkgnames{$pass}{$idir})) {
|
||||
my $pa=$pkgnames{$pass}{$idir};
|
||||
push(@$pa, $fn);
|
||||
} else {
|
||||
$pkgnames{$pass}{$idir}=[$fn];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return %pkgnames;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub include_file
|
||||
{
|
||||
my $file = shift;
|
||||
my $idir = shift;
|
||||
my @text = ();
|
||||
unless ($file =~ /^\//) {
|
||||
$file = $idir."/".$file;
|
||||
}
|
||||
|
||||
open(INCLUDE,$file) || \
|
||||
return "#INCLUDEBAD:cannot open $file#";
|
||||
|
||||
while(<INCLUDE>) {
|
||||
chomp($_);
|
||||
s/\s+$//; #remove trailing spaces
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
push(@text, $_);
|
||||
}
|
||||
|
||||
close(INCLUDE);
|
||||
|
||||
return join(',', @text);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user