commit:     895009885a1c65efbad037ce14173ca0742482f4
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 20 21:50:23 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Sep 11 03:05:37 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=89500988

[2 of 3] Update module loading for the new python structure

Rename snapshot_target to snapshot

---
 catalyst/main.py                                   | 75 ++++++++--------------
 catalyst/targets/embedded_target.py                |  4 --
 catalyst/targets/grp_target.py                     |  4 --
 catalyst/targets/livecd_stage1_target.py           |  4 --
 catalyst/targets/livecd_stage2_target.py           |  4 --
 catalyst/targets/netboot2_target.py                |  4 --
 catalyst/targets/netboot_target.py                 |  4 --
 .../targets/{snapshot_target.py => snapshot.py}    |  6 +-
 catalyst/targets/stage1_target.py                  |  4 --
 catalyst/targets/stage2_target.py                  |  4 --
 catalyst/targets/stage3_target.py                  |  4 --
 catalyst/targets/stage4_target.py                  |  5 --
 catalyst/targets/tinderbox_target.py               |  4 --
 13 files changed, 27 insertions(+), 99 deletions(-)

diff --git a/catalyst/main.py b/catalyst/main.py
index 15664de..1446cf9 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -16,21 +16,20 @@ import os.path
 
 __selfpath__ = os.path.abspath(os.path.dirname(__file__))
 
-sys.path.append(__selfpath__ + "/modules")
 
 from . import __version__
 import catalyst.config
 import catalyst.util
+from catalyst.contents import ContentsMap, CONTENTS_DEFINITIONS
+from catalyst.defaults import confdefaults, option_messages
+from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
 from catalyst.lock import LockInUse
 from catalyst.support import CatalystError, find_binary
-from catalyst.defaults import (confdefaults, option_messages,
-       required_build_targets, valid_build_targets)
-from hash_utils import HashMap, HASH_DEFINITIONS
-from contents import ContentsMap, CONTENTS_DEFINITIONS
 
 
 conf_values={}
 
+
 def usage():
        print """Usage catalyst [options] [-C variable=value...] [ -s 
identifier]
  -a --clear-autoresume  clear autoresume flags
@@ -135,59 +134,40 @@ def parse_config(myconfig):
                print "Envscript support enabled."
 
 
-def import_modules():
-       # import catalyst's own modules
-       # (i.e. stage 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
-               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
-
+               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 \""+addlargs["target"]+"\" 
not available."
-
-               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 "Target run() exception:  Python traceback output 
follows:"
                catalyst.util.print_traceback()
                print "!!! catalyst: Error encountered during run of target " + 
addlargs["target"]
                sys.exit(1)
 
 def main():
-       targetmap={}
 
        version()
        if os.getuid() != 0:
@@ -341,9 +321,6 @@ def main():
                        print "Catalyst aborting...."
                        sys.exit(2)
 
-       # import the rest of the catalyst modules
-       targetmap=import_modules()
-
        addlargs={}
 
        if myspecfile:
@@ -364,7 +341,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 528d545..aee0f00 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 deba80a..e3f08a2 100644
--- a/catalyst/targets/grp_target.py
+++ b/catalyst/targets/grp_target.py
@@ -118,7 +118,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 a19f4ac..9c74253 100644
--- a/catalyst/targets/livecd_stage1_target.py
+++ b/catalyst/targets/livecd_stage1_target.py
@@ -76,7 +76,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 e7ae212..a4630e6 100644
--- a/catalyst/targets/livecd_stage2_target.py
+++ b/catalyst/targets/livecd_stage2_target.py
@@ -145,7 +145,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 987afd8..130e2b6 100644
--- a/catalyst/targets/netboot2_target.py
+++ b/catalyst/targets/netboot2_target.py
@@ -167,7 +167,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 c880289..9d92ef2 100644
--- a/catalyst/targets/netboot_target.py
+++ b/catalyst/targets/netboot_target.py
@@ -127,7 +127,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 337ff1d..6c2396e 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 0a36432..2329b58 100644
--- a/catalyst/targets/stage1_target.py
+++ b/catalyst/targets/stage1_target.py
@@ -94,7 +94,3 @@ class stage1_target(StageBase):
                self.mounts.append("stage1root/proc")
                self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc"
                self.mountmap["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 783d42e..ec6d78d 100644
--- a/catalyst/targets/stage2_target.py
+++ b/catalyst/targets/stage2_target.py
@@ -62,7 +62,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 28021b1..103242d 100644
--- a/catalyst/targets/stage3_target.py
+++ b/catalyst/targets/stage3_target.py
@@ -25,7 +25,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 0d725c7..4dbdb45 100644
--- a/catalyst/targets/stage4_target.py
+++ b/catalyst/targets/stage4_target.py
@@ -36,8 +36,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 1e245f2..0c389e6 100644
--- a/catalyst/targets/tinderbox_target.py
+++ b/catalyst/targets/tinderbox_target.py
@@ -45,7 +45,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

Reply via email to