* [gentoo-commits] gentoolkit r567 - in trunk/src: . ekeyword2
@ 2009-05-01 14:48 Paul Varner (fuzzyray)
0 siblings, 0 replies; only message in thread
From: Paul Varner (fuzzyray) @ 2009-05-01 14:48 UTC (permalink / raw
To: gentoo-commits
Author: fuzzyray
Date: 2009-05-01 14:48:36 +0000 (Fri, 01 May 2009)
New Revision: 567
Added:
trunk/src/ekeyword2/
trunk/src/ekeyword2/ekeyword2
Log:
Add ekeyword rewritten in python to repo
Added: trunk/src/ekeyword2/ekeyword2
===================================================================
--- trunk/src/ekeyword2/ekeyword2 (rev 0)
+++ trunk/src/ekeyword2/ekeyword2 2009-05-01 14:48:36 UTC (rev 567)
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+
+# Output like:
+# setuptools-0.6_rc9.ebuild
+# < KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~sparc-fbsd -x86 ~x86-fbsd"
+# ---
+# > KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~sparc-fbsd x86 ~x86-fbsd"
+
+from __future__ import with_statement
+from sys import argv
+from fnmatch import fnmatch
+from shutil import copyfile
+
+import re
+
+STABLE_KEYWORDS = frozenset((
+ 'alpha',
+ 'amd64',
+ 'amd64-fbsd',
+ 'arm',
+ 'hppa',
+ 'ia64',
+ 'mips',
+ 'm68k',
+ 'ppc',
+ 'ppc-macos',
+ 'ppc64',
+ 's390',
+ 'sparc',
+ 'sparc-fbsd',
+ 'sh',
+ 'x86',
+ 'x86-fbsd',
+))
+TEST_KEYWORDS = frozenset(['~'+k for k in STABLE_KEYWORDS])
+KNOWN_KEYWORDS = STABLE_KEYWORDS | TEST_KEYWORDS
+
+kw_re = re.compile(r'KEYWORDS="([^"]*)"')
+ebuilds = set([x for x in argv[1:] if fnmatch(x, '*.ebuild')])
+pretend = not bool(set(('-p', '--pretend',)) - set(argv))
+keywords = frozenset(argv[1:]) - ebuilds - set(('-p', '--pretend'))
+
+if not ebuilds:
+ print 'usage: ekeyword [-p|--pretend] [~] [[~|-]arch [[~|-]arch]...] ebuild [ebuild...]'
+
+for e in ebuilds:
+ # TODO: error handling for file I/O
+ kw = set(keywords)
+ if not pretend:
+ try:
+ copyfile(e, e+'.orig')
+ except IOError:
+ print "Can't copy file %s. Check permissions." % e
+ exit(1)
+ try:
+ with open(e) as c:
+ ebuild = c.read()
+ except IOError:
+ print "Can't open file %s. Aborting." % e
+ exit(1)
+
+ orig = kw_re.search(ebuild)
+ curkw = set(orig.groups()[0].split())
+
+ if '~' in kw:
+ kw.remove('~')
+ curkw = set(['~'+k if k in STABLE_KEYWORDS else k for k in curkw])
+
+ for k in kw:
+ if k[0] == '-':
+ curkw -= set(('~'+k[1:], k[1:],))
+ elif k[0] == '~':
+ curkw -= set((k[1:],))
+ curkw |= set((k,))
+ else:
+ curkw -= set(('~'+k,))
+ curkw |= set((k,))
+
+ result = 'KEYWORDS="%s"' % ' '.join(sorted(curkw))
+ if not pretend:
+ try:
+ with open(e, 'w') as rebuild:
+ rebuild.write(kw_re.sub(result, ebuild))
+ except IOError:
+ print "Can't write file %s. Aborting." % e
+ exit(1)
+
+ unknown_keywords = curkw - KNOWN_KEYWORDS
+ if unknown_keywords:
+ print "\nWarning: Unknown keywords '%s'.\n" % ', '.join(sorted(unknown_keywords))
+
+ print '<<< %s' % orig.group()
+ print '>>> %s' % result
Property changes on: trunk/src/ekeyword2/ekeyword2
___________________________________________________________________
Name: svn:executable
+ *
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-05-01 14:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-01 14:48 [gentoo-commits] gentoolkit r567 - in trunk/src: . ekeyword2 Paul Varner (fuzzyray)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox