import os, string, types, shutil
from stat import *
import catalyst
-from catalyst.output import warn
+from catalyst.output import *
from catalyst.spawn import cmd
from catalyst.error import *
from catalyst.target.generic import *
self.settings["crosscompile"]=(self.settings["hostarch"]!=\
self.settings["buildarch"])
+ # XXX This should be moved somewhere "higher"
""" Call arch constructor, pass our settings """
try:
self.arch=self.subarchmap[self.settings["subarch"]](self.settings)
except KeyError:
- print "Invalid subarch: "+self.settings["subarch"]
- print "Choose one of the following:",
- for x in self.subarchmap:
- print x,
- print
+ msg("Invalid subarch: " + self.settings["subarch"])
+ msg("Choose one of the following:")
+ msg("\n".join(self.subarchmap.keys()))
sys.exit(2)
- print "Using target:",self.settings["target"]
+ msg("Using target: " + self.settings["target"])
""" Print a nice informational message """
if self.settings["buildarch"]==self.settings["hostarch"]:
- print "Building natively for",self.settings["hostarch"]
+ msg("Building natively for " + self.settings["hostarch"])
elif self.settings["crosscompile"]:
- print "Cross-compiling on",self.settings["buildarch"],\
- "for different machine type",self.settings["hostarch"]
+ msg("Cross-compiling on " + self.settings["buildarch"] + \
+ "for different machine type " + self.settings["hostarch"])
else:
- print "Building on",self.settings["buildarch"],\
- "for alternate personality type",self.settings["hostarch"]
+ msg("Building on" + self.settings["buildarch"] + \
+ "for alternate personality type " + self.settings["hostarch"])
""" This must be set first as other set_ options depend on this """
self.set_spec_prefix()
"""
if "PKGCACHE" in self.settings:
self.set_pkgcache_path()
- print "Location of the package cache is "+\
- self.settings["pkgcache_path"]
+ msg("Location of the package cache is " + \
+ self.settings["pkgcache_path"])
self.mounts.append("/usr/portage/packages")
self.mountmap["/usr/portage/packages"]=\
self.settings["pkgcache_path"]
if "KERNCACHE" in self.settings:
self.set_kerncache_path()
- print "Location of the kerncache is "+\
- self.settings["kerncache_path"]
+ msg("Location of the kerncache is " + \
+ self.settings["kerncache_path"])
self.mounts.append("/tmp/kerncache")
self.mountmap["/tmp/kerncache"]=self.settings["kerncache_path"]
self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+\
"/builds/"+self.settings["target_subpath"]+".tar.bz2")
if self.check_autoresume("setup_target_path"):
- print "Resume point detected, skipping target path setup operation..."
+ msg("Resume point detected, skipping target path setup operation...")
else:
""" First clean up any existing target stuff """
# XXX WTF are we removing the old tarball before we start building the
self.settings["fstype"]="normal"
for x in self.valid_values:
if x == self.settings["spec_prefix"]+"/fstype":
- print "\n"+self.settings["spec_prefix"]+\
- "/fstype is being set to the default of \"normal\"\n"
+ msg(self.settings["spec_prefix"] + \
+ "/fstype is being set to the default of 'normal'")
def set_fsops(self):
if "fstype" in self.settings:
catalyst.hash.generate_hash(self.settings["source_path"],\
hash_function=self.settings["hash_function"],\
verbose=False)
- print "Source path set to "+self.settings["source_path"]
+ msg("Source path set to " + self.settings["source_path"])
if os.path.isdir(self.settings["source_path"]):
- print "\tIf this is not desired, remove this directory or turn off"
- print "\tseedcache in the options of catalyst.conf the source path"
- print "\twill then be "+\
- catalyst.util.normpath(self.settings["storedir"]+"/builds/"+\
- self.settings["source_subpath"]+".tar.bz2\n")
+ msg("\tIf this is not desired, remove this directory or turn off")
+ msg("\tseedcache in the options of catalyst.conf the source path")
+ msg("\twill then be " + \
+ catalyst.util.normpath(self.settings["storedir"] + "/builds/" + \
+ self.settings["source_subpath"] + ".tar.bz2"))
def set_dest_path(self):
if "root_path" in self.settings:
self.settings["snapshot"]+"/")
self.snapcache_lock=\
catalyst.lock.LockDir(self.settings["snapshot_cache_path"])
- print "Caching snapshot to "+self.settings["snapshot_cache_path"]
+ msg("Caching snapshot to " + self.settings["snapshot_cache_path"])
def set_chroot_path(self):
"""
if type(self.settings["portage_overlay"])==types.StringType:
self.settings["portage_overlay"]=\
self.settings["portage_overlay"].split()
- print "portage_overlay directories are set to: \""+\
- string.join(self.settings["portage_overlay"])+"\""
+ msg("portage_overlay directories are set to: '" + \
+ "".join(self.settings["portage_overlay"]) + "'")
def set_overlay(self):
if self.settings["spec_prefix"]+"/overlay" in self.settings:
del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
def kill_chroot_pids(self):
- print "Checking for processes running in chroot and killing them."
+ msg("Checking for processes running in chroot and killing them.")
"""
Force environment variables to be exported so script can see them
if catalyst.util.ismount(mypath+x):
""" Something is still mounted "" """
try:
- print x+" is still mounted; performing auto-bind-umount...",
+ msg(x + " is still mounted; performing auto-bind-umount...")
""" Try to umount stuff ourselves """
self.unbind()
if catalyst.util.ismount(mypath+x):
- raise CatalystError, "Auto-unbind failed for "+x
+ raise CatalystError("Auto-unbind failed for " + x)
else:
- print "Auto-unbind successful..."
+ msg("Auto-unbind successful...")
except CatalystError:
raise CatalystError, "Unable to auto-unbind "+x
self.settings["chroot_path"]+" failed."
else:
""" SEEDCACHE is a not a directory, try untar'ing """
- print "Referenced SEEDCACHE does not appear to be a directory, trying to untar..."
+ msg("Referenced SEEDCACHE does not appear to be a directory, trying to untar...")
display_msg="\nStarting tar extract from "+\
self.settings["source_path"]+"\nto "+\
self.settings["chroot_path"]+\
if invalid_snapshot:
if self.check_autoresume():
- print "No Valid Resume point detected, cleaning up..."
+ msg("No Valid Resume point detected, cleaning up...")
self.clear_autoresume()
self.clear_chroot()
if not os.path.exists(self.settings["kerncache_path"]):
os.makedirs(self.settings["kerncache_path"],0755)
- print display_msg
+ msg(display_msg)
cmd(unpack_cmd,error_msg,env=self.env)
if "source_path_hash" in self.settings:
else:
self.set_autoresume("unpack")
else:
- print "Resume point detected, skipping unpack operation..."
+ msg("Resume point detected, skipping unpack operation...")
def unpack_snapshot(self):
unpack=True
self.snapshot_lock_object=self.snapcache_lock
if self.settings["snapshot_path_hash"]==snapshot_cache_hash:
- print "Valid snapshot cache, skipping unpack of portage tree..."
+ msg("Valid snapshot cache, skipping unpack of portage tree...")
unpack=False
else:
destdir=catalyst.util.normpath(self.settings["chroot_path"]+"/usr/portage")
and os.path.exists(self.settings["chroot_path"]+\
"/usr/portage/") \
and self.settings["snapshot_path_hash"] == snapshot_hash:
- print \
- "Valid Resume point detected, skipping unpack of portage tree..."
+ msg("Valid Resume point detected, skipping unpack of portage tree...")
unpack=False
if unpack:
if "SNAPCACHE" in self.settings:
self.snapshot_lock_object.write_lock()
if os.path.exists(destdir):
- print cleanup_msg
+ msg(cleanup_msg)
cleanup_cmd="rm -rf "+destdir
cmd(cleanup_cmd,cleanup_errmsg,env=self.env)
if not os.path.exists(destdir):
os.makedirs(destdir,0755)
- print "Unpacking portage tree (This can take a long time) ..."
+ msg("Unpacking portage tree (This can take a long time) ...")
cmd(unpack_cmd,unpack_errmsg,env=self.env)
if "SNAPCACHE" in self.settings:
myf.write(self.settings["snapshot_path_hash"])
myf.close()
else:
- print "Setting snapshot autoresume point"
+ msg("Setting snapshot autoresume point")
myf=open(self.settings["autoresume_path"]+"unpack_portage","w")
myf.write(self.settings["snapshot_path_hash"])
myf.close()
def config_profile_link(self):
if self.check_autoresume("config_profile_link"):
- print \
- "Resume point detected, skipping config_profile_link operation..."
+ msg("Resume point detected, skipping config_profile_link operation...")
else:
# TODO: zmedico and I discussed making this a directory and pushing
# in a parent file, as well as other user-specified configuration.
- print "Configuring profile link..."
+ msg("Configuring profile link...")
cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.profile",\
"Error zapping profile link",env=self.env)
cmd("ln -sf ../usr/portage/profiles/"+\
def setup_confdir(self):
if self.check_autoresume("setup_confdir"):
- print "Resume point detected, skipping setup_confdir operation..."
+ msg("Resume point detected, skipping setup_confdir operation...")
else:
if "portage_confdir" in self.settings:
- print "Configuring /etc/portage..."
+ msg("Configuring /etc/portage...")
cmd("rm -rf "+self.settings["chroot_path"]+"/etc/portage",\
"Error zapping /etc/portage",env=self.env)
cmd("cp -R "+self.settings["portage_confdir"]+"/ "+\
if "portage_overlay" in self.settings:
for x in self.settings["portage_overlay"]:
if os.path.exists(x):
- print "Copying overlay dir " +x
+ msg("Copying overlay dir " + x)
cmd("mkdir -p "+self.settings["chroot_path"]+\
"/usr/local/portage",\
"Could not make portage_overlay dir",env=self.env)
for x in self.settings[self.settings["spec_prefix"]+\
"/root_overlay"]:
if os.path.exists(x):
- print "Copying root_overlay: "+x
+ msg("Copying root_overlay: " + x)
cmd("rsync -a "+x+"/ "+\
self.settings["chroot_path"],\
self.settings["spec_prefix"]+"/root_overlay: "+x+\
self.override_cxxflags()
self.override_ldflags()
if self.check_autoresume("chroot_setup"):
- print "Resume point detected, skipping chroot_setup operation..."
+ msg("Resume point detected, skipping chroot_setup operation...")
else:
- print "Setting up chroot..."
+ msg("Setting up chroot...")
#self.makeconf=catalyst.util.read_makeconf(self.settings["chroot_path"]+"/etc/make.conf")
raise CatalystError,\
"Can't find envscript "+self.settings["ENVSCRIPT"]
- print "\nWarning!!!!"
- print "\tOverriding certain env variables may cause catastrophic failure."
- print "\tIf your build fails look here first as the possible problem."
- print "\tCatalyst assumes you know what you are doing when setting"
- print "\t\tthese variables."
- print "\tCatalyst Maintainers use VERY minimal envscripts if used at all"
- print "\tYou have been warned\n"
+ msg("\nWarning!!!!")
+ msg("\tOverriding certain env variables may cause catastrophic failure.")
+ msg("\tIf your build fails look here first as the possible problem.")
+ msg("\tCatalyst assumes you know what you are doing when setting")
+ msg("\t\tthese variables.")
+ msg("\tCatalyst Maintainers use VERY minimal envscripts if used at all")
+ msg("\tYou have been warned\n")
cmd("cp "+self.settings["ENVSCRIPT"]+" "+\
self.settings["chroot_path"]+"/tmp/envscript",\
myusevars = sorted(set(myusevars))
myf.write('USE="'+string.join(myusevars)+'"\n')
if '-*' in myusevars:
- print "\nWarning!!! "
- print "\tThe use of -* in "+self.settings["spec_prefix"]+\
- "/use will cause portage to ignore"
- print "\tpackage.use in the profile and portage_confdir. You've been warned!"
+ msg("\nWarning!!! ")
+ msg("\tThe use of -* in " + self.settings["spec_prefix"] + \
+ "/use will cause portage to ignore")
+ msg("\tpackage.use in the profile and portage_confdir. You've been warned!")
""" Setup the portage overlay """
if "portage_overlay" in self.settings:
def fsscript(self):
if self.check_autoresume("fsscript"):
- print "Resume point detected, skipping fsscript operation..."
+ msg("Resume point detected, skipping fsscript operation...")
else:
if "fsscript" in self.settings:
if os.path.exists(self.settings["controller_file"]):
def rcupdate(self):
if self.check_autoresume("rcupdate"):
- print "Resume point detected, skipping rcupdate operation..."
+ msg("Resume point detected, skipping rcupdate operation...")
else:
if os.path.exists(self.settings["controller_file"]):
cmd("/bin/bash "+self.settings["controller_file"]+" rc-update",\
def clean(self):
if self.check_autoresume("clean"):
- print "Resume point detected, skipping clean operation..."
+ msg("Resume point detected, skipping clean operation...")
else:
for x in self.settings["cleanables"]:
- print "Cleaning chroot: "+x+"... "
+ msg("Cleaning chroot: " + x +"...")
cmd("rm -rf "+self.settings["destpath"]+x,"Couldn't clean "+\
x,env=self.env)
def empty(self):
if self.check_autoresume("empty"):
- print "Resume point detected, skipping empty operation..."
+ msg("Resume point detected, skipping empty operation...")
else:
if self.settings["spec_prefix"]+"/empty" in self.settings:
if type(self.settings[self.settings["spec_prefix"]+\
for x in self.settings[self.settings["spec_prefix"]+"/empty"]:
myemp=self.settings["destpath"]+x
if not os.path.isdir(myemp):
- print x,"not a directory or does not exist, skipping 'empty' operation."
+ msg(x + " not a directory or does not exist, skipping 'empty' operation.")
continue
- print "Emptying directory",x
+ msg("Emptying directory" + x)
"""
stat the dir, delete the dir, recreate the dir and set
the proper perms and ownership
def remove(self):
if self.check_autoresume("remove"):
- print "Resume point detected, skipping remove operation..."
+ msg("Resume point detected, skipping remove operation...")
else:
if self.settings["spec_prefix"]+"/rm" in self.settings:
for x in self.settings[self.settings["spec_prefix"]+"/rm"]:
We're going to shell out for all these cleaning
operations, so we get easy glob handling.
"""
- print "livecd: removing "+x
+ msg("livecd: removing " + x)
os.system("rm -rf "+self.settings["chroot_path"]+x)
try:
if os.path.exists(self.settings["controller_file"]):
def preclean(self):
if self.check_autoresume("preclean"):
- print "Resume point detected, skipping preclean operation..."
+ msg("Resume point detected, skipping preclean operation...")
else:
try:
if os.path.exists(self.settings["controller_file"]):
def capture(self):
if self.check_autoresume("capture"):
- print "Resume point detected, skipping capture operation..."
+ msg("Resume point detected, skipping capture operation...")
else:
""" Capture target in a tarball """
mypath=self.settings["target_path"].split("/")
if not os.path.exists(mypath):
os.makedirs(mypath)
- print "Creating stage tarball..."
+ msg("Creating stage tarball...")
cmd("tar cjpf "+self.settings["target_path"]+" -C "+\
self.settings["stage_path"]+" .",\
def run_local(self):
if self.check_autoresume("run_local"):
- print "Resume point detected, skipping run_local operation..."
+ msg("Resume point detected, skipping run_local operation...")
else:
try:
if os.path.exists(self.settings["controller_file"]):
self.purge()
for x in self.settings["action_sequence"]:
- print "--- Running action sequence: "+x
+ msg("--- Running action sequence: " + x)
sys.stdout.flush()
try:
apply(getattr(self,x))
def unmerge(self):
if self.check_autoresume("unmerge"):
- print "Resume point detected, skipping unmerge operation..."
+ msg("Resume point detected, skipping unmerge operation...")
else:
if self.settings["spec_prefix"]+"/unmerge" in self.settings:
if type(self.settings[self.settings["spec_prefix"]+\
cmd("/bin/bash "+self.settings["controller_file"]+\
" unmerge "+ myunmerge,"Unmerge script failed.",\
env=self.env)
- print "unmerge shell script"
+ msg("unmerge shell script")
except CatalystError:
self.unbind()
raise
def target_setup(self):
if self.check_autoresume("target_setup"):
- print "Resume point detected, skipping target_setup operation..."
+ msg("Resume point detected, skipping target_setup operation...")
else:
- print "Setting up filesystems per filesystem type"
+ msg("Setting up filesystems per filesystem type")
cmd("/bin/bash "+self.settings["controller_file"]+\
" target_image_setup "+ self.settings["target_path"],\
"target_image_setup script failed.",env=self.env)
def setup_overlay(self):
if self.check_autoresume("setup_overlay"):
- print "Resume point detected, skipping setup_overlay operation..."
+ msg("Resume point detected, skipping setup_overlay operation...")
else:
if self.settings["spec_prefix"]+"/overlay" in self.settings:
for x in self.settings[self.settings["spec_prefix"]+"/overlay"]:
def create_iso(self):
if self.check_autoresume("create_iso"):
- print "Resume point detected, skipping create_iso operation..."
+ msg("Resume point detected, skipping create_iso operation...")
else:
""" Create the ISO """
if "iso" in self.settings:
catalyst.hash.gen_digest_file(self.settings["iso"], self.settings)
self.set_autoresume("create_iso")
else:
- print "WARNING: livecd/iso was not defined."
- print "An ISO Image will not be created."
+ msg("WARNING: livecd/iso was not defined.")
+ msg("An ISO Image will not be created.")
def build_packages(self):
if self.settings["spec_prefix"]+"/packages" in self.settings:
if self.check_autoresume("build_packages"):
- print "Resume point detected, skipping build_packages operation..."
+ msg("Resume point detected, skipping build_packages operation...")
else:
mypack = \
catalyst.util.list_bashify(self.settings[self.settings["spec_prefix"] \
def build_kernel(self):
if self.check_autoresume("build_kernel"):
- print "Resume point detected, skipping build_kernel operation..."
+ msg("Resume point detected, skipping build_kernel operation...")
else:
if "boot/kernel" in self.settings:
try:
for kname in mynames:
if self.check_autoresume("build_kernel_" + kname):
- print "Resume point detected, skipping build_kernel for "+kname+" operation..."
+ msg("Resume point detected, skipping build_kernel for " + kname + " operation...")
else: # TODO: make this not require a kernel config
try:
if not os.path.exists(self.settings["boot/kernel/"+kname+"/config"]):
"/initramfs_overlay"):
if os.path.exists(self.settings["boot/kernel/"+\
kname+"/initramfs_overlay"]):
- print "Copying initramfs_overlay dir "+\
- self.settings["boot/kernel/"+kname+\
- "/initramfs_overlay"]
+ msg("Copying initramfs_overlay dir " + \
+ self.settings["boot/kernel/" + kname + \
+ "/initramfs_overlay"])
cmd("mkdir -p "+\
self.settings["chroot_path"]+\
"/initramfs_overlay"):
if os.path.exists(self.settings["chroot_path"]+\
"/tmp/initramfs_overlay/"):
- print "Cleaning up temporary overlay dir"
+ msg("Cleaning up temporary overlay dir")
cmd("rm -R "+self.settings["chroot_path"]+\
"/tmp/initramfs_overlay/",env=self.env)
def bootloader(self):
if self.check_autoresume("bootloader"):
- print "Resume point detected, skipping bootloader operation..."
+ msg("Resume point detected, skipping bootloader operation...")
else:
try:
cmd("/bin/bash "+self.settings["controller_file"]+\
def livecd_update(self):
if self.check_autoresume("livecd_update"):
- print "Resume point detected, skipping build_packages operation..."
+ msg("Resume point detected, skipping build_packages operation...")
else:
try:
cmd("/bin/bash "+self.settings["controller_file"]+\
def clear_chroot(self):
myemp=self.settings["chroot_path"]
if os.path.isdir(myemp):
- print "Emptying directory",myemp
+ msg("Emptying directory " + myemp)
"""
stat the dir, delete the dir, recreate the dir and set
the proper perms and ownership
def clear_packages(self):
if "PKGCACHE" in self.settings:
- print "purging the pkgcache ..."
+ msg("purging the pkgcache...")
myemp=self.settings["pkgcache_path"]
if os.path.isdir(myemp):
- print "Emptying directory",myemp
+ msg("Emptying directory " + myemp)
"""
stat the dir, delete the dir, recreate the dir and set
the proper perms and ownership
def clear_kerncache(self):
if "KERNCACHE" in self.settings:
- print "purging the kerncache ..."
+ msg("purging the kerncache...")
myemp=self.settings["kerncache_path"]
if os.path.isdir(myemp):
- print "Emptying directory",myemp
+ msg("Emptying directory " + myemp)
"""
stat the dir, delete the dir, recreate the dir and set
the proper perms and ownership
def clear_autoresume(self):
""" Clean resume points since they are no longer needed """
if self.check_autoresume():
- print "Removing AutoResume Points: ..."
+ msg("Removing AutoResume Points: ...")
myemp=self.settings["autoresume_path"]
if os.path.isdir(myemp):
- print "Emptying directory",myemp
+ msg("Emptying directory " + myemp)
"""
stat the dir, delete the dir, recreate the dir and set
the proper perms and ownership
def purge(self):
catalyst.util.countdown(10, "Purging Caches ...")
if "PURGE" in self.settings or "PURGEONLY" in self.settings:
- print "clearing autoresume ..."
+ msg("clearing autoresume ...")
self.clear_autoresume()
- print "clearing chroot ..."
+ msg("clearing chroot ...")
self.clear_chroot()
- print "clearing package cache ..."
+ msg("clearing package cache ...")
self.clear_packages()
- print "clearing kerncache ..."
+ msg("clearing kerncache ...")
self.clear_kerncache()
# vim: ts=4 sw=4 sta et sts=4 ai