On Wednesday 22 June 2005 05:28, Jason Stubbs wrote: > On Tuesday 21 June 2005 14:35, Alin Nastac wrote: > > This would be fine as long as LINGUAS do not appear in IUSE. When > > LINGUAS var is empty, the "equery uses" report would be an abomination . > > The whole point is to add this stuff to IUSE and improve the output > accordingly. Using current tools as a reason to not improve things isn't > really logical.
And here's a messy patch that took me ten minutes (after looking at equery code for the first time) that does just that. Output as follows: $ ./equery uses portage ... [ Found these USE variables for sys-apps/portage-2.0.51.22-r1 ] U I - - build : !!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used for creating build images and the first half of bootstrapping. - - selinux : !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur $ ./equery vars portage ... [ Found these environment variables for sys-apps/portage-2.0.51.22-r1 ] U I ----- LINGUAS + + en : <unknown> - - fr : <unknown> + + ja : <unknown> Regards, Jason Stubbs
--- /usr/bin/equery 2005-06-22 05:29:36.000000000 +0900 +++ equery 2005-06-22 06:14:45.000000000 +0900 @@ -451,6 +451,8 @@ except IOError: print_warn(5, "Could not load USE flag descriptions from " + ppath(gentoolkit.settings["PORTDIR"] + "/profiles/use.desc")) + use_expand = gentoolkit.settings["USE_EXPAND"].lower().split() + # Load local USE flag descriptions try: fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.local.desc") @@ -483,12 +485,19 @@ matches_found += 1 bestver = p.get_cpv() - iuse = p.get_env_var("IUSE") - - if iuse: - usevar = iuse.split() - else: - usevar = [] + iuse = p.get_env_var("IUSE").split() + + for usevar in iuse[:]: + found = False + for usehead in use_expand: + if usevar.startswith(usehead+"_"): + found = True + break + if found: + iuse.remove(usevar) + + usevar = iuse + usevar.sort() inuse = [] if p.is_installed(): @@ -570,6 +579,206 @@ " " + pp.localoption("-a, --all") + " - include non-installed packages\n" +class CmdDisplayVars(Command): + """Advanced report of a package's USE flags""" + def __init__(self): + self.default_opts = { + "installedOnly" : True + } + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + elif x in ["-a", "--all"]: + opts["installedOnly"] = False + else: + query = x + + if need_help or query == "": + print_info(0, self.longHelp()) + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + + (query, opts) = self.parseArgs(args) + + if not Config["piping"]: + print_info(3, "[ Searching for packages matching " + pp.pkgquery(query) + "... ]") + + matches = gentoolkit.find_packages(query, True) + + if not matches: + die(3, "No matching packages found for \"" + pp.pkgquery(query) + "\"") + + + useflags = gentoolkit.settings["USE"].split() + usedesc = {} + uselocaldesc = {} + + # Load global USE flag descriptions + try: + fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.desc") + usedesc = {} + for line in fd.readlines(): + if line[0] == "#": + continue + fields = line.split(" - ") + if len(fields) == 2: + usedesc[fields[0].strip()] = fields[1].strip() + except IOError: + print_warn(5, "Could not load USE flag descriptions from " + ppath(gentoolkit.settings["PORTDIR"] + "/profiles/use.desc")) + + # Load local USE flag descriptions + try: + fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.local.desc") + for line in fd.readlines(): + if line[0] == "#": + continue + fields = line.split(" - ") + if len(fields) == 2: + 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].strip()} + else: + uselocaldesc[catpkguse.group(1).strip()][catpkguse.group(2).strip()] = fields[1].strip() + except IOError: + print_warn(5, "Could not load USE flag descriptions from " + path(gentoolkit.settings["PORTDIR"] + "/profiles/use.desc")) + + if not Config["piping"]: + print_info(3, "[ Colour Code : " + pp.useflagon("set") + " " + pp.useflagoff("unset") + " ]") + print_info(3, "[ Legend : Left column (U) - USE flags from make.conf ]") + print_info(3, "[ : Right column (I) - USE flags packages was installed with ]") + + use_expand = gentoolkit.settings["USE_EXPAND"].lower().split() + + # Iterate through matches, printing a report for each package + matches_found = 0 + for p in matches: + + if not p.is_installed() and opts["installedOnly"]: + continue + + matches_found += 1 + + bestver = p.get_cpv() + iuse = p.get_env_var("IUSE").split() + + use_expand_map = {} + + for usevar in iuse[:]: + found = False + for usehead in use_expand: + if usevar.startswith(usehead+"_"): + found = True + use_expand_map[usevar] = usehead + break + if not found: + iuse.remove(usevar) + + usevar = use_expand_map.keys() + usevar.sort() + + inuse = [] + if p.is_installed(): + used = p.get_use_flags().split() + else: + # cosmetic issue here as noninstalled packages don't have "used" flags + used = useflags + + # store (inuse, inused, flag, desc) + output = [] + + for u in usevar: + inuse = 0 + inused = 0 + try: + desc = usedesc[u] + except KeyError: + try: + desc = uselocaldesc[p.get_category() + "/" + p.get_name()][u] + except KeyError: + desc = "" + + if u in p.get_settings("USE"): + inuse = 1 + if u in used: + inused = 1 + + output.append((inuse, inused, u, desc)) + + # pretty print + if output: + if not Config["piping"]: + print_info(0, "[ Found these environment variables for " + pp.cpv(bestver) + " ]") + print_info(3, pp.emph(" U I")) + + maxflag_len = 0 + for inuse, inused, u, desc in output: + if len(u) - len(use_expand_map[u]) - 1 > maxflag_len: + maxflag_len = len(u)-len(use_expand_map[u])-1 + + prev_usehead = "" + for in_makeconf, in_installed, flag, desc in output: + if use_expand_map[flag] != prev_usehead: + prev_usehead = use_expand_map[flag] + print "-----",prev_usehead.upper() + markers = ["-","+"] + colour = [pp.useflagoff, pp.useflagon] + if Config["piping"]: + print_info(0, markers[in_makeconf] + flag[len(prev_usehead)+1:]) + else: + if in_makeconf != in_installed: + print_info(0, pp.emph(" %s %s" % (markers[in_makeconf], markers[in_installed])), False) + else: + print_info(0, " %s %s" % (markers[in_makeconf], markers[in_installed]), False) + + print_info(0, " " + colour[in_makeconf](flag[len(prev_usehead)+1:].ljust(maxflag_len)), False) + + # print description + if desc: + print_info(0, " : " + desc) + else: + print_info(0, " : <unknown>") + else: + if not Config["piping"]: + print_info(1, "[ No environment variables found for " + pp.cpv(p.get_cpv()) + "]") + + if Config["verbosityLevel"] >= 2: + if matches_found == 0: + s = "" + if opts["installedOnly"]: + s = "installed " + die(3, "No " + s + "packages found for " + pp.pkgquery(query)) + + + def shortHelp(self): + return pp.localoption("<local-opts> ") + pp.pkgquery("pkgspec") + " - display environment variables for " + pp.pkgquery("pkgspec") + def longHelp(self): + return "Display environment for a given package\n" + \ + "\n" + \ + "Syntax:\n" + \ + " " + pp.command("vars") + pp.localoption(" <local-opts> ") + pp.pkgquery("pkgspec") + \ + "\n" + \ + pp.localoption("<local-opts>") + " is either of: \n" + \ + " " + pp.localoption("-a, --all") + " - include non-installed packages\n" + + class CmdDisplayDepGraph(Command): """Display tree graph of dependencies for a query""" @@ -1403,6 +1612,7 @@ "depends" : CmdListDepends(), "hasuse" : CmdFindUSEs(), "uses" : CmdDisplayUSEs(), + "vars" : CmdDisplayVars(), "depgraph" : CmdDisplayDepGraph(), "changes" : CmdDisplayChanges(), "size" : CmdDisplaySize(), @@ -1427,6 +1637,7 @@ "s" : "size", "t" : "stats", "u" : "uses", + "v" : "vars", "w" : "which" }
pgptUCDxEq7BC.pgp
Description: PGP signature