From 72a2244898e15bf99f55a8b6fff45c8e5ad0eafb Mon Sep 17 00:00:00 2001 From: agriffis Date: Tue, 13 Apr 2004 00:02:32 +0000 Subject: [PATCH] add ^ to remove keywords, -* support, and a man-page svn path=/; revision=102 --- trunk/src/ekeyword/ChangeLog | 7 +++ trunk/src/ekeyword/Makefile | 11 +++-- trunk/src/ekeyword/ekeyword | 77 +++++++++++++++++++++++++-------- trunk/src/ekeyword/ekeyword.1 | 12 ----- trunk/src/ekeyword/ekeyword.pod | 74 +++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 34 deletions(-) delete mode 100644 trunk/src/ekeyword/ekeyword.1 create mode 100644 trunk/src/ekeyword/ekeyword.pod diff --git a/trunk/src/ekeyword/ChangeLog b/trunk/src/ekeyword/ChangeLog index 3ab0d56..2748897 100644 --- a/trunk/src/ekeyword/ChangeLog +++ b/trunk/src/ekeyword/ChangeLog @@ -1,3 +1,10 @@ +12 Apr 2004 Aron Griffis + * Add ability to remove keywords with ^, for example: + ekeyword ^alpha blah.ebuild + * Add support for -*, for example: ekeyword -* would add it; + ekeyword ^* would remove it. + * Add a man-page for ekeyword + 09 Apr 2004 Aron Griffis * Add ability to modify all keywords via all, ~all, or -all, for example: ekeyword -all ~alpha ia64 blah.ebuild diff --git a/trunk/src/ekeyword/Makefile b/trunk/src/ekeyword/Makefile index 487930f..708863e 100644 --- a/trunk/src/ekeyword/Makefile +++ b/trunk/src/ekeyword/Makefile @@ -6,14 +6,17 @@ include ../../makedefs.mak -all: - echo "ALBACETE (AL-ba-seet n.) A single surprisingly long hair growing in the middle of nowhere." +%.1 : %.pod + pod2man $< > $@ -dist: +.PHONY: all +all: ekeyword.1 + +dist: ekeyword.1 mkdir -p ../../$(distdir)/src/ekeyword cp {Makefile,AUTHORS,README,TODO,ChangeLog,ekeyword,ekeyword.1} ../../$(distdir)/src/ekeyword/ -install: +install: all install -m 0755 ekeyword $(bindir)/ install -d $(docdir)/ekeyword install -m 0644 {AUTHORS,README,TODO,ChangeLog} $(docdir)/ekeyword/ diff --git a/trunk/src/ekeyword/ekeyword b/trunk/src/ekeyword/ekeyword index 4845c38..67f2ea7 100644 --- a/trunk/src/ekeyword/ekeyword +++ b/trunk/src/ekeyword/ekeyword @@ -12,7 +12,8 @@ # > KEYWORDS="x86 ppc sparc ~alpha" -my ($kw_re) = '^[-~]?\w+$'; +my ($kw_re) = '^(?:([-~^]?)(\w+)|([-^]\*))$'; +my (@kw); # make sure the cmdline consists of keywords and ebuilds unless (@ARGV > 1 && $ARGV[0] =~ /$kw_re/o) { @@ -30,37 +31,77 @@ for my $f (@ARGV) { next; } + print "$f\n"; + open I, "<$f" or die "Can't read $f: $!\n"; open O, ">$f.new" or die "Can't create $f.new: $!\n"; select O; while () { /^KEYWORDS/ or print, next; + + # extract the quoted section from KEYWORDS + (my $quoted = $_) =~ s/^.*["'](.*?)["'].*/$1/s; + + # replace -* with -star for our convenience below + $quoted =~ s/-\*/-star/; + for my $k (@kw) { - (my $arch = $k) =~ s/^[-~]//; - if ($arch eq 'all') { - # remove "all" so that only leader is left (blank, ~ or -) - $k =~ s/all//; - - # extract the quoted section from KEYWORDS - (my $quoted = $_) =~ s/^.*["'](.*?)["'].*/$1/s; - - # modify every keyword in the list - $quoted =~ s/(^|\s)[-~]?(?=\w)/$1$k/g; - - # re-insert to KEYWORDS - s/(["']).*?["']/$1$quoted$1/; - } else { - # modify just one keyword - s/[-~]?$arch\b/$k/ || s/(.*?['"].*?)\s*(?=['"])/$1 $k/; + my ($leader, $arch, $star) = ($k =~ /$kw_re/o); + + # handle -* and ^* + if (defined $star) { + $leader = substr $star,0,1; + $arch = 'star'; + } + + # remove keywords + if ($leader eq '^') { + if ($arch eq 'all') { + $quoted = ''; + } else { + $quoted =~ s/[-~]?\Q$arch\E\b//; + } + } + + # add or modify keywords + else { + if ($arch eq 'all') { + # modify every keyword in the list + $quoted =~ s/(^|\s)[-~]?(?=\w)/$1$leader/g; + } else { + # modify or add keyword + unless ($quoted =~ s/[-~]?\Q$arch\E\b/$leader$arch/) { + # modification failed, need to add + if ($arch eq 'star') { + $quoted = "$leader$arch $quoted"; + } else { + $quoted .= " $leader$arch"; + } + } + } } } + + # replace -star with -* + $quoted =~ s/-star\b/-*/; + + # fixup spacing + $quoted =~ s/^\s*(.*?)\s*$/$1/; # leading/trailing + $quoted =~ s/\s+/ /g; # inner + + # re-insert quoted to KEYWORDS + s/(["']).*?["']/$1$quoted$1/; + print $_, or die "Can't write $f.new: $!\n"; } close I; close O; + select STDOUT; - system "diff $f $f.new"; # don't die because the files might be the same + system "diff $f $f.new | grep -v '^[0-1]'"; rename "$f.new", "$f" or die "Can't rename: $!\n"; } + +# vim:ts=8 sw=4 diff --git a/trunk/src/ekeyword/ekeyword.1 b/trunk/src/ekeyword/ekeyword.1 deleted file mode 100644 index 339f4cd..0000000 --- a/trunk/src/ekeyword/ekeyword.1 +++ /dev/null @@ -1,12 +0,0 @@ -.TH ekeyword "1" "Nov 2003" "gentoolkit" -.SH NAME -ekeyword \- Gentoo: ebuild Keyword Changer -.SH SYNOPSIS -.B ekeyword -.SH BUGS -This tool does not yet have a man page. Feel free to submit a bug about it to -http://bugs.gentoo.org -.SH AUTHORS -This informative man page was written by Karl Trygve Kalleberg -. - diff --git a/trunk/src/ekeyword/ekeyword.pod b/trunk/src/ekeyword/ekeyword.pod new file mode 100644 index 0000000..1fac8ef --- /dev/null +++ b/trunk/src/ekeyword/ekeyword.pod @@ -0,0 +1,74 @@ +=head1 NAME + +ekeyword - Gentoo: modify package KEYWORDS + +=head1 SYNOPSIS + +ekeyword { arch|~arch|-arch|^arch } ebuild... + +=head1 DESCRIPTION + +This tool provides a simple way to add or update KEYWORDS in a set of +ebuilds. Each command-line argument is processed in order, so that +keywords are added to the current list as they appear, and ebuilds are +processed as they appear. + +Instead of specifying a specific arch, it's possible to use the word +"all". This causes the change to apply to all keywords presently +specified in the ebuild. + +The ^ leader instructs ekeyword to remove the specified arch. + +=head1 OPTIONS + +Presently ekeyword is simple enough that it supplies no options. +Probably I'll add B<--help> and B<--version> in the future, but for +now it's enough to track the gentoolkit version. + +=head1 EXAMPLES + +To mark a single arch stable: + + $ ekeyword alpha metalog-0.7-r1.ebuild + metalog-0.7-r1.ebuild + < KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + --- + > KEYWORDS="~x86 ~ppc ~sparc alpha ~mips ~hppa ~amd64 ~ia64" + +When bumping a package, to mark all arches for testing: + + $ ekeyword ~all metalog-0.7-r2.ebuild + metalog-0.7-r2.ebuild + < KEYWORDS="x86 ppc sparc alpha mips hppa amd64 ia64" + --- + > KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + +To signify that a package is broken for all arches except one: + + $ ekeyword ^all -* ~x86 metalog-0.7-r3.ebuild + metalog-0.7-r3.ebuild + < KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + --- + > KEYWORDS="-* ~x86" + +To do lots of things at once: + + $ ekeyword alpha metalog-0.7-r1.ebuild \ + ~all metalog-0.7-r2.ebuild ^all -* ~x86 metalog-0.7-r3.ebuild + metalog-0.7-r1.ebuild + < KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + --- + > KEYWORDS="~x86 ~ppc ~sparc alpha ~mips ~hppa ~amd64 ~ia64" + metalog-0.7-r2.ebuild + < KEYWORDS="x86 ppc sparc alpha mips hppa amd64 ia64" + --- + > KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + metalog-0.7-r3.ebuild + < KEYWORDS="~x86 ~ppc ~sparc ~alpha ~mips ~hppa ~amd64 ~ia64" + --- + > KEYWORDS="-* ~x86" + +=head1 NOTES + +This tool was written by Aron Griffis . Bugs +found should be filed against me at http://bugs.gentoo.org/ -- 2.26.2