mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-20 01:12:18 +00:00
refactor(pkglist): share package-list line filtering
Share line normalization and directive filtering across the legacy text reader, its include reader and the record reader. Keep leading whitespace in legacy includes and leave each parser expansion policy unchanged. Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com>
This commit is contained in:
@@ -1819,6 +1819,21 @@ sub get_envlist
|
||||
return ($envlist, $pkgtext);
|
||||
}
|
||||
|
||||
sub _pkglist_line
|
||||
{
|
||||
my ($line, $trim_leading) = @_;
|
||||
chomp($line);
|
||||
$line =~ s/\s+$//;
|
||||
$line =~ s/^\s*// if $trim_leading;
|
||||
return if $line =~ /^\s*$/;
|
||||
return
|
||||
if ($line =~ /^\s*#/
|
||||
&& $line !~ /^\s*#INCLUDE:[^#^\n]+#/
|
||||
&& $line !~ /^\s*#NEW_INSTALL_LIST#/
|
||||
&& $line !~ /^\s*#ENV:[^#^\n]+#/);
|
||||
return $line;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head3 get_pkglist_text
|
||||
@@ -1846,15 +1861,8 @@ sub get_pkglist_tex
|
||||
{
|
||||
while (readline(FILE1))
|
||||
{
|
||||
chomp($_); #remove newline
|
||||
s/\s+$//; #remove trailing spaces
|
||||
s/^\s*//; #remove leading blanks
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
next
|
||||
if (/^\s*#/
|
||||
&& !/^\s*#INCLUDE:[^#^\n]+#/
|
||||
&& !/^\s*#NEW_INSTALL_LIST#/
|
||||
&& !/^\s*#ENV:[^#^\n]+#/); #-- skip comments
|
||||
$_ = _pkglist_line($_, 1);
|
||||
next unless defined $_;
|
||||
if (/^@(.*)/)
|
||||
{ #for groups that has space in name
|
||||
my $save = $1;
|
||||
@@ -1925,15 +1933,8 @@ sub pkglist_file_records
|
||||
open(my $fh, '<', $file) or return ("#INCLUDEBAD:cannot open pkglist file $file#");
|
||||
while (my $line = <$fh>)
|
||||
{
|
||||
chomp($line);
|
||||
$line =~ s/\s+$//;
|
||||
$line =~ s/^\s*//;
|
||||
next if $line eq '';
|
||||
next
|
||||
if ($line =~ /^#/
|
||||
&& $line !~ /^#INCLUDE:[^#^\n]+#/
|
||||
&& $line !~ /^#NEW_INSTALL_LIST#/
|
||||
&& $line !~ /^#ENV:[^#^\n]+#/);
|
||||
$line = _pkglist_line($line, 1);
|
||||
next unless defined $line;
|
||||
if ($line =~ /^#INCLUDE:([^#^\n]+)#(.*)$/ && $depth < 20)
|
||||
{
|
||||
my ($name, $note) = ($1, $2);
|
||||
@@ -1974,14 +1975,9 @@ sub includefile
|
||||
|
||||
while (<INCLUDE>)
|
||||
{
|
||||
chomp($_); #remove newline
|
||||
s/\s+$//; #remove trailing spaces
|
||||
next if /^\s*$/; #-- skip empty lines
|
||||
next
|
||||
if (/^\s*#/
|
||||
&& !/^\s*#INCLUDE:[^#^\n]+#/
|
||||
&& !/^\s*#NEW_INSTALL_LIST#/
|
||||
&& !/^\s*#ENV:[^#^\n]+#/); #-- skip comments
|
||||
# Legacy includes preserve leading whitespace, unlike root package lists.
|
||||
$_ = _pkglist_line($_, 0);
|
||||
next unless defined $_;
|
||||
if (/^@(.*)/)
|
||||
{ #for groups that has space in name
|
||||
my $save = $1;
|
||||
|
||||
Reference in New Issue
Block a user