# | Just uses the new IUSE parameter in ebuilds |
# `-------------------------------------------------------'
def uses(query):
- pkg = smart_pkgsplit(query)
- matches = search(pkg[1])
+
+ tup = smart_pkgsplit(query)
+ if tup[0] and tup[1]:
+ matches = [ tup[0] + "/" + tup[1] ]
+ elif tup[1]:
+ matches = search(tup[1])
+
useflags = portage.config()["USE"].split()
usedesc = {}
uselocaldesc = {}
# open up use.desc
+
try:
# TODO: use portage settings
fd = open("/usr/portage/profiles/use.desc")
catpkguse = re.search("([a-z]+-[a-z]+/.*):(.*)", fields[0])
if catpkguse:
if not uselocaldesc.has_key(catpkguse.group(1).strip()):
- uselocaldesc[catpkguse.group(1).strip()] = {catpkguse.group(2).strip() : fields[1]}
+ uselocaldesc[catpkguse.group(1).strip()] = {catpkguse.group(2).strip() : fields[1].strip()}
else:
- uselocaldesc[catpkguse.group(1).strip()][catpkguse.group(2).strip()] = fields[1]
+ uselocaldesc[catpkguse.group(1).strip()][catpkguse.group(2).strip()] = fields[1].strip()
except IOError:
pass
-
-
print "[ Colour Code : " + green("set") + " " + red("unset") + " ]"
print "[ Legend : (U) Col 1 - Current USE flags ]"
print "[ : (I) Col 2 - Installed With USE flags ]"
for p in matches:
- print white(" U I ") + "[ Found these USE variables in : " + white(p) + " ]"
-
curver = portage.db["/"]["vartree"].dep_bestmatch(p)
- iuse = portage.db["/"]["porttree"].dbapi.aux_get(curver,["IUSE"])
+
+ if curver:
+ try:
+ iuse = portage.db["/"]["porttree"].dbapi.aux_get(curver,["IUSE"])
+ except KeyError:
+ print "[ Error Occured. Ebuild not found for :", white(p), "]"
+ else:
+ print "[ No USE flags found for :", white(p), "]"
+ continue
+
if iuse: usevar = iuse[0].split()
else: usevar = []
used = open(installed[-1] + "/USE").read().split()
except:
used = []
+
+ # store (inuse, inused, flag, desc)
+ output = []
for u in usevar:
inuse = 0
inused = 0
- flag = ["-","+"]
- colour = [red, green]
try:
desc = usedesc[u]
except KeyError:
- desc = ""
-
- if u in useflags: inuse = 1
- if u in used: inused = 1
-
- if inuse != inused:
- print yellow(" %s %s" % (flag[inuse], flag[inused])),
- else:
- print " %s %s" % (flag[inuse], flag[inused]),
- print colour[inuse](u),
-
- # check for local useflags
- if uselocaldesc.has_key(p):
try:
desc = uselocaldesc[p][u]
except KeyError:
desc = ""
- # print description
- if desc:
- print ":", desc
- else:
- print ": unknown"
+
+ if u in useflags: inuse = 1
+ if u in used: inused = 1
+
+ output.append((inuse, inused, u, desc))
+
+ # pretty print
+ if output:
+ print
+ print white(" U I ") + "[ Found these USE variables in : " + white(p) + " ]"
+ maxflag_len = 0
+ for inuse, inused, u, desc in output:
+ if len(u) > maxflag_len:
+ maxflag_len = len(u)
+
+ for inuse, inused, u, desc in output:
+ flag = ["-","+"]
+ colour = [red, green]
+ if inuse != inused:
+ print yellow(" %s %s" % (flag[inuse], flag[inused])),
+ else:
+ print " %s %s" % (flag[inuse], flag[inused]),
+
+ print colour[inuse](u.ljust(maxflag_len)),
+
+ # print description
+ if desc:
+ print ":", desc
+ else:
+ print ": unknown"
+ else:
+ print "[ No USE flags found for :", white(p), "]"
+
return
# deprecated - this was a hack anyway