1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/env python3
# Copyright 2007 Charlie Shepherd
import os
import sys
from operator import attrgetter
try:
from pkgcore.restrictions.boolean import OrRestriction
from pkgcore.util import commandline
except ImportError:
print("Cannot import pkgcore!", file=sys.stderr)
print(
"Verify it is properly installed and/or PYTHONPATH is set correctly.",
file=sys.stderr,
)
if "--debug" not in sys.argv:
print("Add --debug to the commandline for a traceback.", file=sys.stderr)
else:
raise
sys.exit(1)
argparser = commandline.ArgumentParser(color=False, version=False)
argparser.add_argument("target", nargs="+", help="target package atoms")
argparser.add_argument(
"--repo",
action=commandline.StoreRepoObject,
help="repo to use (default from domain if omitted).",
)
argparser.add_argument(
"--print_type",
"-t",
default="cpvstr",
choices=("slotted_atom", "versioned_atom", "cpvstr"),
help="""type of atom to output:
'versioned_atom' : a valid versioned atom,
'slotted_atom' : a valid slotted atom,
'cpvstr' : the cpv of the package""",
)
@argparser.bind_final_check
def check_args(parser, namespace):
domain = namespace.domain
namespace.vdb = domain.all_installed_repos
if not namespace.repo:
# fallback to default repo
namespace.repo = namespace.config.get_default("repo")
namespace.restrict = OrRestriction(
*commandline.convert_to_restrict(namespace.target)
)
namespace.outputter = attrgetter(namespace.print_type)
@argparser.bind_main_func
def main(options, out, err):
repo = options.repo
for built in options.vdb.itermatch(options.restrict):
current = repo.match(built.unversioned_atom)
if current:
current = current[0]
oldflags = built.iuse & built.use
newflags = current.iuse & built.use
if (newflags != oldflags) or (current.iuse ^ built.iuse):
changed_flags = (oldflags ^ newflags) | (current.iuse ^ built.iuse)
if options.verbosity > 0:
out.write(
"package %s, %d flags have changed:\n\t%s"
% (
current.unversioned_atom,
len(changed_flags),
" ".join(changed_flags),
)
)
else:
out.write(options.outputter(current))
else:
if options.verbosity > 0:
out.write("%s is the same as it was before" % current.cpvstr)
if __name__ == "__main__":
tool = commandline.Tool(argparser)
sys.exit(tool())
|