/[gli]/trunk/src/GLIPortage.py
Gentoo

Diff of /trunk/src/GLIPortage.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1185 Revision 1311
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.
6Gentoo Linux Installer 6Gentoo Linux Installer
7 7
8$Id: GLIPortage.py,v 1.5 2005/12/25 05:06:35 agaffney Exp $ 8$Id: GLIPortage.py,v 1.47 2006/02/20 18:15:17 agaffney Exp $
9""" 9"""
10 10
11import re
11import os 12import os
12import re 13import sys
13import GLIUtility 14import GLIUtility
14 15from GLIException import GLIException
15class MissingPackagesError(Exception):
16 pass
17
18class depgraph:
19
20 def __init__(self):
21 self.graph = {}
22
23 def add(self, node, parent=None):
24 if node not in self.graph:
25 self.graph[node] = [[], []]
26 if parent and parent not in self.graph[node][0]:
27 if parent not in self.graph:
28 self.graph[parent] = [[], []]
29 self.graph[node][0].append(parent)
30 self.graph[parent][1].append(node)
31
32 def remove(self, node):
33 for parent in self.graph[node][0]:
34 self.graph[parent][1].remove(node)
35 for child in self.graph[node][1]:
36 self.graph[child][0].remove(node)
37 return self.graph.pop(node)
38
39 def has_node(self, node):
40 return node in self.graph
41
42 def leaf_nodes(self):
43 return [node for node in self.graph if not self.graph[node][1]]
44
45 def node_count(self):
46 return len(self.graph)
47
48 def important_node(self):
49 important_node = None
50 importance = 0
51 for node in self.graph:
52 if len(self.graph[node][0]) > importance:
53 importance = len(self.graph[node][0])
54 important_node = node
55 return important_node
56 16
57class GLIPortage(object): 17class GLIPortage(object):
58 18
59 def __init__(self, chroot_dir, grp_install, logger, debug): 19 def __init__(self, chroot_dir, grp_install, logger, debug, cc, compile_logfile):
60 self._chroot_dir = chroot_dir 20 self._chroot_dir = chroot_dir
21 self._grp_install = grp_install
61 self._logger = logger 22 self._logger = logger
62 self._debug = debug 23 self._debug = debug
63 self._grp_install = grp_install 24 self._cc = cc
64 25 self._compile_logfile = compile_logfile
65 def resolve_deps(self, dep_list):
66 if dep_list and dep_list[0] == "||":
67 for dep in dep_list[1:]:
68 if isinstance(dep, list):
69 try:
70 atoms = resolve_deps(dep)
71 except MissingPackagesError:
72 continue
73 else:
74 atoms = [dep]
75 all_found = True
76 for atom in atoms:
77 if not atom.startswith("!") and not self.vdb.match(atom):
78 all_found = False
79 break
80 if all_found:
81 return atoms
82 raise MissingPackagesError(dep_list)
83 atoms = []
84 for dep in dep_list:
85 if isinstance(dep, list):
86 atoms.extend(resolve_deps(dep))
87 elif not dep.startswith("!"):
88 if not self.vdb.match(dep):
89 raise MissingPackagesError([dep])
90 atoms.append(dep)
91 return atoms
92 26
93 def get_deps(self, pkgs): 27 def get_deps(self, pkgs):
94 if not self._grp_install: 28 pkglist = []
95 del(os.environ['ROOT']) 29 if isinstance(pkgs, str):
30 pkgs = pkgs.split()
31 for pkg in pkgs:
32 if not pkg: continue
33 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
34 if not self._grp_install or not self.get_best_version_vdb(pkg):
35 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
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") 36 tmppkglist = GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n")
97 os.environ['ROOT'] = self._chroot_dir
98 else: 37 else:
99 return GLIUtility.spawn("../../runtimedeps.py " + pkgs, return_output=True)[1].split("\n")[:-1] 38 if self._debug: self._logger.log("get_deps(): grabbing binary deps")
39 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself
40# tmppkglist = GLIUtility.spawn("python ../../runtimedeps.py " + self._chroot_dir + " " + pkg, return_output=True)[1].strip().split("\n")
41 tmppkglist = []
42 for tmppkg in GLIUtility.spawn("emerge -p " + pkg + r" 2>/dev/null | grep -e '^\[[a-z]' | cut -d ']' -f2 | sed -e 's:^ ::' -e 's: .\+$::'", chroot=self._chroot_dir, return_output=True)[1].strip().split("\n"):
43 if self._debug: self._logger.log("get_deps(): looking at " + tmppkg)
44 if self.get_best_version_vdb("=" + tmppkg):
45 if self._debug: self._logger.log("get_deps(): package " + tmppkg + " in host vdb...adding to tmppkglist")
46 tmppkglist.append(tmppkg)
47 if self._debug: self._logger.log("get_deps(): deplist for " + pkg + ": " + str(tmppkglist))
48 for tmppkg in tmppkglist:
49 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist")
50 if not tmppkg in pkglist and not self.get_best_version_vdb_chroot("=" + tmppkg):
51 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
52 pkglist.append(tmppkg)
53 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
54 return pkglist
100 55
101 def copy_pkg_to_chroot(self, package): 56 def parse_vdb_contents(self, file):
57 entries = []
58 try:
59 vdbfile = open(file, "r")
60 except:
61 return entries
62 for line in vdbfile.readlines():
63 parts = line.strip().split(" ")
64 if parts[0] == "obj":
65 entries.append(parts[1])
66# elif parts[0] == "dir":
67# entries.append(parts[1] + "/")
68 elif parts[0] == "sym":
69 entries.append(" ".join(parts[1:4]))
70 entries.sort()
71 return entries
72
73 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
102 symlinks = { '/bin/': '/mnt/livecd/bin/', '/boot/': '/mnt/livecd/boot/', '/lib/': '/mnt/livecd/lib/', 74 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
103 '/opt/': '/mnt/livecd/opt/', '/sbin/': '/mnt/livecd/sbin/', '/usr/': '/mnt/livecd/usr/', 75 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
104 '/etc/gconf/': '/usr/livecd/gconf/' } 76 '/etc/gconf': '/usr/livecd/gconf/' }
77
78 tmpdir = "/var/tmp/portage"
79 image_dir = tmpdir + "/" + package.split("/")[1] + "/image"
80 root_cmd = ""
81 tmp_chroot_dir = self._chroot_dir
82 portage_tmpdir = "/var/tmp/portage"
83 vdb_dir = "/var/db/pkg/"
84 if use_root:
85 root_cmd = "ROOT=" + self._chroot_dir
86 tmp_chroot_dir = ""
87 portage_tmpdir = self._chroot_dir + "/var/tmp/portage"
88 vdb_dir = self._chroot_dir + "/var/db/pkg/"
89
90 # Check to see if package is actually in vdb
91 if not GLIUtility.is_file("/var/db/pkg/" + package):
92 if ignore_missing:
93 if self._debug:
94 self._logger.log("DEBUG: copy_pkg_to_chroot(): package " + package + " does not have a vdb entry but ignore_missing=True...ignoring error")
95 return
96 else:
97 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
105 98
106 # Copy the vdb entry for the package from the LiveCD to the chroot 99 # Copy the vdb entry for the package from the LiveCD to the chroot
107 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package) 100 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package)
108 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package)): 101 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + "/var/db/pkg/" + package + " && cp -a /var/db/pkg/" + package + "/* " + self._chroot_dir + "/var/db/pkg/" + package)):
109 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package) 102 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
110 103
104 # Create the image dir in the chroot
105 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
106 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir)):
107 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
108
111 # Create list of files for tar to work with from CONTENTS file in vdb entry 109 # Create list of files for tar to work with from CONTENTS file in vdb entry
112 entries = GLIUtility.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") 110 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
111 if not entries:
112 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
113 else:
113 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries)) 114 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
114 try: 115 try:
115 tarfiles = open("/tmp/tarfilelist", "w") 116 tarfiles = open("/tmp/tarfilelist", "w")
116 for entry in entries: 117 for entry in entries:
117 parts = entry.split(" ") 118 parts = entry.split(" ")
118 # Hack for symlink crappiness 119# # Hack for symlink crappiness
119 for symlink in symlinks: 120# for symlink in symlinks:
120 if parts[0].startswith(symlink): 121# if parts[0].startswith(symlink):
121 parts[0] = symlinks[symlink] + parts[0][len(symlink):] 122# parts[0] = symlinks[symlink] + parts[0][len(symlink):]
122 tarfiles.write(parts[0] + "\n") 123 tarfiles.write(parts[0] + "\n")
123 tarfiles.close() 124 tarfiles.close()
124 except: 125 except:
125 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) 126 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
126 127
127 # Use tar to transfer files into IMAGE directory 128 # Use tar to transfer files into IMAGE directory
128 tmpdir = "/var/tmp/portage"
129 image_dir = tmpdir + "/" + package.split("/")[1] + "/image"
130 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + " && tar -c --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -x'") 129 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp'")
131 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir + " && tar -c --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -x")): 130 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -cp --files-from=/tmp/tarfilelist --no-recursion 2>/dev/null | tar -C " + self._chroot_dir + image_dir + " -xp")):
132 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package) 131 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
133 132
134 # More symlink crappiness hacks 133# # More symlink crappiness hacks
135 for symlink in symlinks: 134# for symlink in symlinks:
136 if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 135## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
137# parts[0] = symlinks[symlink] + parts[len(symlink):] 136# if os.path.islink(self._chroot_dir + image_dir + symlink):
138 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): fixing /usr/livecd/gconf/ stuff in " + image_dir + " for " + package) 137# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): fixing " + symlink + " symlink ickiness stuff in " + image_dir + " for " + package)
138# GLIUtility.spawn("rm " + self._chroot_dir + image_dir + symlink)
139 if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)): 139# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)):
140 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix /usr/livecd/gconf/ stuff for " + package) 140# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
141 141
142 # Run pkg_setup 142 # Run pkg_setup
143 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 143 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
144 if not GLIUtility.exitsuccess(GLIUtility.spawn("env ROOT=" + self._chroot_dir + " PORTAGE_TMPDIR=" + self._chroot_dir + tmpdir + " ebuild " + self._chroot_dir + "/var/db/pkg/" + package + "/*.ebuild setup")): 144 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir)):
145 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) 145 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
146
147 # Run qmerge
148# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running qmerge for " + package)
149# if not GLIUtility.exitsuccess(GLIUtility.spawn("env ROOT=" + self._chroot_dir + " PORTAGE_TMPDIR=" + self._chroot_dir + tmpdir + " ebuild " + self._chroot_dir + "/var/db/pkg/" + package + "/*.ebuild qmerge")):
150# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute qmerge for " + package)
151 146
152 # Run pkg_preinst 147 # Run pkg_preinst
153 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 148 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
154 if not GLIUtility.exitsuccess(GLIUtility.spawn("env ROOT=" + self._chroot_dir + " PORTAGE_TMPDIR=" + self._chroot_dir + tmpdir + " ebuild " + self._chroot_dir + "/var/db/pkg/" + package + "/*.ebuild preinst")): 149 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir)):
155 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) 150 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
156 151
157 # Copy files from image_dir to chroot 152 # Copy files from image_dir to chroot
153 if not entries:
154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
155 else:
158 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 156 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
159 if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)): 157# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
158 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -c . | tar -C " + self._chroot_dir + "/ -x")):
160 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) 159 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
161 160
162 # Run pkg_postinst 161 # Run pkg_postinst
163 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 162 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
164 if not GLIUtility.exitsuccess(GLIUtility.spawn("env ROOT=" + self._chroot_dir + " PORTAGE_TMPDIR=" + self._chroot_dir + tmpdir + " ebuild " + "/var/db/pkg/" + package + "/*.ebuild postinst")): 163 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)):
165 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) 164 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
166 165
167 # Remove image_dir 166 # Remove image_dir
168 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing + " + image_dir + " for " + package) 167 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
169 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)): 168 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)):
170 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) 169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
171 170
171 # Run env-update
172 if not use_root:
173 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
174 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir)):
175 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
176
172 def add_pkg_to_world(self, package): 177 def add_pkg_to_world(self, package):
173 if package.find("/") == -1: 178 if package.find("/") == -1:
174 package = GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() 179 package = self.get_best_version_vdb_chroot(package)
175 if not package: return False 180 if not package: return False
176 expr = re.compile('^(.+?)(-\d.+)?$') 181 expr = re.compile('^=?(.+?/.+?)(-\d.+)?$')
177 res = expr.match(package) 182 res = expr.match(package)
178 if res: 183 if res:
179 GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world") 184 GLIUtility.spawn("echo " + res.group(1) + " >> " + self._chroot_dir + "/var/lib/portage/world")
180 185
181 def get_best_version_vdb(self, package): 186 def get_best_version_vdb(self, package):
187 if package.startswith('='):
188 package = package[1:]
189 if GLIUtility.is_file("/var/db/pkg/" + package):
190 return package
191 else:
192 return ""
193 else:
182 return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip() 194 return GLIUtility.spawn("portageq best_version / " + package, return_output=True)[1].strip()
183# 195
196 def get_best_version_vdb_chroot(self, package):
197 if package.startswith('='):
198 package = package[1:]
199 if GLIUtility.is_file(self._chroot_dir + "/var/db/pkg/" + package):
200 return package
201 else:
202 return ""
203 else:
204 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
205
184# def get_best_version_tree(self, package): 206# def get_best_version_tree(self, package):
185# return portage.best(tree.match(package)) 207# return portage.best(tree.match(package))
208
209 def emerge(self, packages, add_to_world=True):
210 if isinstance(packages, str):
211 packages = packages.split()
212 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
213 pkglist = self.get_deps(packages)
214 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
215 for i, pkg in enumerate(pkglist):
216 if not pkg: continue
217 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
218 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
219 if not self._grp_install or not self.get_best_version_vdb("=" + pkg):
220 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
221# status = self._emerge("=" + pkg)
222 if not GLIUtility.exitsuccess(status):
223 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
224 else:
225# try:
226 self.copy_pkg_to_chroot(pkg)
227# except:
228# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
229 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
230 if add_to_world:
231 for package in packages:
232 self.add_pkg_to_world(package)
233
234
235def usage(progname):
236 print """
237Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
238
239Options:
240
241 -c|--chroot-dir Specifies the directory where your chroot is. This is
242 "/mnt/gentoo" by default.
243
244 -g|--grp Install specified packages and dependencies into chroot
245 by using files from the LiveCD.
246
247 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
248 files from the LiveCD.
249
250 -h|--help Display this help
251""" % (progname)
252
253if __name__ == "__main__":
254 chroot_dir = "/mnt/gentoo"
255 mode = None
256 grp_packages = []
257 progname = sys.argv.pop(0)
258 while len(sys.argv):
259 arg = sys.argv.pop(0)
260 if arg == "-c" or arg == "--chroot-dir":
261 chroot_dir = sys.argv.pop(0)
262 elif arg == "-g" or arg == "--grp":
263 mode = "grp"
264 elif arg == "-s" or arg == "--stage3":
265 mode = "stage3"
266 elif arg == "-h" or arg == "--help":
267 usage(progname)
268 sys.exit(0)
269 elif arg[0] == "-":
270 usage(progname)
271 sys.exit(1)
272 else:
273 grp_packages.append(arg)
274
275 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
276 if mode == "stage3":
277 if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
278 print "Required file /usr/livecd/systempkgs.txt does not exist!"
279 sys.exit(1)
280 try:
281 syspkgs = open("/usr/livecd/systempkgs.txt", "r")
282 systempkgs = syspkgs.readlines()
283 syspkgs.close()
284 except:
285 print "Could not open /usr/livecd/systempkgs.txt!"
286 sys.exit(1)
287
288 # Pre-create /lib (and possible /lib32 and /lib64)
289 if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
290 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
291 print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
292 sys.exit(1)
293
294 syspkglen = len(systempkgs)
295 for i, pkg in enumerate(systempkgs):
296 pkg = pkg.strip()
297 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
298 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
299 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
300 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
301 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
302
303 # Nasty, nasty, nasty hack because vapier is a tool
304 for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
305 GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
306
307 chrootscript = r"""
308 #!/bin/bash
309
310 source /etc/make.conf
311 export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
312
313 ldconfig $LDPATH
314 gcc-config 1
315 env-update
316 source /etc/profile
317 modules-update
318 [ -f /usr/bin/binutils-config ] && binutils-config 1
319 source /etc/profile
320 #mount -t proc none /proc
321 #cd /dev
322 #/sbin/MAKEDEV generic-i386
323 #umount /proc
324 [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
325 """
326 script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
327 script.write(chrootscript)
328 script.close()
329 GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
330 GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
331 print "Stage3 equivelant generation complete!"
332 elif mode == "grp":
333 for pkg in grp_packages:
334 if not gliportage.get_best_version_vdb(pkg):
335 print "Package " + pkg + " is not available for install from the LiveCD"
336 continue
337 pkglist = gliportage.get_deps(pkg)
338 for i, tmppkg in enumerate(pkglist):
339 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
340 gliportage.copy_pkg_to_chroot(tmppkg)
341 gliportage.add_pkg_to_world(pkg)
342 print "GRP install complete!"
343 else:
344 print "You must specify an operating mode (-g or -s)!"
345 usage(progname)
346 sys.exit(1)

Legend:
Removed from v.1185  
changed lines
  Added in v.1311

  ViewVC Help
Powered by ViewVC 1.1.20