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

Legend:
Removed from v.1196  
changed lines
  Added in v.1525

  ViewVC Help
Powered by ViewVC 1.1.20