def display_size(match_set): """Display the total size of all accessible files owned by packages. @type match_set: list @param match_set: package cat/pkg-ver strings """ for pkg in match_set: size, files, uncounted = pkg.size() if CONFIG['verbose']: pp.uprint(" * %s" % pp.cpv(str(pkg.cpv))) print("Total files : %s".rjust(25) % pp.number(str(files))) if uncounted: print(("Inaccessible files : %s".rjust(25) % pp.number(str(uncounted)))) if QUERY_OPTS["size_in_bytes"]: size_str = pp.number(str(size)) else: size_str = "%s %s" % format_bytes(size) print("Total size : %s".rjust(25) % size_str) else: info = "%s: total(%d), inaccessible(%d), size(%s)" pp.uprint(info % (str(pkg.cpv), files, uncounted, size))
def format_bytes(bytes_, precision=2): """Format bytes into human-readable format (IEC naming standard). @see: http://mail.python.org/pipermail/python-list/2008-August/503423.html @rtype: tuple @return: (str(num), str(label)) """ labels = ( (1<<40, 'TiB'), (1<<30, 'GiB'), (1<<20, 'MiB'), (1<<10, 'KiB'), (1, 'bytes') ) if bytes_ == 0: return (pp.number('0'), 'bytes') elif bytes_ == 1: return (pp.number('1'), 'byte') for factor, label in labels: if not bytes_ >= factor: continue float_split = str(bytes_/float(factor)).split('.') integer = float_split[0] decimal = float_split[1] if int(decimal[0:precision]): float_string = '.'.join([integer, decimal[0:precision]]) else: float_string = integer return (pp.number(float_string), label)
def make_depgraph(pkg, printer_fn): """Create and display depgraph for each package.""" print() if CONFIG['verbose']: pp.uprint(" * " + pp.subsection("dependency graph for ") + pp.cpv(str(pkg.cpv))) else: pp.uprint("%s:" % pkg.cpv) # Print out the first package printer_fn(0, pkg, None, initial_pkg=True) deps = pkg.deps.graph_depends( max_depth=QUERY_OPTS['depth'], printer_fn=printer_fn, # Use this to set this pkg as the graph's root; better way? result=[(0, pkg)]) if CONFIG['verbose']: pkgname = pp.cpv(str(pkg.cpv)) n_packages = pp.number(str(len(deps))) max_seen = pp.number(str(max(x[0] for x in deps))) info = "[ %s stats: packages (%s), max depth (%s) ]" pp.uprint(info % (pkgname, n_packages, max_seen))
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 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 make_depgraph(pkg, printer_fn): """Create and display depgraph for each package.""" print() if CONFIG["verbose"]: pp.uprint(" * " + pp.subsection("dependency graph for ") + pp.cpv(str(pkg.cpv))) else: pp.uprint("%s:" % pkg.cpv) # Print out the first package printer_fn(0, pkg, None, initial_pkg=True) deps = pkg.deps.graph_depends( max_depth=QUERY_OPTS["depth"], printer_fn=printer_fn, # Use this to set this pkg as the graph's root; better way? result=[(0, pkg)], ) if CONFIG["verbose"]: pkgname = pp.cpv(str(pkg.cpv)) n_packages = pp.number(str(len(deps))) max_seen = pp.number(str(max(x[0] for x in deps))) info = "[ %s stats: packages (%s), max depth (%s) ]" pp.uprint(info % (pkgname, n_packages, max_seen))
def format_bytes(bytes_, precision=2): """Format bytes into human-readable format (IEC naming standard). @see: http://mail.python.org/pipermail/python-list/2008-August/503423.html @rtype: tuple @return: (str(num), str(label)) """ labels = ((1 << 40, 'TiB'), (1 << 30, 'GiB'), (1 << 20, 'MiB'), (1 << 10, 'KiB'), (1, 'bytes')) if bytes_ == 0: return (pp.number('0'), 'bytes') elif bytes_ == 1: return (pp.number('1'), 'byte') for factor, label in labels: if not bytes_ >= factor: continue float_split = str(bytes_ / float(factor)).split('.') integer = float_split[0] decimal = float_split[1] if int(decimal[0:precision]): float_string = '.'.join([integer, decimal[0:precision]]) else: float_string = integer return (pp.number(float_string), label)
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 result(self, cp, version, urls, handler, confidence): from euscan.version import get_version_type cpv = '%s-%s' % (cp, version) urls = ' '.join( transform_url(self.config, cpv, url) for url in urls.split() ) if self.config['format'] in ['json', 'dict']: _curr = self.queries[self.current_query] _curr["result"].append( { "version": version, "urls": urls.split(), "handler": handler, "confidence": confidence, "type": get_version_type(version) } ) else: if not self.config['quiet']: print "Upstream Version:", pp.number("%s" % version), print pp.path(" %s" % urls) else: print pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(urls)
def result(self, cp, version, urls, handler, confidence): from euscan.version import get_version_type cpv = '%s-%s' % (cp, version) urls = ' '.join( transform_url(self.config, cpv, url) for url in urls.split() ) if self.config['format'] in ['json', 'dict']: _curr = self.queries[self.current_query] _curr["result"].append( { "version": version, "urls": urls.split(), "handler": handler, "confidence": confidence, "type": get_version_type(version) } ) else: if not self.config['quiet']: print("Upstream Version:", pp.number("%s" % version), end=' ') print(pp.path(" %s" % urls)) else: print(pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(urls))
def print_keyword_quiet(key, stability, default, count, pkgs): """Quietly prints a subset set of USE flag info.. """ _key = (pp.keyword((stability + key), stable=(stability == " "), hard_masked=stability == "-")) print(_key, '.' * (20 - len(key)), default, pp.number(count))
def print_use_quiet(key, active, default, count, pkgs): """Quietly prints a subset set of USE flag info.. """ if active in ["+", "-"]: _key = pp.useflag((active + key), active == "+") else: _key = (" " + key) print(_key, '.' * (35 - len(key)), default, pp.number(count))
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 print_use_quiet(key, active, default, count, pkgs): """Quietly prints a subset set of USE flag info.. """ if active in ["+", "-"]: _key = pp.useflag((active + key), active == "+") else: _key = " " + key print(_key, "." * (35 - len(key)), default, pp.number(count))
def print_keyword_verbose(key, stability, default, count, pkgs): """Verbosely prints a set of keywords info. including the pkgs using them. """ _pkgs = pkgs[:] _key = pp.keyword((stability + key), stable=(stability == " "), hard_masked=stability == "-") cpv = _pkgs.pop(0) print(_key, "." * (20 - len(key)), default, pp.number(count), pp.cpv(cpv)) while _pkgs: cpv = _pkgs.pop(0) print(" " * 37 + pp.cpv(cpv))
def print_keyword_verbose(self, key, stability, default, count, pkgs): """Verbosely prints a set of keywords info. including the pkgs using them. """ _pkgs = pkgs[:] _key = (pp.keyword((stability+key),stable=(stability==" "), hard_masked=stability=="-")) cpv = _pkgs.pop(0) print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count), pp.cpv(cpv)) while _pkgs: cpv = _pkgs.pop(0) print(' '*37 + pp.cpv(cpv))
def print_use_verbose(key, active, default, count, pkgs): """Verbosely prints a set of use flag info. including the pkgs using them. """ _pkgs = pkgs[:] if active in ["+", "-"]: _key = pp.useflag((active + key), active == "+") else: _key = " " + key cpv = _pkgs.pop(0) print(_key, "." * (35 - len(key)), default, pp.number(count), pp.cpv(cpv)) while _pkgs: cpv = _pkgs.pop(0) print(" " * 52 + pp.cpv(cpv))
def print_use_verbose(key, active, default, count, pkgs): """Verbosely prints a set of use flag info. including the pkgs using them. """ _pkgs = pkgs[:] if active in ["+", "-"]: _key = pp.useflag((active + key), active == "+") else: _key = (" " + key) cpv = _pkgs.pop(0) print(_key, '.' * (35 - len(key)), default, pp.number(count), pp.cpv(cpv)) while _pkgs: cpv = _pkgs.pop(0) print(' ' * 52 + pp.cpv(cpv))
def result(self, cp, version, url, handler, confidence): from euscan.helpers import get_version_type if self.config['format']: _curr = self.queries[self.current_query] _curr["result"].append( {"version": version, "urls": [url], "handler": handler, "confidence": confidence, "type": get_version_type(version)} ) else: if not self.config['quiet']: print "Upstream Version:", pp.number("%s" % version), print pp.path(" %s" % url) else: print pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(url)
def print_keyword_quiet(key, stability, default, count, pkgs): """Quietly prints a subset set of USE flag info.. """ _key = pp.keyword((stability + key), stable=(stability == " "), hard_masked=stability == "-") print(_key, "." * (20 - len(key)), default, pp.number(count))