/[gli]/branches/overhaul/src/GLIPortage.py
Gentoo

Diff of /branches/overhaul/src/GLIPortage.py

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

Revision 1280 Revision 1309
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.35 2006/02/07 02:05:39 agaffney Exp $ 8$Id: GLIPortage.py,v 1.45 2006/02/20 17:20:57 agaffney Exp $
9""" 9"""
10 10
11import re 11import re
12import os 12import os
13import sys
13import GLIUtility 14import GLIUtility
14from GLIException import GLIException 15from GLIException import GLIException
15 16
16class GLIPortage(object): 17class GLIPortage(object):
17 18
26 def get_deps(self, pkgs): 27 def get_deps(self, pkgs):
27 pkglist = [] 28 pkglist = []
28 if isinstance(pkgs, str): 29 if isinstance(pkgs, str):
29 pkgs = pkgs.split() 30 pkgs = pkgs.split()
30 for pkg in pkgs: 31 for pkg in pkgs:
32 if not pkg: continue
31 if self._debug: self._logger.log("get_deps(): pkg is " + pkg) 33 if self._debug: self._logger.log("get_deps(): pkg is " + pkg)
32 if not self._grp_install or not self.get_best_version_vdb(pkg): 34 if not self._grp_install or not self.get_best_version_vdb(pkg):
33 if self._debug: self._logger.log("get_deps(): grabbing compile deps") 35 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
34 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") 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")
35 else: 37 else:
150 # Copy files from image_dir to chroot 152 # Copy files from image_dir to chroot
151 if not entries: 153 if not entries:
152 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /") 154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
153 else: 155 else:
154 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)
155 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")):
156 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)
157 160
158 # Run pkg_postinst 161 # Run pkg_postinst
159 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)
160 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)): 163 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)):
162 165
163 # Remove image_dir 166 # Remove image_dir
164 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)
165 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)):
166 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)
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)
167 176
168 def add_pkg_to_world(self, package): 177 def add_pkg_to_world(self, package):
169 if package.find("/") == -1: 178 if package.find("/") == -1:
170 package = self.get_best_version_vdb_chroot(package) 179 package = self.get_best_version_vdb_chroot(package)
171 if not package: return False 180 if not package: return False
173 res = expr.match(package) 182 res = expr.match(package)
174 if res: 183 if res:
175 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")
176 185
177 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:
178 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()
179 195
180 def get_best_version_vdb_chroot(self, package): 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:
181 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() 204 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
182 205
183# def get_best_version_tree(self, package): 206# def get_best_version_tree(self, package):
184# return portage.best(tree.match(package)) 207# return portage.best(tree.match(package))
185 208
186 def emerge(self, packages, add_to_world=True): 209 def emerge(self, packages, add_to_world=True):
188 packages = packages.split() 211 packages = packages.split()
189 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) 212 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
190 pkglist = self.get_deps(packages) 213 pkglist = self.get_deps(packages)
191 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) 214 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
192 for i, pkg in enumerate(pkglist): 215 for i, pkg in enumerate(pkglist):
216 if not pkg: continue
193 if self._debug: self._logger.log("install_packages(): processing package " + pkg) 217 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
194 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 218 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
195 if not self._grp_install or not self.get_best_version_vdb("=" + pkg): 219 if not self._grp_install or not self.get_best_version_vdb("=" + pkg):
196 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) 220 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
197# status = self._emerge("=" + pkg) 221# status = self._emerge("=" + pkg)
204# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 228# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
205 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 229 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
206 if add_to_world: 230 if add_to_world:
207 for package in packages: 231 for package in packages:
208 self.add_pkg_to_world(package) 232 self.add_pkg_to_world(package)
233
234
235def usage():
236 print """
237Usage: GLIPortage.py [-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"""
252
253if __name__ == "__main__":
254 chroot_dir = "/mnt/gentoo"
255 mode = None
256 grp_packages = []
257 while len(sys.argv):
258 arg = sys.argv.pop(0)
259 if arg == "-c" or arg == "--chroot-dir":
260 chroot_dir = sys.argv.pop(0)
261 elif arg == "-g" or arg == "--grp":
262 mode = "grp"
263 elif arg == "-s" or arg == "--stage3":
264 mode = "stage3"
265 elif arg == "-h" or arg == "--help":
266 usage()
267 sys.exit(0)
268 elif arg[0] == "-":
269 usage()
270 sys.exit(1)
271 else:
272 grp_packages.append(arg)
273
274 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
275 if mode == "stage3":
276 if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
277 print "Required file /usr/livecd/systempkgs.txt does not exist!"
278 sys.exit(1)
279 try:
280 syspkgs = open("/usr/livecd/systempkgs.txt", "r")
281 systempkgs = syspkgs.readlines()
282 syspkgs.close()
283 except:
284 print "Could not open /usr/livecd/systempkgs.txt!"
285 sys.exit(1)
286
287 # Pre-create /lib (and possible /lib32 and /lib64)
288 if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
289 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
290 print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
291 sys.exit(1)
292
293 syspkglen = len(systempkgs)
294 for i, pkg in enumerate(systempkgs):
295 pkg = pkg.strip()
296 sys.stdout.write("Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")\r")
297 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
298 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
299 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
300 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
301
302 # Nasty, nasty, nasty hack because vapier is a tool
303 for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
304 GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
305
306 chrootscript = r"""
307 #!/bin/bash
308
309 source /etc/make.conf
310 export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
311
312 ldconfig $LDPATH
313 gcc-config 1
314 env-update
315 source /etc/profile
316 modules-update
317 [ -f /usr/bin/binutils-config ] && binutils-config 1
318 source /etc/profile
319 #mount -t proc none /proc
320 #cd /dev
321 #/sbin/MAKEDEV generic-i386
322 #umount /proc
323 [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
324 """
325 script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
326 script.write(chrootscript)
327 script.close()
328 GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
329 GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
330 print "Stage3 equivelant generation complete!"
331 elif mode == "grp":
332 for pkg in grp_packages:
333 if not gliportage.get_best_version_vdb(pkg):
334 print "Package " + pkg + " is not available for install from the LiveCD"
335 pkglist = gliportage.get_deps(pkg)
336 for tmppkg in pkglist:
337 gliportage.copy_pkg_to_chroot(tmppkg)
338 gliportage.add_pkg_to_world(pkg)
339 print "GRP install complete!"
340 else:
341 print "You must specify an operating mode (-g or -s)!"
342 usage()
343 sys.exit(1)

Legend:
Removed from v.1280  
changed lines
  Added in v.1309

  ViewVC Help
Powered by ViewVC 1.1.20