| … | |
… | |
| 3 | # This source code is distributed under the terms of version 2 of the GNU |
3 | # This source code is distributed under the terms of version 2 of the GNU |
| 4 | # General Public License as published by the Free Software Foundation, a copy |
4 | # General Public License as published by the Free Software Foundation, a copy |
| 5 | # of which can be found in the main directory of this project. |
5 | # of which can be found in the main directory of this project. |
| 6 | Gentoo Linux Installer |
6 | Gentoo Linux Installer |
| 7 | |
7 | |
| 8 | $Id: GLIPortage.py,v 1.4 2005/12/24 17:29:33 agaffney Exp $ |
8 | $Id: GLIPortage.py,v 1.5 2005/12/25 05:06:35 agaffney Exp $ |
| 9 | """ |
9 | """ |
| 10 | |
10 | |
| 11 | import os |
11 | import os |
| 12 | import re |
12 | import re |
| 13 | import GLIUtility |
13 | import GLIUtility |
| … | |
… | |
| 55 | return important_node |
55 | return important_node |
| 56 | |
56 | |
| 57 | class GLIPortage(object): |
57 | class GLIPortage(object): |
| 58 | |
58 | |
| 59 | def __init__(self, chroot_dir, grp_install, logger, debug): |
59 | def __init__(self, chroot_dir, grp_install, logger, debug): |
| 60 | os.environ['ROOT'] = chroot_dir |
|
|
| 61 | import portage, portage_dep |
|
|
| 62 | self.vdb = portage.db["/"]["vartree"].dbapi |
|
|
| 63 | self.tree = portage.db[chroot_dir]["porttree"].dbapi |
|
|
| 64 | self._chroot_dir = chroot_dir |
60 | self._chroot_dir = chroot_dir |
| 65 | self._logger = logger |
61 | self._logger = logger |
| 66 | self._debug = debug |
62 | self._debug = debug |
| 67 | self._grp_install = grp_install |
63 | self._grp_install = grp_install |
| 68 | |
64 | |
| … | |
… | |
| 91 | elif not dep.startswith("!"): |
87 | elif not dep.startswith("!"): |
| 92 | if not self.vdb.match(dep): |
88 | if not self.vdb.match(dep): |
| 93 | raise MissingPackagesError([dep]) |
89 | raise MissingPackagesError([dep]) |
| 94 | atoms.append(dep) |
90 | atoms.append(dep) |
| 95 | return atoms |
91 | return atoms |
| 96 | |
|
|
| 97 | def calc_required_pkgs(self, atom, graph, parent=None): |
|
|
| 98 | pkg = portage.best(self.vdb.match(atom)) |
|
|
| 99 | if not pkg: |
|
|
| 100 | raise MissingPackagesError([atom]) |
|
|
| 101 | if pkg == parent: |
|
|
| 102 | return |
|
|
| 103 | already_processed = graph.has_node(pkg) |
|
|
| 104 | graph.add(pkg, parent) |
|
|
| 105 | if already_processed: |
|
|
| 106 | return |
|
|
| 107 | useflags = self.vdb.aux_get(pkg, ["USE"])[0].split() |
|
|
| 108 | rdep_raw = " ".join(self.vdb.aux_get(pkg, ["RDEPEND", "PDEPEND"])) |
|
|
| 109 | rdep_struct = portage_dep.use_reduce(portage_dep.paren_reduce(rdep_raw), uselist=useflags) |
|
|
| 110 | rdep_struct = portage.dep_virtual(portage_dep.dep_opconvert(rdep_struct), portage.settings) |
|
|
| 111 | rdep_atoms = portage.unique_array(resolve_deps(rdep_struct)) |
|
|
| 112 | for atom in rdep_atoms: |
|
|
| 113 | calc_required_pkgs(atom, graph, pkg) |
|
|
| 114 | |
|
|
| 115 | def prune_existing(self, graph): |
|
|
| 116 | db = portage.db[portage.root]["vartree"].dbapi |
|
|
| 117 | for atom in db.cp_all(): |
|
|
| 118 | for pkg in db.match(atom): |
|
|
| 119 | if graph.has_node(pkg): |
|
|
| 120 | graph.remove(pkg) |
|
|
| 121 | |
92 | |
| 122 | def get_deps(self, pkgs): |
93 | def get_deps(self, pkgs): |
| 123 | if not self._grp_install: |
94 | if not self._grp_install: |
| 124 | del(os.environ['ROOT']) |
95 | del(os.environ['ROOT']) |
| 125 | return GLIUtility.spawn("emerge -p " + pkgs + r" | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].split("\n") |
96 | return GLIUtility.spawn("emerge -p " + pkgs + r" | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].split("\n") |
| … | |
… | |
| 205 | expr = re.compile('^(.+?)(-\d.+)?$') |
176 | expr = re.compile('^(.+?)(-\d.+)?$') |
| 206 | res = expr.match(package) |
177 | res = expr.match(package) |
| 207 | if res: |
178 | if res: |
| 208 | GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world") |
179 | GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world") |
| 209 | |
180 | |
| 210 | # def get_best_version_vdb(self, package): |
181 | def get_best_version_vdb(self, package): |
| 211 | # return portage.best(vdb.match(package)) |
182 | return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip() |
| 212 | # |
183 | # |
| 213 | # def get_best_version_tree(self, package): |
184 | # def get_best_version_tree(self, package): |
| 214 | # return portage.best(tree.match(package)) |
185 | # return portage.best(tree.match(package)) |