From 1f834cb5d294d57e250e95faaad8773e78de63ce Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Mon, 12 Jan 2009 09:46:40 -0600 Subject: [PATCH] Replace more instances of print with msg() --- ChangeLog | 11 +++++++++++ modules/catalyst/config.py | 3 ++- modules/catalyst/error.py | 18 +++++++++--------- modules/catalyst/hash.py | 8 ++++---- modules/catalyst/output.py | 10 +++++----- modules/catalyst/spawn.py | 7 ++++--- modules/catalyst/target/embedded.py | 5 +++-- modules/catalyst/target/grp.py | 7 ++++--- modules/catalyst/target/livecd_stage1.py | 3 ++- modules/catalyst/target/livecd_stage2.py | 9 +++++---- modules/catalyst/target/netboot.py | 19 ++++++++++--------- modules/catalyst/target/snapshot.py | 13 +++++++------ modules/catalyst/target/stage1.py | 21 ++++++++++++--------- modules/catalyst/target/stage2.py | 17 ++++++++++------- modules/catalyst/target/stage3.py | 10 ++++++---- 15 files changed, 94 insertions(+), 67 deletions(-) diff --git a/ChangeLog b/ChangeLog index df9fce24..a14cf88b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,17 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 12 Jan 2009; Andrew Gaffney + 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 catalyst, modules/catalyst/output.py, modules/catalyst/util.py: More replacements of the print statement with msg() diff --git a/modules/catalyst/config.py b/modules/catalyst/config.py index 53c2b920..4fc62911 100644 --- a/modules/catalyst/config.py +++ b/modules/catalyst/config.py @@ -1,5 +1,6 @@ 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[:] @@ -119,7 +120,7 @@ class ParserBase: 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 diff --git a/modules/catalyst/error.py b/modules/catalyst/error.py index 66ab3e0c..ef028615 100644 --- a/modules/catalyst/error.py +++ b/modules/catalyst/error.py @@ -3,18 +3,18 @@ This module contains the custom exception classes used by catalyst """ 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): @@ -23,7 +23,7 @@ class LockInUse(Exception): #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() diff --git a/modules/catalyst/hash.py b/modules/catalyst/hash.py index 5a8b879a..43ee89ed 100644 --- a/modules/catalyst/hash.py +++ b/modules/catalyst/hash.py @@ -4,7 +4,7 @@ This module contains functions for generating the CONTENTS and hash files 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"): @@ -80,7 +80,7 @@ def calc_contents(file, cmd, verbose): 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 @@ -111,7 +111,7 @@ def calc_hash(file, cmd, cmd_args, id_string="MD5", verbose=False): 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): @@ -123,7 +123,7 @@ 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 diff --git a/modules/catalyst/output.py b/modules/catalyst/output.py index ec6adb7a..7d6e802c 100644 --- a/modules/catalyst/output.py +++ b/modules/catalyst/output.py @@ -6,17 +6,17 @@ import sys 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) diff --git a/modules/catalyst/spawn.py b/modules/catalyst/spawn.py index c1734682..cfd1c037 100644 --- a/modules/catalyst/spawn.py +++ b/modules/catalyst/spawn.py @@ -5,6 +5,7 @@ This module contains all the functions related to spawning external commands import sys, os, types, signal import catalyst.util from catalyst.error import * +from catalyst.output import * BASH_BINARY = "/bin/bash" @@ -243,7 +244,7 @@ def spawn(mycommand,env={},raw_exit_code=False,opt_name=None,fd_pipes=None,retur 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. @@ -252,7 +253,7 @@ def spawn(mycommand,env={},raw_exit_code=False,opt_name=None,fd_pipes=None,retur 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) @@ -262,7 +263,7 @@ def spawn(mycommand,env={},raw_exit_code=False,opt_name=None,fd_pipes=None,retur 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 diff --git a/modules/catalyst/target/embedded.py b/modules/catalyst/target/embedded.py index fbc8e8cf..68edf761 100644 --- a/modules/catalyst/target/embedded.py +++ b/modules/catalyst/target/embedded.py @@ -11,6 +11,7 @@ ROOT=/tmp/submerge emerge --blahblah foo bar from generic_stage import * import catalyst.util +from catalyst.output import * class embedded_target(generic_stage_target): @@ -35,10 +36,10 @@ 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} diff --git a/modules/catalyst/target/grp.py b/modules/catalyst/target/grp.py index 263ce39f..931db9f8 100644 --- a/modules/catalyst/target/grp.py +++ b/modules/catalyst/target/grp.py @@ -8,6 +8,7 @@ from generic_stage import * 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): @@ -36,7 +37,7 @@ class grp_target(generic_stage_target): 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"]): @@ -74,7 +75,7 @@ class grp_target(generic_stage_target): 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): @@ -89,7 +90,7 @@ class grp_target(generic_stage_target): 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: diff --git a/modules/catalyst/target/livecd_stage1.py b/modules/catalyst/target/livecd_stage1.py index a0162281..841fb642 100644 --- a/modules/catalyst/target/livecd_stage1.py +++ b/modules/catalyst/target/livecd_stage1.py @@ -6,6 +6,7 @@ Builder class for LiveCD stage1. 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): @@ -24,7 +25,7 @@ class livecd_stage1_target(generic_stage_target): 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"]): diff --git a/modules/catalyst/target/livecd_stage2.py b/modules/catalyst/target/livecd_stage2.py index f9cad328..bd8931db 100644 --- a/modules/catalyst/target/livecd_stage2.py +++ b/modules/catalyst/target/livecd_stage2.py @@ -8,6 +8,7 @@ from generic_stage import * 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): @@ -46,7 +47,7 @@ class livecd_stage2_target(generic_stage_target): 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"]): @@ -86,7 +87,7 @@ class livecd_stage2_target(generic_stage_target): 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: @@ -95,7 +96,7 @@ class livecd_stage2_target(generic_stage_target): 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() @@ -114,7 +115,7 @@ class livecd_stage2_target(generic_stage_target): 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: diff --git a/modules/catalyst/target/netboot.py b/modules/catalyst/target/netboot.py index 140a6249..ebfccc43 100644 --- a/modules/catalyst/target/netboot.py +++ b/modules/catalyst/target/netboot.py @@ -8,6 +8,7 @@ from generic_stage import * 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): @@ -45,7 +46,7 @@ class netboot_target(generic_stage_target): 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"]): @@ -62,7 +63,7 @@ class netboot_target(generic_stage_target): # 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: @@ -94,7 +95,7 @@ class netboot_target(generic_stage_target): 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"]: @@ -110,25 +111,25 @@ class netboot_target(generic_stage_target): 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: @@ -136,9 +137,9 @@ class netboot_target(generic_stage_target): 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) diff --git a/modules/catalyst/target/snapshot.py b/modules/catalyst/target/snapshot.py index 1d7d3a09..e88ad8ca 100644 --- a/modules/catalyst/target/snapshot.py +++ b/modules/catalyst/target/snapshot.py @@ -7,6 +7,7 @@ import os 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): @@ -38,8 +39,8 @@ class snapshot_target(generic_target): 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): @@ -48,7 +49,7 @@ class snapshot_target(generic_target): 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) @@ -56,18 +57,18 @@ class snapshot_target(generic_target): 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 diff --git a/modules/catalyst/target/stage1.py b/modules/catalyst/target/stage1.py index 1b8eddca..c0b9fb0b 100644 --- a/modules/catalyst/target/stage1.py +++ b/modules/catalyst/target/stage1.py @@ -4,7 +4,8 @@ Builder class for a stage1 installation tarball build. """ from generic_stage import * -import catalyst.util +import catalyst +from catalyst.output import * class stage1_target(generic_stage_target): def __init__(self,spec,addlargs): @@ -14,12 +15,12 @@ class stage1_target(generic_stage_target): 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) @@ -52,10 +53,12 @@ class stage1_target(generic_stage_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() def base_dirs(self): if os.uname()[0] == "FreeBSD": @@ -72,14 +75,14 @@ class stage1_target(generic_stage_target): 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 diff --git a/modules/catalyst/target/stage2.py b/modules/catalyst/target/stage2.py index b2f6507b..68e8c8df 100644 --- a/modules/catalyst/target/stage2.py +++ b/modules/catalyst/target/stage2.py @@ -5,6 +5,7 @@ Builder class for a stage2 installation tarball build. from generic_stage import * import catalyst +from catalyst.output import * class stage2_target(generic_stage_target): def __init__(self,spec,addlargs): @@ -22,10 +23,10 @@ class stage2_target(generic_stage_target): # 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? @@ -53,9 +54,11 @@ class stage2_target(generic_stage_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} diff --git a/modules/catalyst/target/stage3.py b/modules/catalyst/target/stage3.py index 54342406..6ae7e100 100644 --- a/modules/catalyst/target/stage3.py +++ b/modules/catalyst/target/stage3.py @@ -14,10 +14,12 @@ class stage3_target(generic_stage_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) -- 2.26.2