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

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

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

Revision 1297 Revision 1338
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.40 2006/02/11 17:26:33 agaffney Exp $ 8$Id: GLIPortage.py,v 1.49 2006/03/05 03:06:44 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:
94 else: 96 else:
95 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) 97 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
96 98
97 # 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
98 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)
99 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, logfile=self._compile_logfile, append_log=True)):
100 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)
101 103
102 # Create the image dir in the chroot 104 # Create the image dir in the chroot
103 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'") 105 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running 'mkdir -p " + self._chroot_dir + image_dir + "'")
104 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir)): 106 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
105 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package) 107 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
106 108
107 # 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
108 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") 110 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
109 if not entries: 111 if not entries:
123 except: 125 except:
124 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)
125 127
126 # Use tar to transfer files into IMAGE directory 128 # Use tar to transfer files into IMAGE directory
127 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'") 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'")
128 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")): 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", logfile=self._compile_logfile, append_log=True)):
129 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)
132
133 # Fix mode, uid, and gid of directories
134 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'")
135 dirlist = GLIUtility.spawn("find " + self._chroot_dir + image_dir + " -type d 2>/dev/null | sed -e 's:^" + self._chroot_dir + image_dir + "::' | grep -v '^$'", return_output=True)[1].strip().split("\n")
136 if not dirlist or dirlist[0] == "":
137 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
138 for dir in dirlist:
139 dirstat = os.stat(dir)
140 os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
141 os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
130 142
131# # More symlink crappiness hacks 143# # More symlink crappiness hacks
132# for symlink in symlinks: 144# for symlink in symlinks:
133## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 145## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
134# if os.path.islink(self._chroot_dir + image_dir + symlink): 146# if os.path.islink(self._chroot_dir + image_dir + symlink):
137# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)): 149# if not GLIUtility.exitsuccess(GLIUtility.spawn("mv " + self._chroot_dir + image_dir + symlinks[symlink] + " " + self._chroot_dir + image_dir + symlink)):
138# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package) 150# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
139 151
140 # Run pkg_setup 152 # Run pkg_setup
141 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 153 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package)
142 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir)): 154 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
143 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) 155 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
144 156
145 # Run pkg_preinst 157 # Run pkg_preinst
146 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 158 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
147 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir)): 159 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
148 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) 160 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
149 161
150 # Copy files from image_dir to chroot 162 # Copy files from image_dir to chroot
151 if not entries: 163 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 /") 164 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
153 else: 165 else:
154 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 166 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)): 167# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)):
156 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -c . | tar -C " + self._chroot_dir + "/ -x")): 168 if not GLIUtility.exitsuccess(GLIUtility.spawn("tar -C " + self._chroot_dir + image_dir + "/ -cp . | tar -C " + self._chroot_dir + "/ -xp", logfile=self._compile_logfile, append_log=True)):
157 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) 169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
158 170
159 # Run pkg_postinst 171 # Run pkg_postinst
160 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 172 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
161 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)): 173 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir, logfile=self._compile_logfile, append_log=True)):
162 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) 174 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
163 175
164 # Remove image_dir 176 # Remove image_dir
165 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) 177 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
166 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)): 178 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
167 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) 179 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
168 180
169 # Run env-update 181 # Run env-update
170 if not use_root: 182 if not use_root:
171 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") 183 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot")
172 if not GLIUtility.exitstatus(GLIUtility.spawn("env-update", chroot=self._chroot_dir)): 184 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
173 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package) 185 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
174 186
175 def add_pkg_to_world(self, package): 187 def add_pkg_to_world(self, package):
176 if package.find("/") == -1: 188 if package.find("/") == -1:
177 package = self.get_best_version_vdb_chroot(package) 189 package = self.get_best_version_vdb_chroot(package)
209 packages = packages.split() 221 packages = packages.split()
210 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) 222 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
211 pkglist = self.get_deps(packages) 223 pkglist = self.get_deps(packages)
212 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) 224 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
213 for i, pkg in enumerate(pkglist): 225 for i, pkg in enumerate(pkglist):
226 if not pkg: continue
214 if self._debug: self._logger.log("install_packages(): processing package " + pkg) 227 if self._debug: self._logger.log("install_packages(): processing package " + pkg)
215 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 228 self._cc.addNotification("progress", (float(i) / len(pkglist), "Emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
216 if not self._grp_install or not self.get_best_version_vdb("=" + pkg): 229 if not self._grp_install or not self.get_best_version_vdb("=" + pkg):
217 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True) 230 status = GLIUtility.spawn("emerge -1 =" + pkg, display_on_tty8=True, chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)
218# status = self._emerge("=" + pkg) 231# status = self._emerge("=" + pkg)
225# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 238# raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
226 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")")) 239 self._cc.addNotification("progress", (float(i+1) / len(pkglist), "Done emerging " + pkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"))
227 if add_to_world: 240 if add_to_world:
228 for package in packages: 241 for package in packages:
229 self.add_pkg_to_world(package) 242 self.add_pkg_to_world(package)
243
244
245def usage(progname):
246 print """
247Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
248
249Options:
250
251 -c|--chroot-dir Specifies the directory where your chroot is. This is
252 "/mnt/gentoo" by default.
253
254 -g|--grp Install specified packages and dependencies into chroot
255 by using files from the LiveCD.
256
257 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
258 files from the LiveCD.
259
260 -h|--help Display this help
261""" % (progname)
262
263if __name__ == "__main__":
264 chroot_dir = "/mnt/gentoo"
265 mode = None
266 grp_packages = []
267 progname = sys.argv.pop(0)
268 while len(sys.argv):
269 arg = sys.argv.pop(0)
270 if arg == "-c" or arg == "--chroot-dir":
271 chroot_dir = sys.argv.pop(0)
272 elif arg == "-g" or arg == "--grp":
273 mode = "grp"
274 elif arg == "-s" or arg == "--stage3":
275 mode = "stage3"
276 elif arg == "-h" or arg == "--help":
277 usage(progname)
278 sys.exit(0)
279 elif arg[0] == "-":
280 usage(progname)
281 sys.exit(1)
282 else:
283 grp_packages.append(arg)
284
285 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
286 if mode == "stage3":
287 if not GLIUtility.is_file("/usr/livecd/systempkgs.txt"):
288 print "Required file /usr/livecd/systempkgs.txt does not exist!"
289 sys.exit(1)
290 try:
291 syspkgs = open("/usr/livecd/systempkgs.txt", "r")
292 systempkgs = syspkgs.readlines()
293 syspkgs.close()
294 except:
295 print "Could not open /usr/livecd/systempkgs.txt!"
296 sys.exit(1)
297
298 # Pre-create /lib (and possible /lib32 and /lib64)
299 if os.path.islink("/lib") and os.readlink("/lib") == "lib64":
300 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir " + chroot_dir + "/lib64 && ln -s lib64 " + chroot_dir + "/lib")):
301 print "Could not precreate /lib64 dir and /lib -> /lib64 symlink"
302 sys.exit(1)
303
304 syspkglen = len(systempkgs)
305 for i, pkg in enumerate(systempkgs):
306 pkg = pkg.strip()
307 print "Copying " + pkg + " (" + str(i+1) + "/" + str(syspkglen) + ")"
308 gliportage.copy_pkg_to_chroot(pkg, True, ignore_missing=True)
309 GLIUtility.spawn("cp /etc/make.conf " + chroot_dir + "/etc/make.conf")
310 GLIUtility.spawn("ln -s `readlink /etc/make.profile` " + chroot_dir + "/etc/make.profile")
311 GLIUtility.spawn("cp -f /etc/inittab.old " + chroot_dir + "/etc/inittab")
312
313 # Nasty, nasty, nasty hack because vapier is a tool
314 for tmpfile in ("/etc/passwd", "/etc/group", "/etc/shadow"):
315 GLIUtility.spawn("grep -ve '^gentoo' " + tmpfile + " > " + chroot_dir + tmpfile)
316
317 chrootscript = r"""
318 #!/bin/bash
319
320 source /etc/make.conf
321 export LDPATH="/usr/lib/gcc-lib/${CHOST}/$(cd /usr/lib/gcc-lib/${CHOST} && ls -1 | head -n 1)"
322
323 ldconfig $LDPATH
324 gcc-config 1
325 env-update
326 source /etc/profile
327 modules-update
328 [ -f /usr/bin/binutils-config ] && binutils-config 1
329 source /etc/profile
330 #mount -t proc none /proc
331 #cd /dev
332 #/sbin/MAKEDEV generic-i386
333 #umount /proc
334 [ -f /lib/udev-state/devices.tar.bz2 ] && tar -C /dev -xjf /lib/udev-state/devices.tar.bz2
335 """
336 script = open(chroot_dir + "/tmp/extrastuff.sh", "w")
337 script.write(chrootscript)
338 script.close()
339 GLIUtility.spawn("chmod 755 /tmp/extrastuff.sh && /tmp/extrastuff.sh", chroot=chroot_dir)
340 GLIUtility.spawn("rm -rf /var/tmp/portage/* /usr/portage /tmp/*", chroot=chroot_dir)
341 print "Stage3 equivelant generation complete!"
342 elif mode == "grp":
343 for pkg in grp_packages:
344 if not gliportage.get_best_version_vdb(pkg):
345 print "Package " + pkg + " is not available for install from the LiveCD"
346 continue
347 pkglist = gliportage.get_deps(pkg)
348 for i, tmppkg in enumerate(pkglist):
349 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
350 gliportage.copy_pkg_to_chroot(tmppkg)
351 gliportage.add_pkg_to_world(pkg)
352 print "GRP install complete!"
353 else:
354 print "You must specify an operating mode (-g or -s)!"
355 usage(progname)
356 sys.exit(1)

Legend:
Removed from v.1297  
changed lines
  Added in v.1338

  ViewVC Help
Powered by ViewVC 1.1.20