/[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

trunk/src/GLIPortage.py Revision 1310 branches/overhaul/src/GLIPortage.py Revision 1700
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.46 2006/02/20 17:26:24 agaffney Exp $ 8$Id: GLIPortage.py,v 1.57 2006/09/13 18:29:13 agaffney Exp $
9""" 9"""
10 10
11import re 11import re
12import os 12import os
13import sys 13import sys
14import GLIUtility 14import GLIUtility
15from GLIException import GLIException 15from GLIException import GLIException
16 16
17class GLIPortage(object): 17class GLIPortage(object):
18 18
19 def __init__(self, chroot_dir, grp_install, logger, debug, cc, compile_logfile): 19 def __init__(self, chroot_dir, logger, debug, cc, compile_logfile):
20 self._chroot_dir = chroot_dir 20 self._chroot_dir = chroot_dir
21 self._grp_install = grp_install
22 self._logger = logger 21 self._logger = logger
23 self._debug = debug 22 self._debug = debug
24 self._cc = cc 23 self._cc = cc
25 self._compile_logfile = compile_logfile 24 self._compile_logfile = compile_logfile
26 25
27 def get_deps(self, pkgs): 26 def get_deps(self, pkgs, grp_install=False):
28 pkglist = [] 27 pkglist = []
29 if isinstance(pkgs, str): 28 if isinstance(pkgs, str):
30 pkgs = pkgs.split() 29 pkgs = pkgs.split()
31 for pkg in pkgs: 30 for pkg in pkgs:
32 if not pkg: continue 31 if not pkg: continue
33 if self._debug: self._logger.log("get_deps(): pkg is " + pkg) 32 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): 33 if not grp_install or not self.get_best_version_vdb(pkg):
35 if self._debug: self._logger.log("get_deps(): grabbing compile deps") 34 if self._debug: self._logger.log("get_deps(): grabbing compile deps")
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 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")
37 else: 36 else:
38 if self._debug: self._logger.log("get_deps(): grabbing binary deps") 37 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 38 # The runtimedeps.py script generates a package install order that is *very* different from emerge itself
49 if self._debug: self._logger.log("get_deps(): checking to see if " + tmppkg + " is already in pkglist") 48 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): 49 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") 50 if self._debug: self._logger.log("get_deps(): adding " + tmppkg + " to pkglist")
52 pkglist.append(tmppkg) 51 pkglist.append(tmppkg)
53 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist)) 52 if self._debug: self._logger.log("get_deps(): pkglist is " + str(pkglist))
53 if not pkglist:
54 raise GLIException("GetDepListError", 'fatal', 'get_deps', "Dep list is empty. This usually means there is no portage tree in the chroot")
54 return pkglist 55 return pkglist
55 56
56 def parse_vdb_contents(self, file): 57 def parse_vdb_contents(self, file):
57 entries = [] 58 entries = []
58 try: 59 try:
73 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False): 74 def copy_pkg_to_chroot(self, package, use_root=False, ignore_missing=False):
74 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/', 75 symlinks = { '/bin': '/mnt/livecd/bin/', '/boot': '/mnt/livecd/boot/', '/lib': '/mnt/livecd/lib/',
75 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/', 76 '/opt': '/mnt/livecd/opt/', '/sbin': '/mnt/livecd/sbin/', '/usr': '/mnt/livecd/usr/',
76 '/etc/gconf': '/usr/livecd/gconf/' } 77 '/etc/gconf': '/usr/livecd/gconf/' }
77 78
78 tmpdir = "/var/tmp/portage" 79 tmpdir = "/var/tmp"
79 image_dir = tmpdir + "/" + package.split("/")[1] + "/image" 80 image_dir = tmpdir + "/portage/" + package.split("/")[1] + "/image"
80 root_cmd = "" 81 root_cmd = ""
81 tmp_chroot_dir = self._chroot_dir 82 tmp_chroot_dir = self._chroot_dir
82 portage_tmpdir = "/var/tmp/portage" 83 portage_tmpdir = "/var/tmp"
83 vdb_dir = "/var/db/pkg/" 84 vdb_dir = "/var/db/pkg/"
84 if use_root: 85 if use_root:
85 root_cmd = "ROOT=" + self._chroot_dir 86 root_cmd = "ROOT=" + self._chroot_dir
86 tmp_chroot_dir = "" 87 tmp_chroot_dir = ""
87 portage_tmpdir = self._chroot_dir + "/var/tmp/portage" 88 portage_tmpdir = self._chroot_dir + "/var/tmp"
88 vdb_dir = self._chroot_dir + "/var/db/pkg/" 89 vdb_dir = self._chroot_dir + "/var/db/pkg/"
90
91 # Create /tmp, /var/tmp, and /var/lib/portage with proper permissions
92 oldumask = os.umask(0)
93 if not os.path.exists(self._chroot_dir + "/tmp"):
94 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /tmp doesn't exist in chroot...creating with proper permissions")
95 try:
96 os.mkdir(self._chroot_dir + "/tmp", 01777)
97 except:
98 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /tmp in chroot")
99 if not os.path.exists(self._chroot_dir + "/var/tmp"):
100 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/tmp doesn't exist in chroot...creating with proper permissions")
101 try:
102 os.mkdir(self._chroot_dir + "/var", 0755)
103 except:
104 pass
105 try:
106 os.mkdir(self._chroot_dir + "/var/tmp", 01777)
107 except:
108 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/tmp in chroot")
109 if not os.path.exists(self._chroot_dir + "/var/lib/portage"):
110 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): /var/lib/portage doesn't exist in chroot...creating with proper permissions")
111 try:
112 os.mkdir(self._chroot_dir + "/var/lib", 0755)
113 except:
114 pass
115 try:
116 os.mkdir(self._chroot_dir + "/var/lib/portage", 02750)
117 except:
118 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Failed to create /var/lib/portage in chroot")
119 os.umask(oldumask)
89 120
90 # Check to see if package is actually in vdb 121 # Check to see if package is actually in vdb
91 if not GLIUtility.is_file("/var/db/pkg/" + package): 122 if not GLIUtility.is_file("/var/db/pkg/" + package):
92 if ignore_missing: 123 if ignore_missing:
93 if self._debug: 124 if self._debug:
96 else: 127 else:
97 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package) 128 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "There is no vdb entry for " + package)
98 129
99 # Copy the vdb entry for the package from the LiveCD to the chroot 130 # Copy the vdb entry for the package from the LiveCD to the chroot
100 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + package) 131 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying vdb entry for " + 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)): 132 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)):
102 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package) 133 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy vdb entry for " + package)
103 134
104 # Create the image dir in the chroot 135 # 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 + "'") 136 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)): 137 if not GLIUtility.exitsuccess(GLIUtility.spawn("mkdir -p " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
107 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package) 138 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create image dir for " + package)
108 139
109 # Create list of files for tar to work with from CONTENTS file in vdb entry 140 # Create list of files for tar to work with from CONTENTS file in vdb entry
110 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS") 141 entries = self.parse_vdb_contents("/var/db/pkg/" + package + "/CONTENTS")
111 if not entries: 142 if not entries:
112 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup") 143 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping tar and symlink fixup")
113 else: 144 else:
114 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries)) 145# if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot: files for " + package + ": " + str(entries))
115 try: 146 try:
116 tarfiles = open("/tmp/tarfilelist", "w") 147 tarfiles = open("/tmp/tarfilelist", "w")
117 for entry in entries: 148 for entry in entries:
118 parts = entry.split(" ") 149 parts = entry.split(" ")
119# # Hack for symlink crappiness 150# # Hack for symlink crappiness
125 except: 156 except:
126 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package) 157 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not create filelist for " + package)
127 158
128 # Use tar to transfer files into IMAGE directory 159 # Use tar to transfer files into IMAGE directory
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'") 160 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'")
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")): 161 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)):
131 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package) 162 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute tar for " + package)
163
164 # Fix mode, uid, and gid of directories
165 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 '^$'")
166 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")
167 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): found the following directories: " + str(dirlist))
168 if not dirlist or dirlist[0] == "":
169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "directory list entry for " + package + "...this shouldn't happen!")
170 for dir in dirlist:
171 dirstat = os.stat(dir)
172 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)
173 os.chown(self._chroot_dir + image_dir + dir, dirstat[4], dirstat[5])
174 os.chmod(self._chroot_dir + image_dir + dir, dirstat[0])
132 175
133# # More symlink crappiness hacks 176# # More symlink crappiness hacks
134# for symlink in symlinks: 177# for symlink in symlinks:
135## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]): 178## if GLIUtility.is_file(self._chroot_dir + image_dir + symlinks[symlink]):
136# if os.path.islink(self._chroot_dir + image_dir + symlink): 179# if os.path.islink(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)): 182# 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 " + symlink + " symlink ickiness for " + package) 183# raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not fix " + symlink + " symlink ickiness for " + package)
141 184
142 # Run pkg_setup 185 # Run pkg_setup
143 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running pkg_setup for " + package) 186 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_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild setup", chroot=tmp_chroot_dir)): 187 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)):
145 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package) 188 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute pkg_setup for " + package)
146 189
147 # Run pkg_preinst 190 # Run pkg_preinst
148 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package) 191 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running preinst for " + package)
149 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild preinst", chroot=tmp_chroot_dir)): 192 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)):
150 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package) 193 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute preinst for " + package)
151 194
152 # Copy files from image_dir to chroot 195 # Copy files from image_dir to chroot
153 if not entries: 196 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 /") 197 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): no files for " + package + "...skipping copy from image dir to /")
155 else: 198 else:
156 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package) 199 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): copying files from " + image_dir + " to / for " + package)
157# if not GLIUtility.exitsuccess(GLIUtility.spawn("cp -a " + self._chroot_dir + image_dir + "/* " + self._chroot_dir)): 200# 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")): 201 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)):
159 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package) 202 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not copy files from " + image_dir + " to / for " + package)
160 203
161 # Run pkg_postinst 204 # Run pkg_postinst
162 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package) 205 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running postinst for " + package)
163 if not GLIUtility.exitsuccess(GLIUtility.spawn("env " + root_cmd + " PORTAGE_TMPDIR=" + portage_tmpdir + " ebuild " + vdb_dir + package + "/*.ebuild postinst", chroot=tmp_chroot_dir)): 206 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)):
164 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package) 207 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not execute postinst for " + package)
165 208
166 # Remove image_dir 209 # Remove image_dir
167 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package) 210 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): removing " + image_dir + " for " + package)
168 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir)): 211 if not GLIUtility.exitsuccess(GLIUtility.spawn("rm -rf " + self._chroot_dir + image_dir, logfile=self._compile_logfile, append_log=True)):
169 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package) 212 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not remove + " + image_dir + " for " + package)
170 213
171 # Run env-update 214 # Run env-update
172 if not use_root: 215 if not use_root:
173 if self._debug: self._logger.log("DEBUG: copy_pkg_to_chroot(): running env-update inside chroot") 216 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)): 217 if not GLIUtility.exitsuccess(GLIUtility.spawn("env-update", chroot=self._chroot_dir, logfile=self._compile_logfile, append_log=True)):
175 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package) 218 raise GLIException("CopyPackageToChrootError", 'fatal', 'copy_pkg_to_chroot', "Could not run env-update for " + package)
176 219
177 def add_pkg_to_world(self, package): 220 def add_pkg_to_world(self, package):
178 if package.find("/") == -1: 221 if package.find("/") == -1:
179 package = self.get_best_version_vdb_chroot(package) 222 package = self.get_best_version_vdb_chroot(package)
204 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip() 247 return GLIUtility.spawn("portageq best_version / " + package, chroot=self._chroot_dir, return_output=True)[1].strip()
205 248
206# def get_best_version_tree(self, package): 249# def get_best_version_tree(self, package):
207# return portage.best(tree.match(package)) 250# return portage.best(tree.match(package))
208 251
209 def emerge(self, packages, add_to_world=True): 252 def emerge(self, packages, grp_install=False, add_to_world=True):
210 if isinstance(packages, str): 253 if isinstance(packages, str):
211 packages = packages.split() 254 packages = packages.split()
212 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages))) 255 self._cc.addNotification("progress", (0, "Calculating dependencies for " + " ".join(packages)))
213 pkglist = self.get_deps(packages) 256 pkglist = self.get_deps(packages, grp_install)
214 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist)) 257 if self._debug: self._logger.log("install_packages(): pkglist is " + str(pkglist))
215 for i, pkg in enumerate(pkglist): 258 for i, pkg in enumerate(pkglist):
216 if not pkg: continue 259 if not pkg: continue
217 if self._debug: self._logger.log("install_packages(): processing package " + pkg) 260 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)) + ")")) 261 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): 262 if not 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) 263 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) 264# status = self._emerge("=" + pkg)
222 if not GLIUtility.exitsuccess(status): 265 if not GLIUtility.exitsuccess(status):
223 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!") 266 raise GLIException("EmergePackageError", "fatal", "emerge", "Could not emerge " + pkg + "!")
224 else: 267 else:
230 if add_to_world: 273 if add_to_world:
231 for package in packages: 274 for package in packages:
232 self.add_pkg_to_world(package) 275 self.add_pkg_to_world(package)
233 276
234 277
235def usage(): 278def usage(progname):
236 print """ 279 print """
237Usage: GLIPortage.py [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help] 280Usage: %s [-c|--chroot-dir <chroot directory>] [-g|--grp] [-s|--stage3] [-h|--help]
238 281
239Options: 282Options:
240 283
241 -c|--chroot-dir Specifies the directory where your chroot is. This is 284 -c|--chroot-dir Specifies the directory where your chroot is. This is
242 "/mnt/gentoo" by default. 285 "/mnt/gentoo" by default.
245 by using files from the LiveCD. 288 by using files from the LiveCD.
246 289
247 -s|--stage3 Create a stage3 equivelant in the chroot directory by using 290 -s|--stage3 Create a stage3 equivelant in the chroot directory by using
248 files from the LiveCD. 291 files from the LiveCD.
249 292
293 -k|--kernel Install kernel and modules from LiveCD into the chroot
294
250 -h|--help Display this help 295 -h|--help Display this help
251""" 296""" % (progname)
252 297
253if __name__ == "__main__": 298if __name__ == "__main__":
254 chroot_dir = "/mnt/gentoo" 299 chroot_dir = "/mnt/gentoo"
255 mode = None 300 mode = None
256 grp_packages = [] 301 grp_packages = []
302 progname = sys.argv.pop(0)
257 while len(sys.argv): 303 while len(sys.argv):
258 arg = sys.argv.pop(0) 304 arg = sys.argv.pop(0)
259 if arg == "-c" or arg == "--chroot-dir": 305 if arg == "-c" or arg == "--chroot-dir":
260 chroot_dir = sys.argv.pop(0) 306 chroot_dir = sys.argv.pop(0)
261 elif arg == "-g" or arg == "--grp": 307 elif arg == "-g" or arg == "--grp":
262 mode = "grp" 308 mode = "grp"
263 elif arg == "-s" or arg == "--stage3": 309 elif arg == "-s" or arg == "--stage3":
264 mode = "stage3" 310 mode = "stage3"
311 elif arg == "-k" or arg == "--kernel":
312 mode = "kernel"
265 elif arg == "-h" or arg == "--help": 313 elif arg == "-h" or arg == "--help":
266 usage() 314 usage(progname)
267 sys.exit(0) 315 sys.exit(0)
268 elif arg[0] == "-": 316 elif arg[0] == "-":
269 usage() 317 usage(progname)
270 sys.exit(1) 318 sys.exit(1)
271 else: 319 else:
272 grp_packages.append(arg) 320 grp_packages.append(arg)
273 321
274 gliportage = GLIPortage(chroot_dir, True, None, False, None, None) 322 gliportage = GLIPortage(chroot_dir, True, None, False, None, None)
330 print "Stage3 equivelant generation complete!" 378 print "Stage3 equivelant generation complete!"
331 elif mode == "grp": 379 elif mode == "grp":
332 for pkg in grp_packages: 380 for pkg in grp_packages:
333 if not gliportage.get_best_version_vdb(pkg): 381 if not gliportage.get_best_version_vdb(pkg):
334 print "Package " + pkg + " is not available for install from the LiveCD" 382 print "Package " + pkg + " is not available for install from the LiveCD"
383 continue
335 pkglist = gliportage.get_deps(pkg) 384 pkglist = gliportage.get_deps(pkg, True)
336 for tmppkg in pkglist: 385 for i, tmppkg in enumerate(pkglist):
386 print "Copying " + tmppkg + " (" + str(i+1) + "/" + str(len(pkglist)) + ")"
337 gliportage.copy_pkg_to_chroot(tmppkg) 387 gliportage.copy_pkg_to_chroot(tmppkg)
338 gliportage.add_pkg_to_world(pkg) 388 gliportage.add_pkg_to_world(pkg)
339 print "GRP install complete!" 389 print "GRP install complete!"
390 elif mode == "kernel":
391 kernelpkg = gliportage.get_best_version_vdb("sys-kernel/livecd-kernel")
392 gliportage.copy_pkg_to_chroot(kernelpkg)
393 print "LiveCD kernel installed!"
340 else: 394 else:
341 print "You must specify an operating mode (-g or -s)!" 395 print "You must specify an operating mode (-g or -s)!"
342 usage() 396 usage(progname)
343 sys.exit(1) 397 sys.exit(1)

Legend:
Removed from v.1310  
changed lines
  Added in v.1700

  ViewVC Help
Powered by ViewVC 1.1.20