From: Brian Dolbec Date: Sun, 20 Jan 2013 21:50:23 +0000 (-0800) Subject: Update module loading for the new python structure, rename snapshot_target to snapshot X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8b785666a8d01af495f4bdb7d3f79423d7bc680b;p=catalyst.git Update module loading for the new python structure, rename snapshot_target to snapshot --- diff --git a/catalyst/defaults.py b/catalyst/defaults.py index f7c7f7e8..0226c66e 100644 --- a/catalyst/defaults.py +++ b/catalyst/defaults.py @@ -1,15 +1,5 @@ -# these should never be touched -required_build_targets = ["generic_stage_target"] - -# new build types should be added here -valid_build_targets = ["stage1_target", "stage2_target", "stage3_target", - "stage4_target", "grp_target", "livecd_stage1_target", "livecd_stage2_target", - "embedded_target", "tinderbox_target", "snapshot_target", "netboot_target", - "netboot2_target" - ] - required_config_file_values = ["storedir", "sharedir", "distdir", "portdir"] valid_config_file_values = required_config_file_values[:] diff --git a/catalyst/main.py b/catalyst/main.py index 545244bb..bd3f57fa 100755 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -9,22 +9,17 @@ import os import sys -import imp import getopt import os.path __selfpath__ = os.path.abspath(os.path.dirname(__file__)) -sys.path.append(__selfpath__ + "/modules") import catalyst.config import catalyst.util from catalyst.lock import LockInUse from catalyst.support import CatalystError, find_binary -from catalyst.defaults import (required_build_targets, valid_build_targets, - hash_definitions, confdefaults, option_messages - ) - +from catalyst.defaults import hash_definitions, confdefaults, option_messages from hash_utils import HashMap from defaults import contents_definitions from contents import ContentsMap @@ -139,55 +134,35 @@ def parse_config(myconfig): print "Envscript support enabled." -def import_modules(): - # import catalyst's own modules (i.e. catalyst_support and the arch modules) - targetmap={} - +def import_module(target): + """ + import catalyst's own modules + (i.e. targets and the arch modules) + """ try: - module_dir = __selfpath__ + "/targets/" - for x in required_build_targets: - try: - fh = open(module_dir + x + ".py") - module = imp.load_module(x, fh, "targets/" + x + ".py", - (".py", "r", imp.PY_SOURCE)) - fh.close() - - except IOError: - raise CatalystError("Can't find " + x + ".py plugin in " + - module_dir, print_traceback=True) - for x in valid_build_targets: - try: - fh = open(module_dir + x + ".py") - module = imp.load_module(x, fh, "targets/" + x + ".py", - (".py", "r", imp.PY_SOURCE)) - module.register(targetmap) - fh.close() - - except IOError: - raise CatalystError("Can't find " + x + ".py plugin in " + - module_dir, print_traceback=True) - + mod_name = "catalyst.targets." + target + module = __import__(mod_name, [],[], ["not empty"]) except ImportError as e: - print "!!! catalyst: Python modules not found in "+\ - module_dir + "; exiting." - print e + print "!!! catalyst: Python module import error: %s " % target + \ + "in catalyst/targets/ ... exiting." + print "ERROR was: ", e sys.exit(1) + return module - return targetmap -def build_target(addlargs, targetmap): +def build_target(addlargs): try: - if addlargs["target"] not in targetmap: - raise CatalystError( - "Target \"%s\" not available." % addlargs["target"], - print_traceback=True) - - mytarget=targetmap[addlargs["target"]](conf_values, addlargs) - - mytarget.run() + module = import_module(addlargs["target"]) + target = getattr(module, addlargs["target"])(conf_values, addlargs) + except AttributeError: + raise CatalystError( + "Target \"%s\" not available." % addlargs["target"], + print_traceback=True) + try: + target.run() except: - print "Python traceback output follows:" + print "Target run() exception: Python traceback output follows:" catalyst.util.print_traceback() print print "!!! catalyst: Error encountered during run of target " + \ @@ -195,7 +170,6 @@ def build_target(addlargs, targetmap): sys.exit(1) def main(): - targetmap={} version() if os.getuid() != 0: @@ -341,9 +315,6 @@ def main(): print "Catalyst aborting...." sys.exit(2) - # import the rest of the catalyst modules - targetmap=import_modules() - addlargs={} if myspecfile: @@ -364,7 +335,7 @@ def main(): # everything is setup, so the build is a go try: - build_target(addlargs, targetmap) + build_target(addlargs) except CatalystError: print diff --git a/catalyst/targets/embedded_target.py b/catalyst/targets/embedded_target.py index 528d5457..aee0f00f 100644 --- a/catalyst/targets/embedded_target.py +++ b/catalyst/targets/embedded_target.py @@ -45,7 +45,3 @@ class embedded_target(StageBase): def set_root_path(self): self.settings["root_path"]=normpath("/tmp/mergeroot") print "embedded root path is "+self.settings["root_path"] - -def register(foo): - foo.update({"embedded":embedded_target}) - return foo diff --git a/catalyst/targets/grp_target.py b/catalyst/targets/grp_target.py index 02279c3f..b0eff7bf 100644 --- a/catalyst/targets/grp_target.py +++ b/catalyst/targets/grp_target.py @@ -119,7 +119,3 @@ class grp_target(StageBase): "config_profile_link","setup_confdir","portage_overlay","bind","chroot_setup",\ "setup_environment","run_local","unbind",\ "generate_digests","clear_autoresume"] - -def register(foo): - foo.update({"grp":grp_target}) - return foo diff --git a/catalyst/targets/livecd_stage1_target.py b/catalyst/targets/livecd_stage1_target.py index 30ba6054..19a03e9c 100644 --- a/catalyst/targets/livecd_stage1_target.py +++ b/catalyst/targets/livecd_stage1_target.py @@ -74,7 +74,3 @@ class livecd_stage1_target(StageBase): self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"])) else: StageBase.set_pkgcache_path(self) - -def register(foo): - foo.update({"livecd-stage1":livecd_stage1_target}) - return foo diff --git a/catalyst/targets/livecd_stage2_target.py b/catalyst/targets/livecd_stage2_target.py index 5b2b4953..c2e9db83 100644 --- a/catalyst/targets/livecd_stage2_target.py +++ b/catalyst/targets/livecd_stage2_target.py @@ -154,7 +154,3 @@ class livecd_stage2_target(StageBase): "unbind","remove","empty","target_setup",\ "setup_overlay","create_iso"] self.settings["action_sequence"].append("clear_autoresume") - -def register(foo): - foo.update({"livecd-stage2":livecd_stage2_target}) - return foo diff --git a/catalyst/targets/netboot2_target.py b/catalyst/targets/netboot2_target.py index ff7c0a97..aa35c8ce 100644 --- a/catalyst/targets/netboot2_target.py +++ b/catalyst/targets/netboot2_target.py @@ -170,7 +170,3 @@ class netboot2_target(StageBase): "setup_environment","build_packages","root_overlay",\ "copy_files_to_image","setup_overlay","build_kernel","move_kernels",\ "remove","empty","unbind","clean","clear_autoresume"] - -def register(foo): - foo.update({"netboot2":netboot2_target}) - return foo diff --git a/catalyst/targets/netboot_target.py b/catalyst/targets/netboot_target.py index eae35a96..92352575 100644 --- a/catalyst/targets/netboot_target.py +++ b/catalyst/targets/netboot_target.py @@ -132,7 +132,3 @@ class netboot_target(StageBase): "setup_environment","build_packages","build_busybox",\ "build_kernel","copy_files_to_image",\ "clean","create_netboot_files","unbind","clear_autoresume"] - -def register(foo): - foo.update({"netboot":netboot_target}) - return foo diff --git a/catalyst/targets/snapshot_target.py b/catalyst/targets/snapshot.py similarity index 95% rename from catalyst/targets/snapshot_target.py rename to catalyst/targets/snapshot.py index 337ff1d9..6c2396e7 100644 --- a/catalyst/targets/snapshot_target.py +++ b/catalyst/targets/snapshot.py @@ -11,7 +11,7 @@ from catalyst.support import normpath, cmd from catalyst.base.targetbase import TargetBase from catalyst.base.genbase import GenBase -class snapshot_target(TargetBase, GenBase): +class snapshot(TargetBase, GenBase): """ Builder class for snapshots. """ @@ -91,7 +91,3 @@ class snapshot_target(TargetBase, GenBase): os.makedirs(myemp,0755) os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) os.chmod(myemp,mystat[ST_MODE]) - -def register(foo): - foo.update({"snapshot":snapshot_target}) - return foo diff --git a/catalyst/targets/stage1_target.py b/catalyst/targets/stage1_target.py index d70c5ec1..6e522470 100644 --- a/catalyst/targets/stage1_target.py +++ b/catalyst/targets/stage1_target.py @@ -95,7 +95,3 @@ class stage1_target(StageBase): # alter the mount mappings to bind mount proc onto it self.mounts.append("/tmp/stage1root/proc") self.mountmap["/tmp/stage1root/proc"]="/proc" - -def register(foo): - foo.update({"stage1":stage1_target}) - return foo diff --git a/catalyst/targets/stage2_target.py b/catalyst/targets/stage2_target.py index 490bca71..4ecb4655 100644 --- a/catalyst/targets/stage2_target.py +++ b/catalyst/targets/stage2_target.py @@ -63,7 +63,3 @@ class stage2_target(StageBase): 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" - -def register(foo): - foo.update({"stage2":stage2_target}) - return foo diff --git a/catalyst/targets/stage3_target.py b/catalyst/targets/stage3_target.py index be73a6c3..ae70df1b 100644 --- a/catalyst/targets/stage3_target.py +++ b/catalyst/targets/stage3_target.py @@ -26,7 +26,3 @@ class stage3_target(StageBase): def set_cleanables(self): StageBase.set_cleanables(self) - -def register(foo): - foo.update({"stage3":stage3_target}) - return foo diff --git a/catalyst/targets/stage4_target.py b/catalyst/targets/stage4_target.py index bbdb048c..d3148018 100644 --- a/catalyst/targets/stage4_target.py +++ b/catalyst/targets/stage4_target.py @@ -37,8 +37,3 @@ class stage4_target(StageBase): if "fetch" not in self.settings['options']: self.settings["action_sequence"].append("capture") self.settings["action_sequence"].append("clear_autoresume") - -def register(foo): - foo.update({"stage4":stage4_target}) - return foo - diff --git a/catalyst/targets/tinderbox_target.py b/catalyst/targets/tinderbox_target.py index fb21f3a7..f665bec2 100644 --- a/catalyst/targets/tinderbox_target.py +++ b/catalyst/targets/tinderbox_target.py @@ -48,7 +48,3 @@ class tinderbox_target(StageBase): "config_profile_link","setup_confdir","bind","chroot_setup",\ "setup_environment","run_local","preclean","unbind","clean",\ "clear_autoresume"] - -def register(foo): - foo.update({"tinderbox":tinderbox_target}) - return foo