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

Legend:
Removed from v.1208  
changed lines
  Added in v.1339

  ViewVC Help
Powered by ViewVC 1.1.20