From 2f4ffdb741e28ceb2b7dc5610b6b72d64f17cceb Mon Sep 17 00:00:00 2001 From: liquidx Date: Thu, 24 Apr 2003 19:14:15 +0000 Subject: [PATCH] More fixes to UI and exceptions svn path=/; revision=19 --- trunk/src/etcat/etcat | 85 +++++++++++++++++++++++++++-------------- trunk/src/etcat/etcat.1 | 6 +-- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/trunk/src/etcat/etcat b/trunk/src/etcat/etcat index 6addddb..78185bc 100755 --- a/trunk/src/etcat/etcat +++ b/trunk/src/etcat/etcat @@ -486,12 +486,18 @@ def versions(query): # | 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") @@ -516,23 +522,28 @@ def uses(query): 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 = [] @@ -544,37 +555,53 @@ def uses(query): 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 diff --git a/trunk/src/etcat/etcat.1 b/trunk/src/etcat/etcat.1 index 6773f10..8919359 100644 --- a/trunk/src/etcat/etcat.1 +++ b/trunk/src/etcat/etcat.1 @@ -16,9 +16,9 @@ More specifically, it lists the versions available highlighted by their status ( .LP It also employes a smarter package query syntax than emerge where examples such as: .LP .IP -mozilla\-1.1.br +mozilla\-1.1 +.br mozilla\-1.* - .LP are accepted. @@ -28,7 +28,7 @@ are accepted. .br \fBbelongs\fR <\fI/path/to/file\fR> [\fIcategory\fR] .IP -Searches for the package which a file belongs to with an option to restrict a search to a single or multiple category. Wildcards in the category name is accepted (eg. etcat belongs /usr/lib/libmpeg.so "media\-*") +Searches for the package which a file belongs to with an option to restrict a search to a single or multiple category. Wildcards in the category name is accepted to speed up searching. (eg. etcat belongs /usr/lib/libmpeg.so "media\-*") .LP \fB\-c\fR <\fIpackage\-[version]\fR> -- 2.26.2