From 29924cbd7e2df4c481df4d62de1e5a9989358ae3 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Mon, 12 Jan 2009 09:33:21 -0600 Subject: [PATCH] More replacements of the print statement with msg() --- ChangeLog | 4 ++ catalyst | 87 +++++++++++++++++++------------------- modules/catalyst/output.py | 7 ++- modules/catalyst/util.py | 14 +++--- 4 files changed, 61 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4671358..df9fce24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 12 Jan 2009; Andrew Gaffney catalyst, + modules/catalyst/output.py, modules/catalyst/util.py: + More replacements of the print statement with msg() + 12 Jan 2009; Andrew Gaffney modules/catalyst/target/generic_stage.py: Replace all instances of print with catalyst.output.msg() in diff --git a/catalyst b/catalyst index 1cbb9f5d..af555995 100755 --- a/catalyst +++ b/catalyst @@ -48,10 +48,10 @@ def usage(): print "catalyst -f stage1-specfile.spec" def show_version(): - print "Catalyst, version "+__version__ - print "Copyright 2003-2008 Gentoo Foundation" - print "Copyright 2008 various authors" - print "Distributed under the GNU General Public License version 2.1\n" + msg("Catalyst, version " + __version__) + msg("Copyright 2003-2008 Gentoo Foundation") + msg("Copyright 2008 various authors") + msg("Distributed under the GNU General Public License version 2.1") def parse_config(myconfig): # search a couple of different areas for the main config file @@ -71,14 +71,14 @@ def parse_config(myconfig): # first, try the one passed (presumably from the cmdline) if myconfig: if os.path.exists(myconfig): - print "Using command line specified Catalyst configuration file, " + myconfig + msg("Using command line specified Catalyst configuration file, " + myconfig) config_file = myconfig else: die("specified configuration file " + myconfig + " does not exist") # next, try the default location elif os.path.exists("/etc/catalyst/catalyst.conf"): - print "Using default Catalyst configuration file, /etc/catalyst/catalyst.conf" + msg("Using default Catalyst configuration file, /etc/catalyst/catalyst.conf") config_file="/etc/catalyst/catalyst.conf" # can't find a config file (we are screwed), so bail out @@ -87,7 +87,7 @@ def parse_config(myconfig): # Load the default config values into myconf for x in confdefaults: - print "Setting " + x + " to default value \"" + confdefaults[x] + "\"" + msg("Setting " + x + " to default value '" + confdefaults[x] + "'") myconf[x] = confdefaults[x] # now, try and parse the config file "config_file" @@ -101,10 +101,10 @@ def parse_config(myconfig): # now, load up the values into conf_values so that we can use them for x in confdefaults.keys(): if x in myconf: - print "Setting",x,"to config file value \""+myconf[x]+"\"" + msg("Setting " + x + " to config file value '" + myconf[x] + "'") conf_values[x]=myconf[x] else: - print "Setting",x,"to default value \""+confdefaults[x]+"\"" + msg("Setting " + x + " to default value '"+confdefaults[x] + "'") conf_values[x]=confdefaults[x] options = ( @@ -128,7 +128,7 @@ def parse_config(myconfig): # parse out the rest of the options from the config file for x in options: if x[0] in split_options: - print x[2] + msg(x[2]) conf_values[x[1]] = "1" if "digests" in myconf: @@ -137,7 +137,7 @@ def parse_config(myconfig): conf_values["contents"]=myconf["contents"] if "envscript" in myconf: - print "Envscript support enabled." + msg("Envscript support enabled.") conf_values["ENVSCRIPT"]=myconf["envscript"] def build_target(addlargs, targetmap): @@ -159,38 +159,38 @@ def verify_digest_and_hash_functions(): if "digests" in conf_values: for i in conf_values["digests"].split(): if not i in hash_map: - print - print i+" is not a valid digest entry" - print "Valid digest entries:" - print hash_map.keys() - print - print "Catalyst aborting...." + msg() + msg(i + " is not a valid digest entry") + msg("Valid digest entries:") + msg("\n".join(hash_map.keys())) + msg() + msg("Catalyst aborting....") sys.exit(2) if catalyst.util.find_binary(hash_map[i][1]) == None: - print - print "digest="+i - print "\tThe "+hash_map[i][1]+\ - " binary was not found. It needs to be in your system path" - print - print "Catalyst aborting...." + msg() + msg("digest=" + i) + msg("\tThe " + hash_map[i][1] + \ + " binary was not found. It needs to be in your system path") + msg() + msg("Catalyst aborting....") sys.exit(2) if "hash_function" in conf_values: if not conf_values["hash_function"] in hash_map: - print - print conf_values["hash_function"]+" is not a valid hash_function entry" - print "Valid hash_function entries:" - print hash_map.keys() - print - print "Catalyst aborting...." + msg() + msg(conf_values["hash_function"] + " is not a valid hash_function entry") + msg("Valid hash_function entries:") + msg("\n".join(hash_map.keys())) + msg() + msg("Catalyst aborting....") sys.exit(2) if catalyst.util.find_binary(hash_map[conf_values["hash_function"]][1]) == None: - print - print "hash_function="+conf_values["hash_function"] - print "\tThe "+hash_map[conf_values["hash_function"]][1]+\ - " binary was not found. It needs to be in your system path" - print - print "Catalyst aborting...." + msg() + msg("hash_function=" + conf_values["hash_function"]) + msg("\tThe " + hash_map[conf_values["hash_function"]][1] + \ + " binary was not found. It needs to be in your system path") + msg() + msg("Catalyst aborting....") sys.exit(2) if __name__ == "__main__": @@ -232,7 +232,7 @@ if __name__ == "__main__": sys.exit(1) if o in ("-V", "--version"): - print "Catalyst version "+__version__ + show_version() sys.exit(1) if o in ("-d", "--debug"): @@ -311,22 +311,23 @@ if __name__ == "__main__": build_target(addlargs, targetmap) except CatalystError: - print - print "Catalyst aborting...." + msg() + msg("Catalyst aborting....") sys.exit(2) except KeyboardInterrupt: - print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )" - print - print "Catalyst aborting...." + msg() + msg("Catalyst build aborted due to user interrupt ( Ctrl-C )") + msg() + msg("Catalyst aborting....") sys.exit(2) except LockInUse: - print "Catalyst aborting...." + msg("Catalyst aborting....") sys.exit(2) except: - print "Catalyst aborting...." + msg("Catalyst aborting....") raise sys.exit(2) diff --git a/modules/catalyst/output.py b/modules/catalyst/output.py index e3030eb4..ec6adb7a 100644 --- a/modules/catalyst/output.py +++ b/modules/catalyst/output.py @@ -6,9 +6,12 @@ import sys verbosity = 1 -def msg(mymsg, verblevel=1): +def msg(mymsg, verblevel=1, newline=True): if verbosity >= verblevel: - print mymsg + if newline: + print mymsg + else: + print mymsg, def warn(msg): print "!!! catalyst: " + msg diff --git a/modules/catalyst/util.py b/modules/catalyst/util.py index 4b95bc85..ccc89822 100644 --- a/modules/catalyst/util.py +++ b/modules/catalyst/util.py @@ -5,6 +5,7 @@ Collection of utility functions for catalyst import sys, traceback, os, os.path, re, time import catalyst from catalyst.error import * +from catalyst.output import * def capture_traceback(): etype, value, tb = sys.exc_info() @@ -13,7 +14,7 @@ def capture_traceback(): def print_traceback(): for x in capture_traceback(): - print x + msg(x) def load_module(name): try: @@ -107,16 +108,17 @@ def touch(myfile): def countdown(secs=5, doing="Starting"): if secs: - print ">>> Waiting " + secs + " seconds before starting..." - print ">>> (Control-C to abort)..." - print doing + " in: ", + msg(">>> Waiting " + secs + " seconds before starting...") + msg(">>> (Control-C to abort)...") + msg(doing + " in: ", newline=False) ticks = range(secs) ticks.reverse() for sec in ticks: - sys.stdout.write(str(sec+1) + " ") +# sys.stdout.write(str(sec+1) + " ") + msg(str(sec+1), newline=False) sys.stdout.flush() time.sleep(1) - print + msg() def file_locate(settings, filelist, expand=True): #if expand is True, non-absolute paths will be accepted and -- 2.26.2