# Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS)
# Distributed under the GPL v2
+ 12 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
+ modules/catalyst/config.py, modules/catalyst/error.py,
+ modules/catalyst/hash.py, modules/catalyst/output.py,
+ modules/catalyst/spawn.py, modules/catalyst/target/embedded.py,
+ modules/catalyst/target/grp.py, modules/catalyst/target/livecd_stage1.py,
+ modules/catalyst/target/livecd_stage2.py,
+ modules/catalyst/target/netboot.py, modules/catalyst/target/snapshot.py,
+ modules/catalyst/target/stage1.py, modules/catalyst/target/stage2.py,
+ modules/catalyst/target/stage3.py:
+ Replace more instances of print with msg()
+
12 Jan 2009; Andrew Gaffney <agaffney@gentoo.org> catalyst,
modules/catalyst/output.py, modules/catalyst/util.py:
More replacements of the print statement with msg()
import re
from catalyst.error import *
+from catalyst.output import *
required_config_file_values=["storedir","sharedir","distdir","portdir"]
valid_config_file_values=required_config_file_values[:]
for x in values.keys():
# Delete empty key pairs
if not values[x]:
- print "\n\tWARNING: No value set for key " + x + "...deleting"
+ msg("\n\tWARNING: No value set for key " + x + "...deleting")
del values[x]
self.values = values
"""
import sys, traceback
-import catalyst.output
+from catalyst.output import *
class CatalystError(Exception):
def __init__(self, message):
if message:
(extype,value)=sys.exc_info()[:2]
if value!=None:
- print
- print traceback.print_exc(file=sys.stdout)
- print
- catalyst.output.warn(message)
- print
+ msg()
+ msg(traceback.print_exc(file=sys.stdout))
+ msg()
+ warn(message)
+ msg()
class LockInUse(Exception):
def __init__(self, message):
#if value!=None:
#print
#kprint traceback.print_exc(file=sys.stdout)
- print
- catalyst.output.warn("lock file in use: " + message)
- print
+ msg()
+ warn("lock file in use: " + message)
+ msg()
import os
from catalyst.error import *
-from catalyst.output import warn
+from catalyst.output import *
def gen_contents_file(file, settings):
if os.path.exists(file+".CONTENTS"):
result = "".join(a.readlines())
a.close()
if verbose:
- print result
+ msg(result)
return result
# This has map must be defined after the function calc_content
result = a.readline().split()[0]
a.close()
if verbose:
- print "%s (%s) = %s" % (id_string, file, result)
+ msg("%s (%s) = %s" % (id_string, file, result))
return result
def calc_hash2(file, cmd, cmd_args, id_string="MD5", verbose=False):
short_file = os.path.split(myline[1])[1]
result = header + tmphash + " " + short_file + "\n"
if verbose:
- print "%s (%s) = %s" % (header, short_file, result)
+ msg("%s (%s) = %s" % (header, short_file, result))
return result
# This has map must be defined after the function calc_hash
verbosity = 1
-def msg(mymsg, verblevel=1, newline=True):
+def msg(mymsg="", verblevel=1, newline=True):
if verbosity >= verblevel:
if newline:
print mymsg
else:
print mymsg,
-def warn(msg):
- print "!!! catalyst: " + msg
+def warn(message):
+ msg("!!! catalyst: " + message)
-def die(msg, exitcode=1):
- warn(msg)
+def die(message, exitcode=1):
+ warn(message)
sys.exit(exitcode)
import sys, os, types, signal
import catalyst.util
from catalyst.error import *
+from catalyst.output import *
BASH_BINARY = "/bin/bash"
os.umask(022)
try:
- #print "execing", myc, myargs
+ #msg("execing", myc, myargs)
if func_call:
# either use a passed in func for interpretting the results, or return if no exception.
# note the passed in list, and dict are expanded.
try:
mycommand[0](*mycommand[1],**mycommand[2])
except Exception,e:
- print "caught exception",e," in forked func",mycommand[0]
+ msg("caught exception",e," in forked func",mycommand[0])
sys.exit(0)
#os.execvp(myc,myargs)
except Exception, e:
if not func_call:
raise str(e)+":\n "+myc+" "+"".join(myargs)
- print "func call failed"
+ msg("func call failed")
# If the execve fails, we need to report it, and exit
# *carefully* --- report error here
from generic_stage import *
import catalyst.util
+from catalyst.output import *
class embedded_target(generic_stage_target):
def set_stage_path(self):
self.settings["stage_path"]=catalyst.util.normpath(self.settings["chroot_path"]+"/tmp/mergeroot")
- print "embedded stage path is "+self.settings["stage_path"]
+ msg("embedded stage path is " + self.settings["stage_path"])
def set_root_path(self):
self.settings["root_path"]=catalyst.util.normpath("/tmp/mergeroot")
- print "embedded root path is "+self.settings["root_path"]
+ msg("embedded root path is " + self.settings["root_path"])
__target_map = {"embedded":embedded_target}
import catalyst
from catalyst.error import *
from catalyst.spawn import cmd
+from catalyst.output import *
class grp_target(generic_stage_target):
def __init__(self,spec,addlargs):
def set_target_path(self):
self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
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
#if os.path.isdir(self.settings["target_path"]):
for pkgset in self.settings["grp"]:
if self.settings["grp/"+pkgset+"/type"] == "pkgset":
destdir=catalyst.util.normpath(self.settings["target_path"]+"/"+pkgset+"/All")
- print "Digesting files in the pkgset....."
+ msg("Digesting files in the pkgset.....")
digests=glob.glob(destdir+'/*.DIGESTS')
for i in digests:
if os.path.exists(i):
catalyst.hash.gen_digest_file(catalyst.util.normpath(destdir+"/"+i), self.settings)
else:
destdir=catalyst.util.normpath(self.settings["target_path"]+"/"+pkgset)
- print "Digesting files in the srcset....."
+ msg("Digesting files in the srcset.....")
digests=glob.glob(destdir+'/*.DIGESTS')
for i in digests:
from generic_stage import *
import catalyst.util
from catalyst.spawn import cmd
+from catalyst.output import *
class livecd_stage1_target(generic_stage_target):
def __init__(self,spec,addlargs):
def set_target_path(self):
self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"])
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
if os.path.exists(self.settings["target_path"]):
import catalyst
from catalyst.error import *
from catalyst.spawn import cmd
+from catalyst.output import *
class livecd_stage2_target(generic_stage_target):
def __init__(self,spec,addlargs):
def set_target_path(self):
self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
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
if os.path.isdir(self.settings["target_path"]):
if self.check_autoresume():
if os.path.isdir(self.settings["source_path"]) and \
self.check_autoresume("unpack"):
- print "Resume point detected, skipping unpack operation..."
+ msg("Resume point detected, skipping unpack operation...")
unpack=False
elif "source_path_hash" in self.settings:
if self.settings["source_path_hash"] != clst_unpack_hash:
if unpack:
self.mount_safety_check()
if invalid_snapshot:
- print "No Valid Resume point detected, cleaning up ..."
+ msg("No Valid Resume point detected, cleaning up...")
#os.remove(self.settings["autoresume_path"]+"dir_setup")
self.clear_autoresume()
self.clear_chroot()
if not display_msg:
raise CatalystError,"Could not find appropriate source. Please check the 'source_subpath' setting in the spec file."
- print display_msg
+ msg(display_msg)
cmd(unpack_cmd,error_msg,env=self.env)
if "source_path_hash" in self.settings:
import catalyst.util
from catalyst.error import *
from catalyst.spawn import cmd
+from catalyst.output import *
class netboot_target(generic_stage_target):
def __init__(self,spec,addlargs):
self.settings["target_path"]=catalyst.util.normpath(self.settings["storedir"]+"/builds/"+\
self.settings["target_subpath"]+"/")
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
if os.path.isfile(self.settings["target_path"]):
# check for autoresume point
if self.check_autoresume("copy_files_to_image"):
- print "Resume point detected, skipping target path setup operation..."
+ msg("Resume point detected, skipping target path setup operation...")
else:
if "netboot/packages" in self.settings:
if type(self.settings["netboot/packages"]) == types.StringType:
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 "netboot/overlay" in self.settings:
for x in self.settings["netboot/overlay"]:
try:
cmd("/bin/bash "+self.settings["controller_file"]+\
" final",env=self.env)
- print ">>> Netboot Build Finished!"
+ msg(">>> Netboot Build Finished!")
except CatalystError:
self.unbind()
raise CatalystError,"Failed to move kernel images!"
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 "netboot: removing " + x
+ msg("netboot: removing " + x)
os.system("rm -rf " + self.settings["chroot_path"] + self.settings["merge_path"] + x)
def empty(self):
if self.check_autoresume("empty"):
- print "Resume point detected, skipping empty operation..."
+ msg("Resume point detected, skipping empty operation...")
else:
if "netboot/empty" in self.settings:
if type(self.settings["netboot/empty"])==types.StringType:
for x in self.settings["netboot/empty"]:
myemp=self.settings["chroot_path"] + self.settings["merge_path"] + 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
mystat=os.stat(myemp)
from generic_stage import *
import catalyst
from catalyst.spawn import cmd
+from catalyst.output import *
class snapshot_target(generic_target):
def __init__(self,myspec,addlargs):
self.purge()
self.setup()
- print "Creating Portage tree snapshot "+self.settings["version_stamp"]+\
- " from "+self.settings["portdir"]+"..."
+ msg("Creating Portage tree snapshot " + self.settings["version_stamp"] + \
+ " from " + self.settings["portdir"] + "...")
mytmp=self.settings["tmp_path"]
if not os.path.exists(mytmp):
cmd("rsync -a --delete --exclude /packages/ --exclude /distfiles/ --exclude /local/ --exclude CVS/ --exclude .svn --filter=H_**/files/digest-* "+\
self.settings["portdir"]+"/ "+mytmp+"/portage/","Snapshot failure",env=self.env)
- print "Compressing Portage snapshot tarball..."
+ msg("Compressing Portage snapshot tarball...")
cmd("tar cjf "+self.settings["snapshot_path"]+" -C "+mytmp+" portage",\
"Snapshot creation failure",env=self.env)
catalyst.hash.gen_digest_file(self.settings["snapshot_path"], self.settings)
self.cleanup()
- print "snapshot: complete!"
+ msg("snapshot: complete!")
def kill_chroot_pids(self):
pass
def cleanup(self):
- print "Cleaning up..."
+ msg("Cleaning up...")
def purge(self):
myemp=self.settings["tmp_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
"""
from generic_stage import *
-import catalyst.util
+import catalyst
+from catalyst.output import *
class stage1_target(generic_stage_target):
def __init__(self,spec,addlargs):
def set_stage_path(self):
self.settings["stage_path"]=catalyst.util.normpath(self.settings["chroot_path"]+self.settings["root_path"])
- print "stage1 stage path is "+self.settings["stage_path"]
+ msg("stage1 stage path is " + self.settings["stage_path"])
def set_root_path(self):
# sets the root path, relative to 'chroot_path', of the stage1 root
self.settings["root_path"]=catalyst.util.normpath("/tmp/stage1root")
- print "stage1 root path is "+self.settings["root_path"]
+ msg("stage1 root path is " + self.settings["root_path"])
def set_cleanables(self):
generic_stage_target.set_cleanables(self)
def set_portage_overlay(self):
generic_stage_target.set_portage_overlay(self)
if "portage_overlay" in self.settings:
- print "\nWARNING !!!!!"
- print "\tUsing an portage overlay for earlier stages could cause build issues."
- print "\tIf you break it, you buy it. Don't complain to us about it."
- print "\tDont say we did not warn you\n"
+ msg()
+ msg("WARNING !!!!!")
+ msg("\tUsing an portage overlay for earlier stages could cause build issues.")
+ msg("\tIf you break it, you buy it. Don't complain to us about it.")
+ msg("\tDont say we did not warn you")
+ msg()
def base_dirs(self):
if os.uname()[0] == "FreeBSD":
proc_keepfile.write('')
proc_keepfile.close()
except IOError:
- print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
+ msg("!!! Failed to create %s" % (self.settings["stage_path"] + "/dev/.keep"))
if not os.path.isfile(self.settings["stage_path"]+"/dev/.keep"):
try:
dev_keepfile = open(self.settings["stage_path"]+"/dev/.keep","w")
dev_keepfile.write('')
dev_keepfile.close()
except IOError:
- print "!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep")
+ msg("!!! Failed to create %s" % (self.settings["stage_path"]+"/dev/.keep"))
else:
pass
from generic_stage import *
import catalyst
+from catalyst.output import *
class stage2_target(generic_stage_target):
def __init__(self,spec,addlargs):
# XXX: Is this even necessary if the previous check passes?
self.settings["source_path_hash"]=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 of seedcache in the options of catalyst.conf"
- print "\tthe source path will 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 of seedcache in the options of catalyst.conf")
+ msg("\tthe source path will then be " + catalyst.util.normpath(self.settings["storedir"] + "/builds/" + self.settings["source_subpath"] + ".tar.bz2\n"))
# XXX: How do these override_foo() functions differ from the ones in
# generic_stage_target and why aren't they in stage3_target?
def set_portage_overlay(self):
generic_stage_target.set_portage_overlay(self)
if "portage_overlay" in self.settings:
- print "\nWARNING !!!!!"
- print "\tUsing an portage overlay for earlier stages could cause build issues."
- print "\tIf you break it, you buy it. Don't complain to us about it."
- print "\tDont say we did not warn you\n"
+ msg()
+ msg("WARNING !!!!!")
+ msg("\tUsing an portage overlay for earlier stages could cause build issues.")
+ msg("\tIf you break it, you buy it. Don't complain to us about it.")
+ msg("\tDont say we did not warn you")
+ msg()
__target_map = {"stage2":stage2_target}
def set_portage_overlay(self):
generic_stage_target.set_portage_overlay(self)
if "portage_overlay" in self.settings:
- print "\nWARNING !!!!!"
- print "\tUsing an overlay for earlier stages could cause build issues."
- print "\tIf you break it, you buy it. Don't complain to us about it."
- print "\tDont say we did not warn you\n"
+ msg()
+ msg("WARNING !!!!!")
+ msg("\tUsing an overlay for earlier stages could cause build issues.")
+ msg("\tIf you break it, you buy it. Don't complain to us about it.")
+ msg("\tDont say we did not warn you")
+ msg()
def set_cleanables(self):
generic_stage_target.set_cleanables(self)