def format_depend(self, dep, dep_is_displayed): """Format a dependency for printing. @type dep: L{gentoolkit.dependencies.Dependencies} @param dep: the dependency to display """ # Don't print blank lines if dep_is_displayed and not self.verbose: return depth = getattr(dep, 'depth', 0) indent = " " * depth mdep = dep.matching_dep use_conditional = "" if mdep.use_conditional: use_conditional = " & ".join( pp.useflag(u) for u in mdep.use_conditional.split() ) if mdep.operator == '=*': formatted_dep = '=%s*' % str(mdep.cpv) else: formatted_dep = mdep.operator + str(mdep.cpv) if mdep.slot: formatted_dep += pp.emph(':') + pp.slot(mdep.slot) if mdep.use: useflags = pp.useflag(','.join(mdep.use.tokens)) formatted_dep += (pp.emph('[') + useflags + pp.emph(']')) if dep_is_displayed: indent = indent + " " * len(str(dep.cpv)) self.print_fn(indent, '', use_conditional, formatted_dep) else: self.print_fn(indent, str(dep.cpv), use_conditional, formatted_dep)
def print_legend(): """Print a legend to explain the output format.""" print("[ Legend : %s - final flag setting for installation]" % pp.emph("U")) print("[ : %s - package is installed with flag ]" % pp.emph("I")) print("[ Colors : %s, %s ]" % ( pp.useflag("set", enabled=True), pp.useflag("unset", enabled=False)))
def display_useflags(output): """Print USE flag descriptions and statuses. @type output: list @param output: [(inuse, inused, flag, desc, restrict), ...] inuse (int) = 0 or 1; if 1, flag is set in make.conf inused (int) = 0 or 1; if 1, package is installed with flag enabled flag (str) = the name of the USE flag desc (str) = the flag's description restrict (str) = corresponds to the text of restrict in metadata """ maxflag_len = len(max([t[2] for t in output], key=len)) twrap = TextWrapper() twrap.width = CONFIG['termWidth'] twrap.subsequent_indent = " " * (maxflag_len + 8) markers = ("-", "+") color = (partial(pp.useflag, enabled=False), partial(pp.useflag, enabled=True)) for in_makeconf, in_installed, flag, desc, restrict in output: if CONFIG['verbose']: flag_name = "" if in_makeconf != in_installed: flag_name += pp.emph( " %s %s" % (markers[in_makeconf], markers[in_installed])) else: flag_name += (" %s %s" % (markers[in_makeconf], markers[in_installed])) flag_name += " " + color[in_makeconf](flag.ljust(maxflag_len)) flag_name += " : " # Strip initial whitespace at the start of the description # Bug 432530 if desc: desc = desc.lstrip() # print description if restrict: restrict = "(%s %s)" % (pp.emph("Restricted to"), pp.cpv(restrict)) twrap.initial_indent = flag_name pp.uprint(twrap.fill(restrict)) if desc: twrap.initial_indent = twrap.subsequent_indent pp.uprint(twrap.fill(desc)) else: print(" : <unknown>") else: if desc: twrap.initial_indent = flag_name desc = twrap.fill(desc) pp.uprint(desc) else: twrap.initial_indent = flag_name print(twrap.fill("<unknown>")) else: pp.uprint(markers[in_makeconf] + flag)
def print_summary(self): """Print a summary of the query.""" if self.query_type == "set": cat_str = "" pkg_str = pp.emph(self.query) else: try: cat, pkg = self.category, self.name + self.fullversion except errors.GentoolkitInvalidCPV: cat = '' pkg = self.atom if cat and not self.is_regex: cat_str = "in %s " % pp.emph(cat.lstrip('><=~!')) else: cat_str = "" if self.is_regex: pkg_str = pp.emph(self.query) else: pkg_str = pp.emph(pkg) repo = '' if self.repo_filter is not None: repo = ' %s' % pp.section(self.repo_filter) pp.uprint(" * Searching%s for %s %s..." % (repo, pkg_str, cat_str))
def format_depend(self, dep, dep_is_displayed): """Format a dependency for printing. @type dep: L{gentoolkit.dependencies.Dependencies} @param dep: the dependency to display """ # Don't print blank lines if dep_is_displayed and not self.verbose: return depth = getattr(dep, 'depth', 0) indent = " " * depth mdep = dep.matching_dep use_conditional = "" if mdep.use_conditional: use_conditional = " & ".join( pp.useflag(u) for u in mdep.use_conditional.split()) if mdep.operator == '=*': formatted_dep = '=%s*' % str(mdep.cpv) else: formatted_dep = mdep.operator + str(mdep.cpv) if mdep.slot: formatted_dep += pp.emph(':') + pp.slot(mdep.slot) if mdep.use: useflags = pp.useflag(','.join(mdep.use.tokens)) formatted_dep += (pp.emph('[') + useflags + pp.emph(']')) if dep_is_displayed: indent = indent + " " * len(str(dep.cpv)) self.print_fn(indent, '', use_conditional, formatted_dep) else: self.print_fn(indent, str(dep.cpv), use_conditional, formatted_dep)
def rebuild_use(self): if not self.options["quiet"]: print() print(" -- Scanning installed packages for USE flag settings that") print(" do not match the default settings") system_use = portage.settings["USE"].split() output = RebuildPrinter( "use", self.options["pretend"], self.options["exact"], self.options["slot"] ) pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use) pkg_count = len(pkgs) if self.options["verbose"]: print() print( ( pp.emph(" -- Found ") + pp.number(str(pkg_count)) + pp.emph(" packages that need entries") ) ) # print pp.emph(" package.use to maintain their current setting") pkg_keys = [] if pkgs: pkg_keys = sorted(pkgs) # print len(pkgs) if self.options["pretend"] and not self.options["quiet"]: print() print( pp.globaloption( " -- These are the installed packages & use flags " + "that were detected" ) ) print( pp.globaloption( " to need use flag settings other " + "than the defaults." ) ) print() elif not self.options["quiet"]: print(" -- preparing pkgs for file entries") for pkg in pkg_keys: output(pkg, pkgs[pkg], cp_counts[pkg]) if self.options["verbose"]: message = ( pp.emph(" ") + pp.number(str(pkg_count)) + pp.emph(" different packages") ) print() print(pp.globaloption(" -- Totals")) print(message) # print # unique = list(unique_flags) # unique.sort() # print unique if not self.options["pretend"]: filepath = os.path.expanduser("~/package.use.test") self.save_file(filepath, output.lines)
def not_implemented(self, target): """Prints a standard module not implemented message""" print() print(pp.error( "Sorry %s module and/or target is not implenented yet." % pp.emph(self.command_name))) print("module: %s, target: %s" %(pp.emph(self.module_name), pp.emph(target))) print()
def mod_usage(mod_name="module", arg="pkgspec", optional=False): """Provide a consistant usage message to the calling module. @type arg: string @param arg: what kind of argument the module takes (pkgspec, filename, etc) @type optional: bool @param optional: is the argument optional? """ return "%(usage)s: %(mod_name)s [%(opts)s] %(arg)s" % { 'usage': pp.emph("Usage"), 'mod_name': pp.command(mod_name), 'opts': pp.localoption("options"), 'arg': ("[%s]" % pp.emph(arg)) if optional else pp.emph(arg) }
def checks_printer(cpv, data, verbose=True, only_failures=False): """Output formatted results of pkg file(s) checks""" seen = [] n_passed, n_checked, errs = data n_failed = n_checked - n_passed if only_failures and not n_failed: return else: if verbose: if not cpv in seen: pp.uprint("* Checking %s ..." % (pp.emph(str(cpv)))) seen.append(cpv) else: pp.uprint("%s:" % cpv, end=' ') if verbose: for err in errs: sys.stderr.write(pp.error(err)) if verbose: n_passed = pp.number(str(n_passed)) n_checked = pp.number(str(n_checked)) info = " %(n_passed)s out of %(n_checked)s files passed" print(info % locals()) else: print("failed(%s)" % n_failed)
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="changes")) print() print(pp.emph("examples")) print(" c portage # show latest visible " "version's entry") print(" c portage --full --limit=3 # show 3 latest entries") print(" c '=sys-apps/portage-2.1.6*' # use atom syntax") print(" c portage --from=2.2_rc60 --to=2.2_rc70 # use version ranges") print() print(pp.command("options")) print( format_options(( (" -h, --help", "display this help message"), (" -l, --latest", "display only the latest ChangeLog entry"), (" -f, --full", "display the full ChangeLog"), (" --limit=NUM", "limit the number of entries displayed (with --full)"), (" --from=VER", "set which version to display from"), (" --to=VER", "set which version to display to"), )))
def main(input_args): """Parse input and run the program""" short_opts = "hai" long_opts = ('help', 'all', 'ignore-linguas') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) # # Output # first_run = True legend_printed = False for query in (Query(x) for x in queries): if not first_run: print() if QUERY_OPTS["all_versions"]: matches = query.find(include_masked=True) else: matches = [query.find_best()] if not any(matches): raise errors.GentoolkitNoMatches(query) matches.sort() global_usedesc = get_global_useflags() for pkg in matches: output = get_output_descriptions(pkg, global_usedesc) if output: if CONFIG['verbose']: if not legend_printed: print_legend() legend_printed = True print((" * Found these USE flags for %s:" % pp.cpv(str(pkg.cpv)))) print(pp.emph(" U I")) display_useflags(output) else: if CONFIG['verbose']: sys.stderr.write( pp.warn("No USE flags found for %s" % pp.cpv(pkg.cpv)) ) first_run = False
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="files")) print() print(pp.command("options")) print( format_options( ((" -h, --help", "display this help message"), (" -m, --md5sum", "include MD5 sum in output"), (" -s, --timestamp", "include timestamp in output"), (" -t, --type", "include file type in output"), (" --tree", "display results in a tree (turns off other options)"), (" -f, --filter=RULES", "filter output by file type"), (" RULES", "a comma-separated list (no spaces); choose from:")))) print(" " * 24, ', '.join(pp.emph(x) for x in FILTER_RULES))
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="hasuse", arg="USE-flag")) print() print(pp.command("options")) print( format_options( ((" -h, --help", "display this help message"), (" -I, --exclude-installed", "exclude installed packages from search path"), (" -o, --overlay-tree", "include overlays in search path"), (" -p, --portage-tree", "include entire portage tree in search path"), (" -F, --format=TMPL", "specify a custom output format"), (" TMPL", "a format template using (see man page):")))) print(" " * 24, ', '.join(pp.emph(x) for x in FORMAT_TMPL_VARS))
def checks_printer(cpv, data, verbose=True, only_failures=False): """Output formatted results of pkg file(s) checks""" seen = [] n_passed, n_checked, errs = data n_failed = n_checked - n_passed if only_failures and not n_failed: return else: if verbose: if not cpv in seen: pp.uprint("* Checking %s ..." % (pp.emph(str(cpv)))) seen.append(cpv) else: pp.uprint("%s:" % cpv, end=' ') if verbose: for err in errs: sys.stderr.write(pp.error(err)) if verbose: n_passed = pp.number(str(n_passed)) n_checked = pp.number(str(n_checked)) info = " %(n_passed)s out of %(n_checked)s files passed" print(info % locals()) print() else: print("failed(%s)" % n_failed)
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="changes")) print() print(pp.emph("examples")) print (" c portage # show latest visible " "version's entry") print(" c portage --full --limit=3 # show 3 latest entries") print(" c '=sys-apps/portage-2.1.6*' # use atom syntax") print(" c portage --from=2.2_rc60 --to=2.2_rc70 # use version ranges") print() print(pp.command("options")) print(format_options(( (" -h, --help", "display this help message"), (" -l, --latest", "display only the latest ChangeLog entry"), (" -f, --full", "display the full ChangeLog"), (" --limit=NUM", "limit the number of entries displayed (with --full)"), (" --from=VER", "set which version to display from"), (" --to=VER", "set which version to display to"), )))
def main(input_args): """Parse input and run the program""" short_opts = "hai" long_opts = ('help', 'all', 'ignore-l10n') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) # # Output # first_run = True legend_printed = False for query in (Query(x) for x in queries): if not first_run: print() if QUERY_OPTS["all_versions"]: matches = query.find(include_masked=True) else: matches = [query.find_best()] if not any(matches): raise errors.GentoolkitNoMatches(query) matches.sort() global_usedesc = get_global_useflags() for pkg in matches: output = get_output_descriptions(pkg, global_usedesc) if output: if CONFIG['verbose']: if not legend_printed: print_legend() legend_printed = True print((" * Found these USE flags for %s:" % pp.cpv(str(pkg.cpv)))) print(pp.emph(" U I")) display_useflags(output) else: if CONFIG['verbose']: sys.stderr.write( pp.warn("No USE flags found for %s" % pp.cpv(pkg.cpv)) ) first_run = False
def rebuild_use(self): if not self.options["quiet"]: print() print(" -- Scanning installed packages for USE flag settings that") print(" do not match the default settings") system_use = portage.settings["USE"].split() output = RebuildPrinter( "use", self.options["pretend"], self.options["exact"], self.options['slot']) pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use) pkg_count = len(pkgs) if self.options["verbose"]: print() print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) + pp.emph(" packages that need entries"))) #print pp.emph(" package.use to maintain their current setting") pkg_keys = [] if pkgs: pkg_keys = sorted(pkgs) #print len(pkgs) if self.options["pretend"] and not self.options["quiet"]: print() print(pp.globaloption( " -- These are the installed packages & use flags " + "that were detected")) print(pp.globaloption(" to need use flag settings other " + "than the defaults.")) print() elif not self.options["quiet"]: print(" -- preparing pkgs for file entries") for pkg in pkg_keys: output(pkg, pkgs[pkg], cp_counts[pkg]) if self.options['verbose']: message = (pp.emph(" ") + pp.number(str(pkg_count)) + pp.emph(" different packages")) print() print(pp.globaloption(" -- Totals")) print(message) #print #unique = list(unique_flags) #unique.sort() #print unique if not self.options["pretend"]: filepath = os.path.expanduser('~/package.use.test') self.save_file(filepath, output.lines)
def main_usage(module_info): """Return the main usage message for analyse""" return "%(usage)s %(product)s [%(g_opts)s] %(mod_name)s [%(mod_opts)s]" % { 'usage': pp.emph("Usage:"), 'product': pp.productname(module_info["__productname__"]), 'g_opts': pp.globaloption("global-options"), 'mod_name': pp.command("module-name"), 'mod_opts': pp.localoption("module-options") }
def main(input_args): """Parse input and run the program""" short_opts = "hiIpoF:" # -i was option for default action # --installed is no longer needed, kept for compatibility (djanderson '09) long_opts = ( "help", "installed", "exclude-installed", "portage-tree", "overlay-tree", "format=", ) try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) matches = Query("*").smart_find(**QUERY_OPTS) matches.sort() # # Output # first_run = True got_match = False for query in queries: if not first_run: print() if CONFIG["verbose"]: pp.uprint(" * Searching for USE flag %s ... " % pp.emph(query)) for pkg in matches: if display_useflags(query, pkg): got_match = True first_run = False if not got_match: sys.exit(1)
def main(input_args): """Parse input and run the program""" short_opts = "hadD" # -d, --direct was old option for default action long_opts = ('help', 'all-packages', 'direct', 'indirect', 'depth=') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) # # Output # dep_print = DependPrinter(verbose=CONFIG['verbose']) first_run = True got_match = False for query in queries: if not first_run: print() pkg = Dependencies(query) if QUERY_OPTS['include_masked']: pkggetter = get_cpvs else: pkggetter = get_installed_cpvs if CONFIG['verbose']: print(" * These packages depend on %s:" % pp.emph(pkg.cpv)) if pkg.graph_reverse_depends( pkgset=sorted(pkggetter(), key=CPV), max_depth=QUERY_OPTS["max_depth"], only_direct=QUERY_OPTS["only_direct"], printer_fn=dep_print ): got_match = True first_run = False if not got_match: sys.exit(1)
def main(input_args): """Parse input and run the program""" short_opts = "hiIpoF:" # -i was option for default action # --installed is no longer needed, kept for compatibility (djanderson '09) long_opts = ('help', 'installed', 'exclude-installed', 'portage-tree', 'overlay-tree', 'format=') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) matches = Query("*").smart_find(**QUERY_OPTS) matches.sort() # # Output # first_run = True got_match = False for query in queries: if not first_run: print() if CONFIG['verbose']: pp.uprint(" * Searching for USE flag %s ... " % pp.emph(query)) for pkg in matches: if display_useflags(query, pkg): got_match = True first_run = False if not got_match: sys.exit(1)
def format_options(options): """Format module options. @type options: list @param options: [('option 1', 'description 1'), ('option 2', 'des... )] @rtype: str @return: formatted options string """ result = [] twrap = TextWrapper(width=gentoolkit.CONFIG['termWidth']) opts = (x[0] for x in options) descs = (x[1] for x in options) for opt, desc in zip(opts, descs): twrap.initial_indent = pp.emph(opt.ljust(25)) twrap.subsequent_indent = " " * 25 result.append(twrap.fill(desc)) return '\n'.join(result)
def format_options(options): """Format module options. @type options: list @param options: [('option 1', 'description 1'), ('option 2', 'des... )] @rtype: str @return: formatted options string """ result = [] twrap = TextWrapper(width=gentoolkit.CONFIG["termWidth"]) opts = (x[0] for x in options) descs = (x[1] for x in options) for opt, desc in zip(opts, descs): twrap.initial_indent = pp.emph(opt.ljust(25)) twrap.subsequent_indent = " " * 25 result.append(twrap.fill(desc)) return "\n".join(result)
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() # Deprecation warning added by djanderson, 12/2008 depwarning = ( "Default action for this module has changed in Gentoolkit 0.3.", "Use globbing to simulate the old behavior (see man equery).", "Use '*' to check all installed packages.", "Use 'foo-bar/*' to filter by category.", ) for line in depwarning: sys.stderr.write(pp.warn(line)) print() print(mod_usage(mod_name="list")) print() print(pp.command("options")) print( format_options(( (" -h, --help", "display this help message"), (" -d, --duplicates", "list only installed duplicate packages"), ( " -b, --binpkgs-missing", "list only installed packages without a corresponding binary package", ), (" -f, --full-regex", "query is a regular expression"), (" -m, --mask-reason", "include reason for package mask"), (" -I, --exclude-installed", "exclude installed packages from output"), (" -o, --overlay-tree", "list packages in overlays"), (" -p, --portage-tree", "list packages in the main portage tree"), (" -F, --format=TMPL", "specify a custom output format"), (" TMPL", "a format template using (see man page):"), ))) print(" " * 24, ", ".join(pp.emph(x) for x in FORMAT_TMPL_VARS))
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() # Deprecation warning added by djanderson, 12/2008 depwarning = ( "Default action for this module has changed in Gentoolkit 0.3.", "Use globbing to simulate the old behavior (see man equery).", "Use '*' to check all installed packages.", "Use 'foo-bar/*' to filter by category." ) for line in depwarning: sys.stderr.write(pp.warn(line)) print() print(mod_usage(mod_name="list")) print() print(pp.command("options")) print(format_options(( (" -h, --help", "display this help message"), (" -d, --duplicates", "list only installed duplicate packages"), (" -b, --binpkgs-missing", "list only installed packages without a corresponding binary package"), (" -f, --full-regex", "query is a regular expression"), (" -m, --mask-reason", "include reason for package mask"), (" -I, --exclude-installed", "exclude installed packages from output"), (" -o, --overlay-tree", "list packages in overlays"), (" -p, --portage-tree", "list packages in the main portage tree"), (" -F, --format=TMPL", "specify a custom output format"), (" TMPL", "a format template using (see man page):") ))) print(" " * 24, ', '.join(pp.emph(x) for x in FORMAT_TMPL_VARS))
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="files")) print() print(pp.command("options")) print(format_options(( (" -h, --help", "display this help message"), (" -m, --md5sum", "include MD5 sum in output"), (" -s, --timestamp", "include timestamp in output"), (" -t, --type", "include file type in output"), (" --tree", "display results in a tree (turns off other options)"), (" -f, --filter=RULES", "filter output by file type"), (" RULES", "a comma-separated list (no spaces); choose from:") ))) print(" " * 24, ', '.join(pp.emph(x) for x in FILTER_RULES))
def print_help(with_description=True): """Print description, usage and a detailed help message. @type with_description: bool @param with_description: if true, print module's __doc__ string """ if with_description: print(__doc__.strip()) print() print(mod_usage(mod_name="hasuse", arg="USE-flag")) print() print(pp.command("options")) print(format_options(( (" -h, --help", "display this help message"), (" -I, --exclude-installed", "exclude installed packages from search path"), (" -o, --overlay-tree", "include overlays in search path"), (" -p, --portage-tree", "include entire portage tree in search path"), (" -F, --format=TMPL", "specify a custom output format"), (" TMPL", "a format template using (see man page):") ))) print(" " * 24, ', '.join(pp.emph(x) for x in FORMAT_TMPL_VARS))
def main(input_args): """Parse input and run the program""" short_opts = "hiIpoF:" # -i was option for default action # --installed is no longer needed, kept for compatibility (djanderson '09) long_opts = ('help', 'installed', 'exclude-installed', 'portage-tree', 'overlay-tree', 'format=', 'package=') try: module_opts, queries = gnu_getopt(input_args, short_opts, long_opts) except GetoptError as err: sys.stderr.write(pp.error("Module %s" % err)) print() print_help(with_description=False) sys.exit(2) parse_module_options(module_opts) if not queries: print_help() sys.exit(2) query_scope = QUERY_OPTS['package_filter'] or '*' matches = Query(query_scope).smart_find(**QUERY_OPTS) matches.sort() # split out the first query since it is suppose to be the env_var QUERY_OPTS['env_var'] = queries.pop(0) env_var = QUERY_OPTS['env_var'] # # Output # if not queries: if not QUERY_OPTS['package_filter']: err = "Used ENV_VAR without match_expression or --package" raise errors.GentoolkitFatalError(err, is_serious=False) else: if len(matches) > 1: raise errors.AmbiguousPackageName(matches) for match in matches: env = QUERY_OPTS['env_var'] print(match.environment(env)) first_run = True got_match = False for query in queries: if not first_run: print() if CONFIG['verbose']: status = " * Searching for {0} {1} ... " pp.uprint(status.format(env_var, pp.emph(query))) for pkg in matches: if query_in_env(query, env_var, pkg): display_pkg(query, env_var, pkg) got_match = True first_run = False if not got_match: sys.exit(1)
def doAction(action,options,exclude={}, output=None): """doAction: execute one action, ie display a few message, call the right find* function, and then call doCleanup with its result.""" # define vocabulary for the output if action == 'packages': files_type = "binary packages" else: files_type = "distfiles" saved = {} deprecated = {} # find files to delete, depending on the action if not options['quiet']: output.einfo("Building file list for "+action+" cleaning...") if action == 'packages': clean_me = findPackages( options, exclude=exclude, destructive=options['destructive'], package_names=options['package-names'], time_limit=options['time-limit'], pkgdir=pkgdir, #port_dbapi=Dbapi(portage.db[portage.root]["porttree"].dbapi), #var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi), ) else: # accept defaults engine = DistfilesSearch(output=options['verbose-output'], #portdb=Dbapi(portage.db[portage.root]["porttree"].dbapi), #var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi), ) clean_me, saved, deprecated = engine.findDistfiles( exclude=exclude, destructive=options['destructive'], fetch_restricted=options['fetch-restricted'], package_names=options['package-names'], time_limit=options['time-limit'], size_limit=options['size-limit'], deprecate = options['deprecated'] ) # initialize our cleaner cleaner = CleanUp(output.progress_controller) # actually clean files if something was found if clean_me: # verbose pretend message if options['pretend'] and not options['quiet']: output.einfo("Here are the "+files_type+" that would be deleted:") # verbose non-pretend message elif not options['quiet']: output.einfo("Cleaning " + files_type +"...") # do the cleanup, and get size of deleted files if options['pretend']: clean_size = cleaner.pretend_clean(clean_me) elif action in ['distfiles']: clean_size = cleaner.clean_dist(clean_me) elif action in ['packages']: clean_size = cleaner.clean_pkgs(clean_me, pkgdir) # vocabulary for final message if options['pretend']: verb = "would be" else: verb = "were" # display freed space if not options['quiet']: output.total('normal', clean_size, len(clean_me), verb, action) # nothing was found elif not options['quiet']: output.einfo("Your "+action+" directory was already clean.") if saved and not options['quiet']: print() print( (pp.emph(" The following ") + yellow("unavailable") + pp.emph(" files were saved from cleaning due to exclusion file entries"))) output.set_colors('deprecated') clean_size = cleaner.pretend_clean(saved) output.total('deprecated', clean_size, len(saved), verb, action) if deprecated and not options['quiet']: print() print( (pp.emph(" The following ") + yellow("unavailable") + pp.emph(" installed packages were found"))) output.set_colors('deprecated') output.list_pkgs(deprecated)
def doAction(action,options,exclude={}, output=None): """doAction: execute one action, ie display a few message, call the right find* function, and then call doCleanup with its result.""" # define vocabulary for the output if action == 'packages': files_type = "binary packages" else: files_type = "distfiles" saved = {} deprecated = {} # find files to delete, depending on the action if not options['quiet']: output.einfo("Building file list for "+action+" cleaning...") if action == 'packages': clean_me = findPackages( options, exclude=exclude, destructive=options['destructive'], package_names=options['package-names'], time_limit=options['time-limit'], pkgdir=pkgdir, #port_dbapi=Dbapi(portage.db[portage.root]["porttree"].dbapi), #var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi), ) else: # accept defaults engine = DistfilesSearch(output=options['verbose-output'], #portdb=Dbapi(portage.db[portage.root]["porttree"].dbapi), #var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi), ) clean_me, saved, deprecated = engine.findDistfiles( exclude=exclude, destructive=options['destructive'], fetch_restricted=options['fetch-restricted'], package_names=options['package-names'], time_limit=options['time-limit'], size_limit=options['size-limit'], deprecate = options['deprecated'] ) # initialize our cleaner cleaner = CleanUp( output.progress_controller) # actually clean files if something was found if clean_me: # verbose pretend message if options['pretend'] and not options['quiet']: output.einfo("Here are the "+files_type+" that would be deleted:") # verbose non-pretend message elif not options['quiet']: output.einfo("Cleaning " + files_type +"...") # do the cleanup, and get size of deleted files if options['pretend']: clean_size = cleaner.pretend_clean(clean_me) elif action in ['distfiles']: clean_size = cleaner.clean_dist(clean_me) elif action in ['packages']: clean_size = cleaner.clean_pkgs(clean_me, pkgdir) # vocabulary for final message if options['pretend']: verb = "would be" else: verb = "were" # display freed space if not options['quiet']: output.total('normal', clean_size, len(clean_me), verb, action) # nothing was found elif not options['quiet']: output.einfo("Your "+action+" directory was already clean.") if saved and not options['quiet']: print() print( (pp.emph(" The following ") + yellow("unavailable") + pp.emph(" files were saved from cleaning due to exclusion file entries"))) output.set_colors('deprecated') clean_size = cleaner.pretend_clean(saved) output.total('deprecated', clean_size, len(saved), verb, action) if deprecated and not options['quiet']: print() print( (pp.emph(" The following ") + yellow("unavailable") + pp.emph(" installed packages were found"))) output.set_colors('deprecated') output.list_pkgs(deprecated)
def display_useflags(output): """Print USE flag descriptions and statuses. @type output: list @param output: [(inuse, inused, flag, desc, restrict), ...] inuse (int) = 0 or 1; if 1, flag is set in make.conf inused (int) = 0 or 1; if 1, package is installed with flag enabled flag (str) = the name of the USE flag desc (str) = the flag's description restrict (str) = corresponds to the text of restrict in metadata """ maxflag_len = len(max([t[2] for t in output], key=len)) twrap = TextWrapper() twrap.width = CONFIG['termWidth'] twrap.subsequent_indent = " " * (maxflag_len + 8) markers = ("-", "+") color = ( partial(pp.useflag, enabled=False), partial(pp.useflag, enabled=True) ) for in_makeconf, in_installed, flag, desc, restrict in output: if CONFIG['verbose']: flag_name = "" if in_makeconf != in_installed: flag_name += pp.emph(" %s %s" % (markers[in_makeconf], markers[in_installed])) else: flag_name += (" %s %s" % (markers[in_makeconf], markers[in_installed])) flag_name += " " + color[in_makeconf](flag.ljust(maxflag_len)) flag_name += " : " # Strip initial whitespace at the start of the description # Bug 432530 if desc: desc = desc.lstrip() # print description if restrict: restrict = "(%s %s)" % (pp.emph("Restricted to"), pp.cpv(restrict)) twrap.initial_indent = flag_name pp.uprint(twrap.fill(restrict)) if desc: twrap.initial_indent = twrap.subsequent_indent pp.uprint(twrap.fill(desc)) else: print(" : <unknown>") else: if desc: twrap.initial_indent = flag_name desc = twrap.fill(desc) pp.uprint(desc) else: twrap.initial_indent = flag_name print(twrap.fill("<unknown>")) else: pp.uprint(markers[in_makeconf] + flag)