7 import string, re, os, csv
15 if len(s) == 0:
return 0
18 x = (1000003*x) ^ ord(c)
27 """Athena CLID Generator"""
41 clidGenerator.__clidRep = {}
42 clidGenerator.__nameRep = {}
45 """Read CLID DataBase file"""
48 if os.path.isfile(cliddb):
49 with open(cliddb,
'r')
as f_cliddb:
50 for row
in csv.reader (f_cliddb, delimiter=
';'):
51 row = [i.strip()
for i
in row]
55 tid_name = row[2]
if len(row)>2
else class_name
63 print (
"No CLID DataBase file <%s> " % cliddb)
64 except Exception
as err:
65 print (
"Error reading from CLID DataBase files <%s>:\n%s " % (
70 """Initializes a CLID Generator object with a CLID Database"""
73 if debug:
print (
"Using specified CLID DataBase files %s " % self.
__cliddbs)
74 elif os.getenv(
'CLIDDB'):
77 if debug:
print (
"Using DataBase file from CLIDDB env variable %s " % self.
__cliddbs)
80 if debug:
print (
"Using DataBase file from DATAPATH %s " % self.
__cliddbs)
83 """Read CLID DataBase file"""
86 output.write(
"%d "%k+self.
__clidRep[k]+
"\n")
90 """Generate CLID from ClassName: A recursive hash with a bit
91 mask and validity range. Will check collisions against and
92 update CLID Repository."""
98 if c < 10001
or c > self.
__mask:
113 """Get the CLID in the repository of class name <className>"""
117 """Get the CLID in the repository of typeid name <tidName>"""
121 """Get the class name in the repository with CLID <clid>"""
125 """Get the typeid name in the repository with CLID <clid>"""
138 collMatch = re.search(
r'.*?Collection_*|.*?Container_*',className)
142 """Find the regular expression pattern s in dictionary."""
152 """Given a search path, find file with requested name """
153 for path
in string.split(search_path, pathsep):
154 candidate = os.path.join(path, filename)
155 if os.path.exists(candidate):
return os.path.abspath(candidate)
159 """Given a search path, find file with requested name """
161 for path
in search_path.split(pathsep):
162 candidate = os.path.join(path, filename)
163 if os.path.exists(candidate): clidFiles.append(os.path.abspath(candidate))