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 import sys
18 if baseModule: classpath = ".".join((baseModule, classpath))
19 parts = classpath.split('.')
20 try:
21 mod = __import__(classpath)
22 mod = sys.modules[classpath]
23 except (ImportError, KeyError):
24 try:
25 base = ".".join(parts[:-1])
26 mod = __import__(base)
27 mod = sys.modules[base]
28 except:
29 raise ZenImportError("failed importing class %s" % classpath)
30 return getattr(mod, parts[-1], mod)
31
32
34 """
35 import all classes listed in baseModule in the variable productNames
36 and return them in a list. Assume that classes are defined in a file
37 with the same name as the class.
38 """
39 classList = []
40 mod = __import__(basemodule)
41 for comp in basemodule.split(".")[1:]:
42 mod = getattr(mod, comp)
43 for prodname in mod.productNames:
44 if prodname in skipnames: continue
45 classdef = importClass(prodname, basemodule)
46 classList.append(classdef)
47 return classList
48
49
51 """
52 Adapts a ZenRelation to find a unique id.
53 """
56
58 """
59 Create an id.
60 """
61 dot = name.rfind('.')
62 if dot >= 0:
63 suffix = name[dot:]
64 name = name[:dot]
65 else:
66 suffix = ''
67 n = name + suffix
68 i = 1
69 inuse = self.context.objectIdsAll()
70 while n in inuse:
71 i += 1
72 n = name + str(i) + suffix
73 return str(n)
74