Initial rearrangement of the python directories
authorBrian Dolbec <dolsen@gentoo.org>
Fri, 11 Jan 2013 02:56:28 +0000 (18:56 -0800)
committerBrian Dolbec <dolsen@gentoo.org>
Sat, 22 Feb 2014 18:30:15 +0000 (10:30 -0800)
New minimal start script, moving the original catalyst script to catalyst/main.py.
Add __init__.py's to modules and arch sub-pkgs.
skip __init__.py when loading the modules.
Update the module loading paths for the new locations.
Fix catalyst_support import to new location and specify imported modules.

37 files changed:
bin/catalyst [new file with mode: 0755]
catalyst/__init__.py [moved from modules/__init__.py with 100% similarity]
catalyst/arch/__init__.py [new file with mode: 0644]
catalyst/arch/alpha.py [moved from arch/alpha.py with 100% similarity]
catalyst/arch/amd64.py [moved from arch/amd64.py with 100% similarity]
catalyst/arch/arm.py [moved from arch/arm.py with 100% similarity]
catalyst/arch/hppa.py [moved from arch/hppa.py with 100% similarity]
catalyst/arch/ia64.py [moved from arch/ia64.py with 100% similarity]
catalyst/arch/m68k.py [moved from arch/m68k.py with 100% similarity]
catalyst/arch/mips.py [moved from arch/mips.py with 100% similarity]
catalyst/arch/powerpc.py [moved from arch/powerpc.py with 100% similarity]
catalyst/arch/s390.py [moved from arch/s390.py with 100% similarity]
catalyst/arch/sh.py [moved from arch/sh.py with 100% similarity]
catalyst/arch/sparc.py [moved from arch/sparc.py with 100% similarity]
catalyst/arch/x86.py [moved from arch/x86.py with 100% similarity]
catalyst/config.py [moved from modules/catalyst/config.py with 100% similarity]
catalyst/main.py [moved from catalyst with 91% similarity, mode: 0644]
catalyst/modules/__init__.py [new file with mode: 0644]
catalyst/modules/builder.py [moved from modules/builder.py with 100% similarity]
catalyst/modules/catalyst_lock.py [moved from modules/catalyst_lock.py with 100% similarity]
catalyst/modules/catalyst_support.py [moved from modules/catalyst_support.py with 100% similarity]
catalyst/modules/embedded_target.py [moved from modules/embedded_target.py with 100% similarity]
catalyst/modules/generic_stage_target.py [moved from modules/generic_stage_target.py with 99% similarity]
catalyst/modules/generic_target.py [moved from modules/generic_target.py with 100% similarity]
catalyst/modules/grp_target.py [moved from modules/grp_target.py with 100% similarity]
catalyst/modules/livecd_stage1_target.py [moved from modules/livecd_stage1_target.py with 100% similarity]
catalyst/modules/livecd_stage2_target.py [moved from modules/livecd_stage2_target.py with 100% similarity]
catalyst/modules/netboot2_target.py [moved from modules/netboot2_target.py with 100% similarity]
catalyst/modules/netboot_target.py [moved from modules/netboot_target.py with 100% similarity]
catalyst/modules/snapshot_target.py [moved from modules/snapshot_target.py with 100% similarity]
catalyst/modules/stage1_target.py [moved from modules/stage1_target.py with 100% similarity]
catalyst/modules/stage2_target.py [moved from modules/stage2_target.py with 100% similarity]
catalyst/modules/stage3_target.py [moved from modules/stage3_target.py with 100% similarity]
catalyst/modules/stage4_target.py [moved from modules/stage4_target.py with 100% similarity]
catalyst/modules/tinderbox_target.py [moved from modules/tinderbox_target.py with 100% similarity]
catalyst/util.py [moved from modules/catalyst/util.py with 100% similarity]
modules/catalyst/__init__.py [deleted file]

