From: idl0r Date: Fri, 2 Jul 2010 15:30:13 +0000 (-0000) Subject: ekeyword: Add file_parse, get_portdir and get_architectures functions. X-Git-Tag: gentoolkit-dev-0.2.7~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bad5e224ff25724efd106412165d4bd55d130700;p=gentoolkit.git ekeyword: Add file_parse, get_portdir and get_architectures functions. file_parse is a file parser which strips trailing and starting whitespace, replaces multiple whitespace by one whitespace and ignores comments. It returns an array. get_portdir uses portageq to determine the PORTDIR value. get_architectures reads $PORTDIR/profiles/arch.list and adds all available architectures to the %ARCH hash which can be used for validation. svn path=/trunk/gentoolkit-dev/; revision=787 --- diff --git a/ChangeLog b/ChangeLog index 606d036..8e4d904 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ 2010-07-02: Christian Ruppert * imlate: Don't ignore package names without category. * ekeyword: Show "diff -U 0" to cover all changes. + Add file_parse, get_portdir and get_architectures functions. + file_parse is a file parser which strips trailing and starting + whitespace, replaces multiple whitespace by one whitespace and ignores + comments. It returns an array. + get_portdir uses portageq to determine the PORTDIR value. + get_architectures reads $PORTDIR/profiles/arch.list and adds all + available architectures to the %ARCH hash which can be used for + validation. 2010-05-17: Christian Ruppert * echangelog: Update copyright in other files too (except binaries and diff --git a/src/ekeyword/ekeyword b/src/ekeyword/ekeyword index 74cff0f..dab5189 100755 --- a/src/ekeyword/ekeyword +++ b/src/ekeyword/ekeyword @@ -13,6 +13,50 @@ my ($kw_re) = '^(?:([-~^]?)(\w[\w-]*)|([-^]\*))$'; my (@kw); +sub file_parse { + my $fname = shift; + my @content = (); + + if ( ! -r $fname ) { + printf STDERR ("Error: File '%s' doesn't exist or is not readable!\n", $fname); + exit(1); + } + + open(FILE, '<', $fname); + while(defined(my $line = )) { + chomp($line); + $line =~ s/^\s*//g; + $line =~ s/\s*$//g; + $line =~ s/\s+/ /g; + next if length($line) eq 0; + + next if $line =~ m/^#/; + + push(@content, $line); + } + close(FILE); + + return @content; +} + +sub get_portdir() { + open(PORTAGEQ, '-|', 'portageq portdir'); + chomp(my $portdir = ); + close(PORTAGEQ); + + if (length($portdir) eq 0) { + printf STDERR ("Error: Couldn't determine your PORTDIR...\n"); + exit(1); + } + return $portdir; +} + +sub get_architectures() { + foreach my $arch (file_parse("${PORTDIR}/profiles/arch.list")) { + $ARCH{$arch} = 0; + } +} + # make sure the cmdline consists of keywords and ebuilds unless (@ARGV > 0) { # NOTE: ~all will ignore all -arch keywords