def generate_attr_dict(pkg, portage_compatible=True): d = {} for k in pkg.tracked_attributes: if k == "contents": continue v = getattr(pkg, k) if k == 'environment': d['environment.bz2'] = compress_data('bzip2', v.bytes_fileobj().read()) continue if k == 'provides': versionless_provides = lambda b: b.key s = stringify_boolean(v, func=versionless_provides) elif k == 'eapi_obj': s = v.magic elif not isinstance(v, basestring): try: s = ' '.join(v) except TypeError: s = str(v) else: s = v d[_metadata_rewrites.get(k, k.upper())] = s d["%s-%s.ebuild" % (pkg.package, pkg.fullver)] = \ pkg.ebuild.text_fileobj().read() # this shouldn't be necessary post portage 2.2. # till then, their code requires redundant data, # so we've got this. if portage_compatible: d["CATEGORY"] = pkg.category d["PF"] = pkg.PF return d
def stringify_attr(config, pkg, attr): """Grab a package attr and convert it to a string.""" # config is currently unused but may affect display in the future. if attr in ('files', 'uris'): data = get_pkg_attr(pkg, 'fetchables') if data is None: return 'MISSING' if attr == 'files': def _format(node): return node.filename else: def _format(node): return ' '.join(node.uri) return conditionals.stringify_boolean(data, _format) if attr == 'use': # Combine a list of all enabled (including irrelevant) and all # available flags into a "enabled -disabled" style string. use = set(get_pkg_attr(pkg, 'use', ())) iuse = get_pkg_attr(pkg, 'iuse_stripped', ()) result = sorted(iuse & use) + sorted('-' + val for val in (iuse - use)) return ' '.join(result) value = get_pkg_attr(pkg, attr) if value is None: # missing revision is assumed to be -r0 if attr == 'revision': return '0' return 'MISSING' if attr in ('iuse', 'properties', 'defined_phases', 'inherited'): return ' '.join(sorted(str(v) for v in value)) if attr == 'maintainers': return ' '.join(str(v) for v in value) if attr == 'longdescription': return str(value) if attr == 'keywords': return ' '.join(sorted(value, key=lambda x: x.lstrip("~"))) if attr == 'distfiles': # collapse depsets for raw repo pkgs -- no USE flags are enabled if isinstance(value, conditionals.DepSet): value = value.evaluate_depset([]) return ' '.join(value) if attr == 'environment': return value.text_fileobj().read() if attr == 'repo': return str(get_pkg_attr(value, 'repo_id', 'no repo id')) # hackish. return str(value)
def stringify_attr(config, pkg, attr): """Grab a package attr and convert it to a string.""" # config is currently unused but may affect display in the future. if attr in ("files", "uris"): data = get_pkg_attr(pkg, "fetchables") if data is None: return "MISSING" if attr == "files": def _format(node): return node.filename else: def _format(node): return " ".join(node.uri or ()) return conditionals.stringify_boolean(data, _format) if attr == "use": # Combine a list of all enabled (including irrelevant) and all # available flags into a "enabled -disabled" style string. use = set(get_pkg_attr(pkg, "use", ())) iuse = get_pkg_attr(pkg, "iuse_stripped", ()) result = sorted(iuse & use) + sorted("-" + val for val in (iuse - use)) return " ".join(result) value = get_pkg_attr(pkg, attr) if value is None: return "MISSING" if attr in ("iuse", "properties", "defined_phases", "inherited"): return " ".join(sorted(unicode(v) for v in value)) if attr == "maintainers": return " ".join(unicode(v) for v in value) if attr == "longdescription": return unicode(value) if attr == "keywords": return " ".join(sorted(value, key=lambda x: x.lstrip("~"))) if attr == "environment": return value.text_fileobj().read() if attr == "repo": return str(get_pkg_attr(value, "repo_id", "no repo id")) # hackish. return str(value)
def stringify_attr(config, pkg, attr): """Grab a package attr and convert it to a string.""" # config is currently unused but may affect display in the future. if attr in ('files', 'uris'): data = get_pkg_attr(pkg, 'fetchables') if data is None: return 'MISSING' if attr == 'files': def _format(node): return node.filename else: def _format(node): return ' '.join(node.uri or ()) return conditionals.stringify_boolean(data, _format) if attr == 'use': # Combine a list of all enabled (including irrelevant) and all # available flags into a "enabled -disabled" style string. use = set(get_pkg_attr(pkg, 'use', ())) iuse = set(x.lstrip("-+") for x in get_pkg_attr(pkg, 'iuse', ())) result = sorted(iuse & use) + sorted('-' + val for val in (iuse - use)) return ' '.join(result) value = get_pkg_attr(pkg, attr) if value is None: return 'MISSING' if attr in ('herds', 'iuse', 'maintainers', 'properties', 'defined_phases', 'inherited'): return ' '.join(sorted(unicode(v) for v in value)) if attr == 'longdescription': return unicode(value) if attr == 'keywords': return ' '.join(sorted(value, key=lambda x: x.lstrip("~"))) if attr == 'environment': return value.text_fileobj().read() if attr == 'repo': return str(get_pkg_attr(value, 'repo_id', 'no repo id')) # hackish. return str(value)
def stringify_attr(config, pkg, attr): """Grab a package attr and convert it to a string.""" # config is currently unused but may affect display in the future. if attr in ('files', 'uris'): data = get_pkg_attr(pkg, 'fetchables') if data is None: return 'MISSING' if attr == 'files': def _format(node): return node.filename else: def _format(node): return ' '.join(node.uri or ()) return conditionals.stringify_boolean(data, _format) if attr == 'use': # Combine a list of all enabled (including irrelevant) and all # available flags into a "enabled -disabled" style string. use = set(get_pkg_attr(pkg, 'use', ())) iuse = set(x.lstrip("-+") for x in get_pkg_attr(pkg, 'iuse', ())) result = sorted(iuse & use) + sorted('-' + val for val in (iuse - use)) return ' '.join(result) value = get_pkg_attr(pkg, attr) if value is None: return 'MISSING' if attr in ('herds', 'iuse', 'maintainers', 'properties', 'defined_phases', 'inherited'): return ' '.join(sorted(unicode(v) for v in value)) if attr == 'longdescription': return unicode(value) if attr == 'keywords': return ' '.join(sorted(value, key=lambda x:x.lstrip("~"))) if attr == 'environment': return value.text_fileobj().read() if attr == 'repo': return str(get_pkg_attr(value, 'repo_id', 'no repo id')) # hackish. return str(value)