diff --git a/bin/catalyst b/bin/catalyst
new file mode 100755 (executable)
index 0000000..ace43fc
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/python2 -OO
+
+# Maintained in full by:
+# Catalyst Team <catalyst@gentoo.org>
+# Release Engineering Team <releng@gentoo.org>
+# Andrew Gaffney <agaffney@gentoo.org>
+# Chris Gianelloni <wolf31o2@wolf31o2.org>
+# $Id$
+
+
+from __future__ import print_function
+
+import sys
+
+__maintainer__="Catalyst <catalyst@gentoo.org>"
+__version__="2.0.12.2"
+
+
+# This block ensures that ^C interrupts are handled quietly.
+try:
+       import signal
+
+       def exithandler(signum,frame):
+               signal.signal(signal.SIGINT, signal.SIG_IGN)
+               signal.signal(signal.SIGTERM, signal.SIG_IGN)
+               print()
+               sys.exit(1)
+
+       signal.signal(signal.SIGINT, exithandler)
+       signal.signal(signal.SIGTERM, exithandler)
+       signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+except KeyboardInterrupt:
+       print()
+       sys.exit(1)
+
+
+from catalyst.main import main
+
+try:
+       main()
+except KeyboardInterrupt:
+       print("Aborted.")
+       sys.exit(130)
+sys.exit(0)
+
similarity index 100%
rename from modules/__init__.py
rename to catalyst/__init__.py
diff --git a/catalyst/arch/__init__.py b/catalyst/arch/__init__.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
similarity index 100%
rename from arch/alpha.py
rename to catalyst/arch/alpha.py
similarity index 100%
rename from arch/amd64.py
rename to catalyst/arch/amd64.py
similarity index 100%
rename from arch/arm.py
rename to catalyst/arch/arm.py
similarity index 100%
rename from arch/hppa.py
rename to catalyst/arch/hppa.py
similarity index 100%
rename from arch/ia64.py
rename to catalyst/arch/ia64.py
similarity index 100%
rename from arch/m68k.py
rename to catalyst/arch/m68k.py
similarity index 100%
rename from arch/mips.py
rename to catalyst/arch/mips.py
similarity index 100%
rename from arch/powerpc.py
rename to catalyst/arch/powerpc.py
similarity index 100%
rename from arch/s390.py
rename to catalyst/arch/s390.py
similarity index 100%
rename from arch/sh.py
rename to catalyst/arch/sh.py
similarity index 100%
rename from arch/sparc.py
rename to catalyst/arch/sparc.py
similarity index 100%
rename from arch/x86.py
rename to catalyst/arch/x86.py
old mode 100755 (executable)
new mode 100644 (file)
similarity index 91%
rename from catalyst
rename to catalyst/main.py
index cb6c022..f6a3e51
--- a/catalyst
@@ -1,4 +1,3 @@
-#!/usr/bin/python2 -OO
 
 # Maintained in full by:
 # Catalyst Team <catalyst@gentoo.org>
@@ -15,8 +14,14 @@ import getopt
 import pdb
 import os.path
 
-import modules.catalyst.config
-import modules.catalyst.util
+__selfpath__ = os.path.abspath(os.path.dirname(__file__))
+
+sys.path.append(__selfpath__ + "/modules")
+
+import catalyst.config
+import catalyst.util
+from catalyst.modules.catalyst_support import (required_build_targets,
+       valid_build_targets, CatalystError, hash_map, find_binary, LockInUse)
 
 __maintainer__="Catalyst <catalyst@gentoo.org>"
 __version__="2.0.15"
@@ -102,7 +107,7 @@ def parse_config(myconfig):
        # now, try and parse the config file "config_file"
        try:
 #              execfile(config_file, myconf, myconf)
-               myconfig = modules.catalyst.config.ConfigParser(config_file)
+               myconfig = catalyst.config.ConfigParser(config_file)
                myconf.update(myconfig.get_values())
 
        except:
@@ -118,6 +123,9 @@ def parse_config(myconfig):
                        print "Setting",x,"to default value \""+confdefaults[x]+"\""
                        conf_values[x]=confdefaults[x]
 
+       # add our python base directory to use for loading target arch's
+       conf_values["PythonDir"] = __selfpath__
+
        # parse out the rest of the options from the config file
        if "autoresume" in string.split(conf_values["options"]):
                print "Autoresuming support enabled."
@@ -191,30 +199,32 @@ def import_modules():
        targetmap={}
 
        try:
+               module_dir = __selfpath__ + "/modules/"
                for x in required_build_targets:
                        try:
-                               fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
-                               module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
+                               fh=open(module_dir + x + ".py")
+                               module=imp.load_module(x, fh,"modules/" + x + ".py",
+                                       (".py", "r", imp.PY_SOURCE))
                                fh.close()
 
                        except IOError:
-                               raise CatalystError,"Can't find "+x+".py plugin in "+\
-                                       conf_values["sharedir"]+"/modules/"
-
+                               raise CatalystError, "Can't find " + x + ".py plugin in " + \
+                                       module_dir
                for x in valid_build_targets:
                        try:
