Anonymous avatar Anonymous committed 97f1f72

handle new clid.db files

Comments (0)

Files changed (3)

+2008-04-18  Paolo Calafiura  <calaf@localhost.localdomain>
+	* tagging CLIDComps-00-04-06
+	* share/clid: cleaned up
+	* python/clidGenerator.py: bring up to speed withnew clid.db format. 
+	Handle multiple clid.db files correctly
+
 2008-04-06  Sebastien Binet  <binet@lblbox>
 
 	* tagging CLIDComps-00-04-05

python/clidGenerator.py

 class clidGenerator:
     "Athena CLID Generator"
     __clidGenerator_type = "Basic"
-    __clidGenerator_version = "$Revision: 1.1 $"
+    __clidGenerator_version = "$Revision: 1.2 $"
     # CLID Mask: Determines bits used for CLID
     __mask = 0x0FFFFFFF
     # CLID Repositories - Dictionaries of CLID<=>Name
     __clidRep = {} # Lookup by CLID
+    __clidPkg = {} # Lookup by CLID
     __nameRep = {} # Lookup by ClassName
     # CLID DataBase (Default = clid.db)
 #   __cliddb = os.getenv('CLIDDB')
     def readdb(self):
         "Read CLID DataBase file"
         try:
-            if os.path.isfile(self.__cliddb):
-                input = open(self.__cliddb,'r')
-                s = input.readlines()
-                for l in s:
-                    ll = string.split(l)
-                    if len(ll) == 2:
-                        self.__clidRep[int(ll[0])] = ll[1]
-                        self.__nameRep[ll[1]] = int(ll[0])
-                input.close()
-            else:
-                print "No CLID DataBase file <%s> " % self.__cliddb        
+            for cliddb in self.__cliddbs:
+                if os.path.isfile(cliddb):
+                    input = open(cliddb,'r')
+                    s = input.readlines()
+                    for l in s:
+                        ll = string.split(l)
+                        if len(ll) == 3:
+                            self.__clidRep[int(ll[0])] = ll[1]
+                            self.__nameRep[ll[1]] = int(ll[0])
+                            self.__clidPkg[int(ll[0])] = ll[2]
+                    input.close()
+                else:
+                    print "No CLID DataBase file <%s> " % cliddb        
         except:
-            print "Error reading from CLID DataBase file <%s> " % self.__cliddb
+            print "Error reading from CLID DataBase files <%s> " %  self.__cliddbs
     def setCLIDDB(self, db, debug):
         "Initializes a CLID Generator object with a CLID Database"
         if db:
-            self.__cliddb = search_file(db, os.getenv('DATAPATH'))
-            if debug: print "Using specified CLID DataBase file %s " % self.__cliddb
+            self.__cliddbs = search_files(db, os.getenv('DATAPATH'))
+            if debug: print "Using specified CLID DataBase files %s " % self.__cliddbs
         elif os.getenv('CLIDDB'):
             # CLID DataBase (Default = clid.db)
-            self.__cliddb = os.getenv('CLIDDB')
-            if debug: print "Using DataBase file from CLIDDB env variable %s " % self.__cliddb
+            self.__cliddbs.append(os.getenv('CLIDDB'))
+            if debug: print "Using DataBase file from CLIDDB env variable %s " % self.__cliddbs
         else:
-            self.__cliddb = search_file('clid.db', os.getenv('DATAPATH'))
-            if debug: print "Using DataBase file from DATAPATH %s " % self.__cliddb
-            
+            self.__cliddbs = search_files('clid.db', os.getenv('DATAPATH'))
+            if debug: print "Using DataBase file from DATAPATH %s " % self.__cliddbs
 
     def writedb(self,db):
         "Read CLID DataBase file"
             return self.__clidRep[clid]
         else:
             return None
+    def getPackageFromClid(self,clid):
+        "Get the name of the package defining <clid>"
+        if self.__clidPkg.has_key(clid):
+            return self.__clidPkg[clid]
+        else:
+            return None
     def demangleClassName(self,s):
         return s
 #        pat = re.compile('\s*(.?)__*\s*')
         candidate = os.path.join(path, filename)
         if os.path.exists(candidate): return os.path.abspath(candidate)
     return None
+
+def search_files(filename, search_path, pathsep=os.pathsep):
+    """Given a search path, find file with requested name """
+    clidFiles = []
+    for path in string.split(search_path, pathsep):
+        candidate = os.path.join(path, filename)
+        if os.path.exists(candidate): clidFiles.append(os.path.abspath(candidate))
+    return clidFiles
 exec python -tx "$0" "$@"
 
 ## @file clid
-# @brief Driver for Athena CLID Generator. "clid -h" for help
-# @author cetull@lbl.gov
+# @brief CLI to Athena CLID DB. "clid -h" for help
+# @author cetull@lbl.gov, pcalafiura@lbl.gov
 
 import string, re
 import sys, os
 #
 def help_examples(prog):
     print "Usage Examples: "
-    print '    ',prog,'-d LArCell'
-    print '    ',prog,'--cliddb=clid.db LArCell'
-    print '    ',prog,'--cliddb=clid.db 2001'
-    print '    ',prog,'--cliddb=clid.db -f "Cr"'
+    print '    ',prog,' -m LArCell'
+    print '    ',prog,' 2001'
+    print '    ',prog,' --cliddb=clid.db -f "Cr"'
 
 
 
               help="Print StoreGate CLASS_DEF macro line", default=False)
 parser.add_option("-s", "--silent", action="store_true", dest="silent",
               help=" Be more silent on output. Print _only_ result. \n (N.B. Overrides -m option.)", default=False)
-#DEPRECATED OPTIONS
-parser.add_option("-x",
-                  action="append", dest="valist", 
-                  help="DEPRECATED OPTION - validate the CLID==CLASSNAME pair",
-                  metavar="CLID==CLASSNAME")
 #
 #load options
 #
 (options, args) = parser.parse_args()
 #print options
 #print args
-if len(args) != 1 and options.relist == None and options.valist == None:
+if len(args) != 1 and options.relist == None:
     parser.error("takes exactly 1 argument")
 
 #
         if options.macro: print "CLASS_DEF(",n,",",c,", 1 )"
         else:
             if options.silent: print c
-            else: print c,n
+            else:
+                print c, n, cgen.getPackageFromClid(c) 
 
 #
 # Process RegEx list
         print '>>> Searching CLIDDB for (',p,') <<<'
         print cgen.findPattern(p)
 
-#
-# Process Validation list
-#
-if options.valist:
-    for p in options.valist:
-        pp = string.split(p,'==')
-        #   print 'Validating(',pp,')'
-        ppid = cgen.getClidFromName(pp[1])
-        if ppid == int(pp[0]):
-            print pp,'is a valid pair.',ppid
-        else:
-            print pp,'is not a valid pair.'
-            sys.exit(1)
-#
-# Write out new repository
-#
-cgen.writedb("new.db")
-#
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.