Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 267565 | Differences between
and this patch

Collapse All | Expand All

(-)ekeyword2 (-12 / +28 lines)
Lines 10-15 Link Here
10
from sys import argv
10
from sys import argv
11
from fnmatch import fnmatch
11
from fnmatch import fnmatch
12
from shutil import copyfile
12
from shutil import copyfile
13
from os import environ as env
13
14
14
import re
15
import re
15
import string
16
import string
Lines 17-32 Link Here
17
from portage import settings
18
from portage import settings
18
19
19
STABLE_KEYWORDS = frozenset(settings["PORTAGE_ARCHLIST"].split())
20
STABLE_KEYWORDS = frozenset(settings["PORTAGE_ARCHLIST"].split())
20
TEST_KEYWORDS = frozenset(['~'+k for k in STABLE_KEYWORDS])
21
BROKEN_KEYWORDS = frozenset(['-*'] + ['-'+k for k in STABLE_KEYWORDS])
21
KNOWN_KEYWORDS = STABLE_KEYWORDS | TEST_KEYWORDS
22
TEST_KEYWORDS   = frozenset(['~'+k for k in STABLE_KEYWORDS])
23
KNOWN_KEYWORDS  = STABLE_KEYWORDS | TEST_KEYWORDS | BROKEN_KEYWORDS
22
24
25
argv = set(argv[1:])
23
kw_re = re.compile(r'KEYWORDS="([^"]*)"')
26
kw_re = re.compile(r'KEYWORDS="([^"]*)"')
24
ebuilds = set([x for x in argv[1:] if fnmatch(x, '*.ebuild')])
27
ebuilds = frozenset([x for x in argv if fnmatch(x, '*.ebuild')])
25
pretend = not bool(set(('-p', '--pretend',)) - set(argv))
28
pretend = bool(argv.intersection(('-p', '--pretend',)))
26
keywords = frozenset(argv[1:]) - ebuilds - set(('-p', '--pretend'))
29
keywords = argv.difference(('-p', '--pretend',)) - ebuilds
27
30
28
if not ebuilds:
31
if not ebuilds:
29
	print 'usage: ekeyword [-p|--pretend] [~] [[~|-]arch [[~|-]arch]...] ebuild [ebuild...]'
32
	print 'usage: ekeyword [-p|--pretend] [^|~|-][all] [[^|~|-]arch [[^|~|-]arch]...] ebuild [ebuild...]'
30
33
31
for e in ebuilds:
34
for e in ebuilds:
32
	# TODO: error handling for file I/O
35
	# TODO: error handling for file I/O
Lines 47-66 Link Here
47
	orig = kw_re.search(ebuild)
50
	orig = kw_re.search(ebuild)
48
	curkw = set(orig.groups()[0].split())
51
	curkw = set(orig.groups()[0].split())
49
52
50
	if '~' in kw:
53
	# ^ or ^all by itself means remove all keywords
51
		kw.remove('~')
54
	# (however, other keywords established in the same args still get set.)
55
	if kw.intersection(('^', '^all',)):
56
		kw -= set(('^', '^all',))
57
		curkw = set()
58
59
	# ~ or ~all by itself means set ~keyword for all keywords
60
	# since ~ expands to "$HOME" in the shell, assume the user meant ~ if we see
61
	# the expansion of "$HOME". (Hope there's no user named 'all'.)
62
	if kw.intersection(('~', '~all', env['HOME'],)):
63
		kw -= set(('~', '~all', env['HOME'],))
52
		curkw = set(['~'+k if k in STABLE_KEYWORDS else k for k in curkw])
64
		curkw = set(['~'+k if k in STABLE_KEYWORDS else k for k in curkw])
53
65
54
	for k in kw:
66
	for k in kw:
55
		if k[0] == '-':
67
		# Remove keywords starting with ^
56
			curkw -= set(('~'+k[1:], k[1:],))
68
		if k[0] == '^':
57
		elif k[0] == '~':
69
			curkw -= set((k[1:], '-'+k[1:], '~'+k[1:], ))
58
			curkw -= set((k[1:],))
70
		# Set ~ and - keywords to TEST and BROKEN, respectively
71
		elif k[0] == '~' or k[0] == '-':
72
			curkw -= set((k[1:], '-'+k[1:], '~'+k[1:], ))
59
			curkw |= set((k,))
73
			curkw |= set((k,))
74
		# Set remaining keywords to STABLE
60
		else:
75
		else:
61
			curkw -= set(('~'+k,))
76
			curkw -= set(('~'+k,))
62
			curkw |= set((k,))
77
			curkw |= set((k,))
63
78
79
	# Sort by arch, then OS (Luckily, this makes -* show up first if it's there)
64
	result = 'KEYWORDS="%s"' % ' '.join(sorted(curkw,
80
	result = 'KEYWORDS="%s"' % ' '.join(sorted(curkw,
65
		key=lambda x: x.strip(string.punctuation).lower()))
81
		key=lambda x: x.strip(string.punctuation).lower()))
66
82

Return to bug 267565