-                               fh=open(conf_values["sharedir"]+"/modules/"+x+".py")
-                               module=imp.load_module(x,fh,"modules/"+x+".py",(".py","r",imp.PY_SOURCE))
+                               fh=open(module_dir + x + ".py")
+                               module=imp.load_module(x, fh, "modules/" + x + ".py",
+                                       (".py", "r", imp.PY_SOURCE))
                                module.register(targetmap)
                                fh.close()
 
                        except IOError:
-                               raise CatalystError,"Can't find "+x+".py plugin in "+\
-                                       conf_values["sharedir"]+"/modules/"
+                               raise CatalystError,"Can't find " + x + ".py plugin in " + \
+                                       module_dir
 
        except ImportError:
                print "!!! catalyst: Python modules not found in "+\
-                       conf_values["sharedir"]+"/modules; exiting."
+                       module_dir + "; exiting."
                sys.exit(1)
 
        return targetmap
@@ -229,11 +239,11 @@ def build_target(addlargs, targetmap):
                mytarget.run()
 
        except:
-               modules.catalyst.util.print_traceback()
+               catalyst.util.print_traceback()
                print "!!! catalyst: Error encountered during run of target " + addlargs["target"]
                sys.exit(1)
 
-if __name__ == "__main__":
+def main():
        targetmap={}
 
        version()
@@ -334,8 +344,6 @@ if __name__ == "__main__":
 
        # import configuration file and import our main module using those settings
        parse_config(myconfig)
-       sys.path.append(conf_values["sharedir"]+"/modules")
-       from catalyst_support import *
 
        # Start checking that digests are valid now that the hash_map was imported
        # from catalyst_support
@@ -382,12 +390,12 @@ if __name__ == "__main__":
        addlargs={}
 
        if myspecfile:
-               spec = modules.catalyst.config.SpecParser(myspecfile)
+               spec = catalyst.config.SpecParser(myspecfile)
                addlargs.update(spec.get_values())
 
        if mycmdline:
                try:
-                       cmdline = modules.catalyst.config.ConfigParser()
+                       cmdline = catalyst.config.ConfigParser()
                        cmdline.parse_lines(mycmdline)
                        addlargs.update(cmdline.get_values())
                except CatalystError:
diff --git a/catalyst/modules/__init__.py b/catalyst/modules/__init__.py
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
similarity index 99%
rename from modules/generic_stage_target.py
rename to catalyst/modules/generic_stage_target.py
index 89b891bb0d411b718a73e3cc9ccc3a5edae18364..f04b186d8a4302a2576ae228a0f018554a038e88 100644 (file)
@@ -78,16 +78,18 @@ class generic_stage_target(generic_target):
                self.archmap = {}
                self.subarchmap = {}
                machinemap = {}
-               for x in [x[:-3] for x in os.listdir(self.settings["sharedir"]+\
-                       "/arch/") if x.endswith(".py")]:
+               arch_dir = self.settings["PythonDir"] + "/arch/"
+               for x in [x[:-3] for x in os.listdir(arch_dir) if x.endswith(".py")]:
+                       if x == "__init__":
+                               continue
                        try:
-                               fh=open(self.settings["sharedir"]+"/arch/"+x+".py")
+                               fh=open(arch_dir + x + ".py")
                                """
                                This next line loads the plugin as a module and assigns it to
                                archmap[x]
                                """
-                               self.archmap[x]=imp.load_module(x,fh,"arch/"+x+\
-                                       ".py",(".py","r",imp.PY_SOURCE))
+                               self.archmap[x]=imp.load_module(x,fh,"../arch/" + x + ".py",
+                                       (".py", "r", imp.PY_SOURCE))
                                """
                                This next line registers all the subarches supported in the
                                plugin
@@ -105,8 +107,7 @@ class generic_stage_target(generic_target):
                                the dir should load just fine. If it doesn't, it's probably a
                                syntax error in the module
                                """
-                               msg("Can't find/load "+x+".py plugin in "+\
-                                       self.settings["sharedir"]+"/arch/")
+                               msg("Can't find/load " + x + ".py plugin in " + arch_dir)
 
                if "chost" in self.settings:
                        hostmachine = self.settings["chost"].split("-")[0]
similarity index 100%
rename from modules/catalyst/util.py
rename to catalyst/util.py
diff --git a/modules/catalyst/__init__.py b/modules/catalyst/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000