From 24c53524bfb97dc0e7d7a37b5bc752cc132210c2 Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Thu, 10 Jan 2013 18:56:28 -0800 Subject: [PATCH] Initial rearrangement of the python directories 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. --- bin/catalyst | 46 ++++++++++++++++++ {modules => catalyst}/__init__.py | 0 catalyst/arch/__init__.py | 1 + {arch => catalyst/arch}/alpha.py | 0 {arch => catalyst/arch}/amd64.py | 0 {arch => catalyst/arch}/arm.py | 0 {arch => catalyst/arch}/hppa.py | 0 {arch => catalyst/arch}/ia64.py | 0 {arch => catalyst/arch}/m68k.py | 0 {arch => catalyst/arch}/mips.py | 0 {arch => catalyst/arch}/powerpc.py | 0 {arch => catalyst/arch}/s390.py | 0 {arch => catalyst/arch}/sh.py | 0 {arch => catalyst/arch}/sparc.py | 0 {arch => catalyst/arch}/x86.py | 0 {modules/catalyst => catalyst}/config.py | 0 catalyst => catalyst/main.py | 48 +++++++++++-------- catalyst/modules/__init__.py | 1 + {modules => catalyst/modules}/builder.py | 0 .../modules}/catalyst_lock.py | 0 .../modules}/catalyst_support.py | 0 .../modules}/embedded_target.py | 0 .../modules}/generic_stage_target.py | 15 +++--- .../modules}/generic_target.py | 0 {modules => catalyst/modules}/grp_target.py | 0 .../modules}/livecd_stage1_target.py | 0 .../modules}/livecd_stage2_target.py | 0 .../modules}/netboot2_target.py | 0 .../modules}/netboot_target.py | 0 .../modules}/snapshot_target.py | 0 .../modules}/stage1_target.py | 0 .../modules}/stage2_target.py | 0 .../modules}/stage3_target.py | 0 .../modules}/stage4_target.py | 0 .../modules}/tinderbox_target.py | 0 {modules/catalyst => catalyst}/util.py | 0 modules/catalyst/__init__.py | 0 37 files changed, 84 insertions(+), 27 deletions(-) create mode 100755 bin/catalyst rename {modules => catalyst}/__init__.py (100%) create mode 100644 catalyst/arch/__init__.py rename {arch => catalyst/arch}/alpha.py (100%) rename {arch => catalyst/arch}/amd64.py (100%) rename {arch => catalyst/arch}/arm.py (100%) rename {arch => catalyst/arch}/hppa.py (100%) rename {arch => catalyst/arch}/ia64.py (100%) rename {arch => catalyst/arch}/m68k.py (100%) rename {arch => catalyst/arch}/mips.py (100%) rename {arch => catalyst/arch}/powerpc.py (100%) rename {arch => catalyst/arch}/s390.py (100%) rename {arch => catalyst/arch}/sh.py (100%) rename {arch => catalyst/arch}/sparc.py (100%) rename {arch => catalyst/arch}/x86.py (100%) rename {modules/catalyst => catalyst}/config.py (100%) rename catalyst => catalyst/main.py (91%) mode change 100755 => 100644 create mode 100644 catalyst/modules/__init__.py rename {modules => catalyst/modules}/builder.py (100%) rename {modules => catalyst/modules}/catalyst_lock.py (100%) rename {modules => catalyst/modules}/catalyst_support.py (100%) rename {modules => catalyst/modules}/embedded_target.py (100%) rename {modules => catalyst/modules}/generic_stage_target.py (99%) rename {modules => catalyst/modules}/generic_target.py (100%) rename {modules => catalyst/modules}/grp_target.py (100%) rename {modules => catalyst/modules}/livecd_stage1_target.py (100%) rename {modules => catalyst/modules}/livecd_stage2_target.py (100%) rename {modules => catalyst/modules}/netboot2_target.py (100%) rename {modules => catalyst/modules}/netboot_target.py (100%) rename {modules => catalyst/modules}/snapshot_target.py (100%) rename {modules => catalyst/modules}/stage1_target.py (100%) rename {modules => catalyst/modules}/stage2_target.py (100%) rename {modules => catalyst/modules}/stage3_target.py (100%) rename {modules => catalyst/modules}/stage4_target.py (100%) rename {modules => catalyst/modules}/tinderbox_target.py (100%) rename {modules/catalyst => catalyst}/util.py (100%) delete mode 100644 modules/catalyst/__init__.py diff --git a/bin/catalyst b/bin/catalyst new file mode 100755 index 00000000..ace43fc7 --- /dev/null +++ b/bin/catalyst @@ -0,0 +1,46 @@ +#!/usr/bin/python2 -OO + +# Maintained in full by: +# Catalyst Team +# Release Engineering Team +# Andrew Gaffney +# Chris Gianelloni +# $Id$ + + +from __future__ import print_function + +import sys + +__maintainer__="Catalyst " +__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) + diff --git a/modules/__init__.py b/catalyst/__init__.py 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 index 00000000..8b137891 --- /dev/null +++ b/catalyst/arch/__init__.py @@ -0,0 +1 @@ + diff --git a/arch/alpha.py b/catalyst/arch/alpha.py similarity index 100% rename from arch/alpha.py rename to catalyst/arch/alpha.py diff --git a/arch/amd64.py b/catalyst/arch/amd64.py similarity index 100% rename from arch/amd64.py rename to catalyst/arch/amd64.py diff --git a/arch/arm.py b/catalyst/arch/arm.py similarity index 100% rename from arch/arm.py rename to catalyst/arch/arm.py diff --git a/arch/hppa.py b/catalyst/arch/hppa.py similarity index 100% rename from arch/hppa.py rename to catalyst/arch/hppa.py diff --git a/arch/ia64.py b/catalyst/arch/ia64.py similarity index 100% rename from arch/ia64.py rename to catalyst/arch/ia64.py diff --git a/arch/m68k.py b/catalyst/arch/m68k.py similarity index 100% rename from arch/m68k.py rename to catalyst/arch/m68k.py diff --git a/arch/mips.py b/catalyst/arch/mips.py similarity index 100% rename from arch/mips.py rename to catalyst/arch/mips.py diff --git a/arch/powerpc.py b/catalyst/arch/powerpc.py similarity index 100% rename from arch/powerpc.py rename to catalyst/arch/powerpc.py diff --git a/arch/s390.py b/catalyst/arch/s390.py similarity index 100% rename from arch/s390.py rename to catalyst/arch/s390.py diff --git a/arch/sh.py b/catalyst/arch/sh.py similarity index 100% rename from arch/sh.py rename to catalyst/arch/sh.py diff --git a/arch/sparc.py b/catalyst/arch/sparc.py similarity index 100% rename from arch/sparc.py rename to catalyst/arch/sparc.py diff --git a/arch/x86.py b/catalyst/arch/x86.py similarity index 100% rename from arch/x86.py rename to catalyst/arch/x86.py diff --git a/modules/catalyst/config.py b/catalyst/config.py similarity index 100% rename from modules/catalyst/config.py rename to catalyst/config.py diff --git a/catalyst b/catalyst/main.py old mode 100755 new mode 100644 similarity index 91% rename from catalyst rename to catalyst/main.py index cb6c0226..f6a3e511 --- a/catalyst +++ b/catalyst/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/python2 -OO # Maintained in full by: # Catalyst Team @@ -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 " __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 index 00000000..8b137891 --- /dev/null +++ b/catalyst/modules/__init__.py @@ -0,0 +1 @@ + diff --git a/modules/builder.py b/catalyst/modules/builder.py similarity index 100% rename from modules/builder.py rename to catalyst/modules/builder.py diff --git a/modules/catalyst_lock.py b/catalyst/modules/catalyst_lock.py similarity index 100% rename from modules/catalyst_lock.py rename to catalyst/modules/catalyst_lock.py diff --git a/modules/catalyst_support.py b/catalyst/modules/catalyst_support.py similarity index 100% rename from modules/catalyst_support.py rename to catalyst/modules/catalyst_support.py diff --git a/modules/embedded_target.py b/catalyst/modules/embedded_target.py similarity index 100% rename from modules/embedded_target.py rename to catalyst/modules/embedded_target.py diff --git a/modules/generic_stage_target.py b/catalyst/modules/generic_stage_target.py similarity index 99% rename from modules/generic_stage_target.py rename to catalyst/modules/generic_stage_target.py index 89b891bb..f04b186d 100644 --- a/modules/generic_stage_target.py +++ b/catalyst/modules/generic_stage_target.py @@ -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] diff --git a/modules/generic_target.py b/catalyst/modules/generic_target.py similarity index 100% rename from modules/generic_target.py rename to catalyst/modules/generic_target.py diff --git a/modules/grp_target.py b/catalyst/modules/grp_target.py similarity index 100% rename from modules/grp_target.py rename to catalyst/modules/grp_target.py diff --git a/modules/livecd_stage1_target.py b/catalyst/modules/livecd_stage1_target.py similarity index 100% rename from modules/livecd_stage1_target.py rename to catalyst/modules/livecd_stage1_target.py diff --git a/modules/livecd_stage2_target.py b/catalyst/modules/livecd_stage2_target.py similarity index 100% rename from modules/livecd_stage2_target.py rename to catalyst/modules/livecd_stage2_target.py diff --git a/modules/netboot2_target.py b/catalyst/modules/netboot2_target.py similarity index 100% rename from modules/netboot2_target.py rename to catalyst/modules/netboot2_target.py diff --git a/modules/netboot_target.py b/catalyst/modules/netboot_target.py similarity index 100% rename from modules/netboot_target.py rename to catalyst/modules/netboot_target.py diff --git a/modules/snapshot_target.py b/catalyst/modules/snapshot_target.py similarity index 100% rename from modules/snapshot_target.py rename to catalyst/modules/snapshot_target.py diff --git a/modules/stage1_target.py b/catalyst/modules/stage1_target.py similarity index 100% rename from modules/stage1_target.py rename to catalyst/modules/stage1_target.py diff --git a/modules/stage2_target.py b/catalyst/modules/stage2_target.py similarity index 100% rename from modules/stage2_target.py rename to catalyst/modules/stage2_target.py diff --git a/modules/stage3_target.py b/catalyst/modules/stage3_target.py similarity index 100% rename from modules/stage3_target.py rename to catalyst/modules/stage3_target.py diff --git a/modules/stage4_target.py b/catalyst/modules/stage4_target.py similarity index 100% rename from modules/stage4_target.py rename to catalyst/modules/stage4_target.py diff --git a/modules/tinderbox_target.py b/catalyst/modules/tinderbox_target.py similarity index 100% rename from modules/tinderbox_target.py rename to catalyst/modules/tinderbox_target.py diff --git a/modules/catalyst/util.py b/catalyst/util.py 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 index e69de29b..00000000 -- 2.26.2