From: Andrew Gaffney Date: Sun, 11 Jan 2009 18:20:35 +0000 (-0600) Subject: Move msg(), warn(), and die() to catalyst.output and update all references X-Git-Tag: CATALYST-2.0.10~3^2~209 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a201b6158cce59a834bebf9f218c57f9127b5a31;p=catalyst.git Move msg(), warn(), and die() to catalyst.output and update all references --- diff --git a/ChangeLog b/ChangeLog index aee3dadc..a4e20e62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,15 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 11 Jan 2009; Andrew Gaffney catalyst, + modules/catalyst/arch/__init__.py, +modules/catalyst/output.py, + modules/catalyst/support.py, modules/catalyst/target/__init__.py, + modules/catalyst/target/generic_stage.py: + Move msg(), warn(), and die() to catalyst.output and update all references + + 11 Jan 2009; Andrew Gaffney catalyst: + Load defaults into myconf before parsing config + 11 Jan 2009; Andrew Gaffney catalyst: Condense code that checks for various things in 'options' to use a loop diff --git a/catalyst b/catalyst index a9b1109a..367a91c1 100755 --- a/catalyst +++ b/catalyst @@ -15,6 +15,7 @@ import catalyst.config import catalyst.util import catalyst.target from catalyst.support import * +from catalyst.output import * __maintainer__="Chris Gianelloni " __version__="2.99" @@ -74,8 +75,7 @@ def parse_config(myconfig): print "Using command line specified Catalyst configuration file, " + myconfig config_file = myconfig else: - print "!!! catalyst: specified configuration file " + myconfig + " does not exist" - sys.exit(1) + die("specified configuration file " + myconfig + " does not exist") # next, try the default location elif os.path.exists("/etc/catalyst/catalyst.conf"): @@ -84,8 +84,7 @@ def parse_config(myconfig): # can't find a config file (we are screwed), so bail out else: - print "!!! catalyst: Could not find a suitable configuration file" - sys.exit(1) + die("Could not find a suitable configuration file") # Load the default config values into myconf for x in confdefaults: @@ -98,8 +97,7 @@ def parse_config(myconfig): myconf.update(myconfig.get_values()) except: - print "!!! catalyst: Unable to parse configuration file, "+myconfig - sys.exit(1) + die("Unable to parse configuration file, " + myconfig) # now, load up the values into conf_values so that we can use them for x in confdefaults.keys(): @@ -154,8 +152,7 @@ def build_target(addlargs, targetmap): except: catalyst.util.print_traceback() - print "!!! catalyst: Error encountered during run of target " + addlargs["target"] -# sys.exit(1) + warn("Error encountered during run of target " + addlargs["target"]) raise def verify_digest_and_hash_functions(): @@ -203,8 +200,7 @@ if __name__ == "__main__": if os.getuid() != 0: # catalyst cannot be run as a normal user due to chroots, mounts, etc - print "!!! catalyst: This script requires root privileges to operate" - sys.exit(2) + die("This script requires root privileges to operate", 2) # parse out the command line arguments try: @@ -226,7 +222,7 @@ if __name__ == "__main__": # check preconditions if len(opts) == 0: - print "!!! catalyst: please specify one of either -f or -C\n" + warn("please specify one of either -f or -C\n") usage() sys.exit(2) @@ -266,7 +262,7 @@ if __name__ == "__main__": if o in ("-s", "--snapshot"): if len(sys.argv) < 3: - print "!!! catalyst: missing snapshot identifier\n" + warn("missing snapshot identifier") usage() sys.exit(2) else: @@ -284,7 +280,7 @@ if __name__ == "__main__": conf_values["CLEAR_AUTORESUME"] = "1" if not run: - print "!!! catalyst: please specify one of either -f or -C\n" + warn("please specify one of either -f or -C") usage() sys.exit(2) @@ -306,8 +302,7 @@ if __name__ == "__main__": cmdline.parse_lines(mycmdline) addlargs.update(cmdline.get_values()) except CatalystError: - print "!!! catalyst: Could not parse commandline, exiting." - sys.exit(1) + die("Could not parse commandline, exiting.") if not "target" in addlargs: raise CatalystError, "Required value \"target\" not specified." diff --git a/modules/catalyst/arch/__init__.py b/modules/catalyst/arch/__init__.py index 1e6fa109..c934986e 100644 --- a/modules/catalyst/arch/__init__.py +++ b/modules/catalyst/arch/__init__.py @@ -5,9 +5,7 @@ Parent module of all arch modules import os import imp import catalyst.util - -# This is only until we move all the output stuff into catalyst.output -from catalyst.support import msg +from catalyst.output import warn def find_arch_modules(self): search_dir = os.path.abspath(os.path.dirname(__file__)) @@ -20,7 +18,7 @@ def get_arches(self): for x in find_arch_modules(): arch_modules[x] = catalyst.util.load_module("catalyst.arch." + x) if arch_modules[x] is None: - msg("Cannot import catalyst.arch." + x + ". This usually only " + \ + warn("Cannot import catalyst.arch." + x + ". This usually only " + \ "happens due to a syntax error, which should be reported as " \ "a bug.") return arch_modules diff --git a/modules/catalyst/output.py b/modules/catalyst/output.py new file mode 100644 index 00000000..b9dd95d5 --- /dev/null +++ b/modules/catalyst/output.py @@ -0,0 +1,15 @@ +""" +This module contains miscellaneous functions for outputting messages +""" + +def msg(mymsg, verblevel=1): + if verbosity >= verblevel: + print mymsg + +def warn(msg): + print "!!! catalyst: " + msg + +def die(msg, exitcode=1): + warn(msg) + sys.exit(exitcode) + diff --git a/modules/catalyst/support.py b/modules/catalyst/support.py index 6aecfbf2..ca97c6e0 100644 --- a/modules/catalyst/support.py +++ b/modules/catalyst/support.py @@ -1,6 +1,8 @@ import sys,string,os,types,re,signal,traceback,time +from catalyst.output import warn #import md5,sha + selinux_capable = False #userpriv_capable = (os.getuid() == 0) #fakeroot_capable = False @@ -263,14 +265,6 @@ class LockInUse(Exception): print "!!! catalyst lock file in use: "+message print -def die(msg=None): - warn(msg) - sys.exit(1) - -def warn(msg): - print "!!! catalyst: "+msg - - def find_binary(myc): """look through the environmental path for an executable file named whatever myc is""" # this sucks. badly. @@ -631,10 +625,6 @@ def read_makeconf(mymakeconffile): makeconf={} return makeconf -def msg(mymsg,verblevel=1): - if verbosity>=verblevel: - print mymsg - def pathcompare(path1,path2): # Change double slashes to slash path1 = re.sub(r"//",r"/",path1) diff --git a/modules/catalyst/target/__init__.py b/modules/catalyst/target/__init__.py index 7f8602b4..8e23b521 100644 --- a/modules/catalyst/target/__init__.py +++ b/modules/catalyst/target/__init__.py @@ -5,9 +5,7 @@ Parent module of all target modules import os import imp import catalyst.util - -# This is only until we move all the output stuff into catalyst.output -from catalyst.support import msg +from catalyst.output import warn def find_target_modules(): search_dir = os.path.abspath(os.path.dirname(__file__)) @@ -20,7 +18,7 @@ def get_targets(): for x in find_target_modules(): target_modules[x] = catalyst.util.load_module("catalyst.target." + x) if target_modules[x] is None: - msg("Cannot import catalyst.target." + x + ". This usually only " + \ + warn("Cannot import catalyst.target." + x + ". This usually only " + \ "happens due to a syntax error, which should be reported as " \ "a bug.") return target_modules diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index f4865127..143e74fe 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -10,6 +10,7 @@ from catalyst.target.generic import * from stat import * import catalyst.lock import catalyst.arch +from catalyst.output import warn class generic_stage_target(generic_target):