1
2
3
4
5
6
7
8
9
10
11
12
13 from Exceptions import ZenImportError
14
16 """lookup a class by its path use baseModule path if passed"""
17 if baseModule: classpath = ".".join((baseModule, classpath))
18 try:
19 mod = __import__(classpath)
20 except ImportError:
21 try:
22 mod = __import__(".".join(classpath.split(".")[:-1]))
23 except:
24 raise ZenImportError("failed importing class %s" % classpath)
25 for comp in classpath.split(".")[1:]:
26 mod = getattr(mod, comp)
27 classdef = getattr(mod, comp, None)
28 if classdef: mod = classdef
29 return mod
30
31
33 """
34 import all classes listed in baseModule in the variable productNames
35 and return them in a list. Assume that classes are defined in a file
36 with the same name as the class.
37 """
38 classList = []
39 mod = __import__(basemodule)
40 for comp in basemodule.split(".")[1:]:
41 mod = getattr(mod, comp)
42 for prodname in mod.productNames:
43 if prodname in skipnames: continue
44 classdef = importClass(prodname, basemodule)
45 classList.append(classdef)
46 return classList
47