diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/runtimedeps.py | 130 | ||||
-rwxr-xr-x | src/vdb_to_fake_binrepo.py | 60 |
3 files changed, 65 insertions, 131 deletions
@@ -1,7 +1,11 @@ # ChangeLog for Gentoo Linux Installer -# Copyright 2005-2007 Gentoo Foundation; Distributed under the GPL v2 +# Copyright 2005-2008 Gentoo Foundation; Distributed under the GPL v2 # $Id: $ + 28 Feb 2008; Andrew Gaffney <agaffney@gentoo.org> -src/runtimedeps.py, + +src/vdb_to_fake_binrepo.py: + Add vdb_to_fake_binrepo.py script from the always awesome zmedico + 03 Dec 2007; Andrew Gaffney <agaffney@gentoo.org> src/GLIPortage.py: force livecd and bindist USE diff --git a/src/runtimedeps.py b/src/runtimedeps.py deleted file mode 100644 index 837146f..0000000 --- a/src/runtimedeps.py +++ /dev/null @@ -1,130 +0,0 @@ -""" -# Copyright 1999-2005 Gentoo Foundation -# This source code is distributed under the terms of version 2 of the GNU -# General Public License as published by the Free Software Foundation, a copy -# of which can be found in the main directory of this project. -Gentoo Linux Installer - -$Id: runtimedeps.py,v 1.3 2005/12/26 19:26:26 agaffney Exp $ -""" - -import os, sys - -class MissingPackagesError(Exception): - pass - -class depgraph: - - def __init__(self): - self.graph = {} - - def add(self, node, parent=None): - if node not in self.graph: - self.graph[node] = [[], []] - if parent and parent not in self.graph[node][0]: - if parent not in self.graph: - self.graph[parent] = [[], []] - self.graph[node][0].append(parent) - self.graph[parent][1].append(node) - - def remove(self, node): - for parent in self.graph[node][0]: - self.graph[parent][1].remove(node) - for child in self.graph[node][1]: - self.graph[child][0].remove(node) - return self.graph.pop(node) - - def has_node(self, node): - return node in self.graph - - def leaf_nodes(self): - return [node for node in self.graph if not self.graph[node][1]] - - def node_count(self): - return len(self.graph) - - def important_node(self): - important_node = None - importance = 0 - for node in self.graph: - if len(self.graph[node][0]) > importance: - importance = len(self.graph[node][0]) - important_node = node - return important_node - -def resolve_deps(dep_list): - if dep_list and dep_list[0] == "||": - for dep in dep_list[1:]: - if isinstance(dep, list): - try: - atoms = resolve_deps(dep) - except MissingPackagesError: - continue - else: - atoms = [dep] - all_found = True - for atom in atoms: - if not atom.startswith("!") and not vdb.match(atom): - all_found = False - break - if all_found: - return atoms - raise MissingPackagesError(dep_list) - atoms = [] - for dep in dep_list: - if isinstance(dep, list): - atoms.extend(resolve_deps(dep)) - elif not dep.startswith("!"): - if not vdb.match(dep): - raise MissingPackagesError([dep]) - atoms.append(dep) - return atoms - -def calc_required_pkgs(atom, graph, parent=None): - pkg = portage.best(vdb.match(atom)) - if not pkg: - raise MissingPackagesError([atom]) - if pkg == parent: - return - already_processed = graph.has_node(pkg) - graph.add(pkg, parent) - if already_processed: - return - useflags = vdb.aux_get(pkg, ["USE"])[0].split() - rdep_raw = " ".join(vdb.aux_get(pkg, ["RDEPEND", "PDEPEND"])) - rdep_struct = portage_dep.use_reduce(portage_dep.paren_reduce(rdep_raw), uselist=useflags) - rdep_struct = portage.dep_virtual(portage_dep.dep_opconvert(rdep_struct), portage.settings) - rdep_atoms = portage.unique_array(resolve_deps(rdep_struct)) - for atom in rdep_atoms: - calc_required_pkgs(atom, graph, pkg) - -def prune_existing(graph): - db = portage.db[portage.root]["vartree"].dbapi - for atom in db.cp_all(): - for pkg in db.match(atom): - if graph.has_node(pkg): - graph.remove(pkg) - -def get_deps(pkgs): - pkglist = [] - graph = depgraph() - for pkg in pkgs.split(): - if not vdb.match(pkg): - continue - calc_required_pkgs(pkg, graph) - while graph.node_count(): - leaf_nodes = graph.leaf_nodes() - if not leaf_nodes: - node = graph.important_node() - pkglist.append(node) - graph.remove(node) - continue - pkglist.extend(leaf_nodes) - for node in leaf_nodes: - graph.remove(node) - return pkglist - -os.environ['ROOT'] = sys.argv[1] -import portage, portage_dep -vdb = portage.db["/"]["vartree"].dbapi -print "\n".join(get_deps(" ".join(sys.argv[2:]))) diff --git a/src/vdb_to_fake_binrepo.py b/src/vdb_to_fake_binrepo.py new file mode 100755 index 0000000..9dced08 --- /dev/null +++ b/src/vdb_to_fake_binrepo.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# Copyright 1999-2008 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ +# +# Zac Medico <zmedico@gentoo.org> +# + +import os +import sys +from itertools import izip + +def vdb_to_fake_binrepo(): + + metadata_keys = ["CATEGORY", "CHOST", "DEPEND", + "EAPI", "IUSE", "KEYWORDS", "LICENSE", "PF", + "PROVIDE", "RDEPEND", "PDEPEND", "SLOT", "USE"] + + import portage + try: + from portage import xpak + from portage.util import ensure_dirs + except ImportError: + import xpak + from portage_util import ensure_dirs + + root = portage.settings["ROOT"] + vartree = portage.db[root]["vartree"] + bintree = portage.db[root]["bintree"] + + for cpv in vartree.dbapi.cpv_all(): + bintree.prevent_collision(cpv) + metadata = dict(izip(metadata_keys, + vartree.dbapi.aux_get(cpv, metadata_keys))) + xpdata = xpak.xpak_mem(metadata) + binpkg_tmpfile = os.path.join(bintree.pkgdir, + cpv + ".tbz2." + str(os.getpid())) + ensure_dirs(os.path.dirname(binpkg_tmpfile)) + xpak.tbz2(binpkg_tmpfile).recompose_mem(xpdata) + binpkg_path = bintree.getname(cpv) + ensure_dirs(os.path.dirname(binpkg_path)) + os.rename(binpkg_tmpfile, binpkg_path) + bintree.inject(cpv) + +def main(): + description = "This program uses the currently installed packages to" + \ + " populate $PKGDIR with a fake binary package repository that is " + \ + "suitable for dependency calculations." + usage = "usage: %s" % os.path.basename(sys.argv[0]) + from optparse import OptionParser + parser = OptionParser(description=description, usage=usage) + options, args = parser.parse_args(args=sys.argv[1:]) + vdb_to_fake_binrepo() + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print "Interrupted." + sys.exit(1) |