1
2
3
4
5
6
7
8
9
10
11 from Exceptions import ZenImportError
12
14 """lookup a class by its path use baseModule path if passed"""
15 import sys
16 if baseModule: classpath = ".".join((baseModule, classpath))
17 parts = classpath.split('.')
18 try:
19 mod = __import__(classpath)
20 mod = sys.modules[classpath]
21 except (ImportError, KeyError):
22 try:
23 base = ".".join(parts[:-1])
24 mod = __import__(base)
25 mod = sys.modules[base]
26 except:
27 raise ZenImportError("failed importing class %s" % classpath)
28 return getattr(mod, parts[-1], mod)
29
30
32 """
33 import all classes listed in baseModule in the variable productNames
34 and return them in a list. Assume that classes are defined in a file
35 with the same name as the class.
36 """
37 classList = []
38 mod = __import__(basemodule)
39 for comp in basemodule.split(".")[1:]:
40 mod = getattr(mod, comp)
41 for prodname in mod.productNames:
42 if prodname in skipnames: continue
43 classdef = importClass(prodname, basemodule)
44 classList.append(classdef)
45 return classList
46
47
49 """
50 Adapts a ZenRelation to find a unique id.
51 """
54
56 """
57 Create an id.
58 """
59 dot = name.rfind('.')
60 if dot >= 0:
61 suffix = name[dot:]
62 name = name[:dot]
63 else:
64 suffix = ''
65 n = name + suffix
66 i = 1
67 inuse = self.context.objectIdsAll()
68 while n in inuse:
69 i += 1
70 n = name + str(i) + suffix
71 return str(n)
72