main.py: print the output of an ImportError to help in debugging.
[catalyst.git] / catalyst / main.py
index 8acd2804f9dd57952d0895044c12fbc2df053f4d..bba3cbab2dbbb12a444ffbec11fdc2d2ff71f9fc 100644 (file)
@@ -18,13 +18,16 @@ __selfpath__ = os.path.abspath(os.path.dirname(__file__))
 
 sys.path.append(__selfpath__ + "/modules")
 
+from . import __version__
 import catalyst.config
 import catalyst.util
 from catalyst.support import (required_build_targets,
-       valid_build_targets, CatalystError, hash_map, find_binary, LockInUse)
+       valid_build_targets, CatalystError, find_binary, LockInUse)
+
+from hash_utils import HashMap, HASH_DEFINITIONS
+from contents import ContentsMap, CONTENTS_DEFINITIONS
+
 
-__maintainer__="Catalyst <catalyst@gentoo.org>"
-__version__="2.0.15"
 
 conf_values={}
 
@@ -182,7 +185,8 @@ def parse_config(myconfig):
        if "digests" in myconf:
                conf_values["digests"]=myconf["digests"]
        if "contents" in myconf:
-               conf_values["contents"]=myconf["contents"]
+               # replace '-' with '_' (for compatibility with existing configs)
+               conf_values["contents"] = myconf["contents"].replace("-", '_')
 
        if "envscript" in myconf:
                print "Envscript support enabled."
@@ -200,11 +204,11 @@ def import_modules():
        targetmap={}
 
        try:
-               module_dir = __selfpath__ + "/modules/"
+               module_dir = __selfpath__ + "/targets/"
                for x in required_build_targets:
                        try:
                                fh=open(module_dir + x + ".py")
-                               module=imp.load_module(x, fh,"modules/" + x + ".py",
+                               module=imp.load_module(x, fh,"targets/" + x + ".py",
                                        (".py", "r", imp.PY_SOURCE))
                                fh.close()
 
@@ -214,7 +218,7 @@ def import_modules():
                for x in valid_build_targets:
                        try:
                                fh=open(module_dir + x + ".py")
-                               module=imp.load_module(x, fh, "modules/" + x + ".py",
+                               module=imp.load_module(x, fh, "targets/" + x + ".py",
                                        (".py", "r", imp.PY_SOURCE))
                                module.register(targetmap)
                                fh.close()
@@ -223,9 +227,10 @@ def import_modules():
                                raise CatalystError,"Can't find " + x + ".py plugin in " + \
                                        module_dir
 
-       except ImportError:
+       except ImportError as e:
                print "!!! catalyst: Python modules not found in "+\
                        module_dir + "; exiting."
+               print e
                sys.exit(1)
 
        return targetmap
@@ -346,40 +351,47 @@ def main():
        # import configuration file and import our main module using those settings
        parse_config(myconfig)
 
-       # Start checking that digests are valid now that the hash_map was imported
-       # from catalyst.support
+       # initialize our contents generator
+       contents_map = ContentsMap(CONTENTS_DEFINITIONS)
+       conf_values["contents_map"] = contents_map
+
+       # initialze our hash and contents generators
+       hash_map = HashMap(HASH_DEFINITIONS)
+       conf_values["hash_map"] = hash_map
+
+       # Start checking that digests are valid now that hash_map is initialized
        if "digests" in conf_values:
                for i in conf_values["digests"].split():
-                       if i not in hash_map:
+                       if i not in HASH_DEFINITIONS:
                                print
                                print i+" is not a valid digest entry"
                                print "Valid digest entries:"
-                               print hash_map.keys()
+                               print HASH_DEFINITIONS.keys()
                                print
                                print "Catalyst aborting...."
                                sys.exit(2)
-                       if find_binary(hash_map[i][1]) == None:
+                       if find_binary(hash_map.hash_map[i].cmd) == None:
                                print
-                               print "digest="+i
-                               print "\tThe "+hash_map[i][1]+\
+                               print "digest=" + i
+                               print "\tThe " + hash_map.hash_map[i].cmd + \
                                        " binary was not found. It needs to be in your system path"
                                print
                                print "Catalyst aborting...."
                                sys.exit(2)
        if "hash_function" in conf_values:
-               if conf_values["hash_function"] not in hash_map:
+               if conf_values["hash_function"] not in HASH_DEFINITIONS:
                        print
                        print conf_values["hash_function"]+\
                                " is not a valid hash_function entry"
                        print "Valid hash_function entries:"
-                       print hash_map.keys()
+                       print HASH_DEFINITIONS.keys()
                        print
                        print "Catalyst aborting...."
                        sys.exit(2)
-               if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
+               if find_binary(hash_map.hash_map[conf_values["hash_function"]].cmd) == None:
                        print
                        print "hash_function="+conf_values["hash_function"]
-                       print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
+                       print "\tThe "+hash_map.hash_map[conf_values["hash_function"]].cmd + \
                                " binary was not found. It needs to be in your system path"
                        print
                        print "Catalyst aborting...."