Help with a reverse dictionary lookup

rh0dium steven.klass at gmail.com
Thu Mar 9 21:16:37 EST 2006


Hey thanks - OK how would you arrange the data structure?  I think that
is my problem - I can arrange in any order - I just want something
which makes sense - this "seemed" logical but can you point me in a
better method..  Basically I am parsing a directory structure:

TECHROOT/
   130nm/
      tsmc/
         1p2m<blah>
         2p2m<blah>
      umc/
         3p2m<blah>
   180nm/
      tsmc/
         1p2m<blah>

Any thoughts -- To parse this I use this..


    def _getNodes(self):
        self.nodes={}
        for node in os.listdir(self.foundrypath):
            node = os.path.join( self.foundrypath, node)
            if os.path.isdir(node):
                self.logger.debug("Node found - %s" % node)
                self.nodes[os.path.basename(node)]={}
            else:
                self.logger.debug("Excluding %s" % node)

        return self.nodes

    def _getFoundries(self):
        for node in self.nodes:
            node = os.path.join( self.foundrypath, node)
            for foundry in os.listdir(node):
                foundry = os.path.join( node, foundry)
                if os.path.isdir(foundry):
                    self.logger.debug("Foundry found - %s" % foundry)
                    if os.path.basename(foundry) != "smsc":

self.nodes[os.path.basename(node)][os.path.basename(foundry)]=[]
                    else:
                        self.logger.debug("smsc foundry found - %s" %
foundry)
                        self.smscfoundry=1
                else:
                    self.logger.debug("Excluding %s" % foundry)

    def _getProcesses(self):
        for node in self.nodes:
            for foundry in self.nodes[node]:
                foundry = os.path.join( self.foundrypath, node,
foundry)
                for process in os.listdir(foundry):
                    process = os.path.join( foundry, process )
                    if os.path.isdir( process ):
                        self.logger.debug("Process found - %s" %
process )

self.nodes[node][os.path.basename(foundry)].append(os.path.basename(process))
                    else:
                        self.logger.debug("Excluding %s" % process)

Please feel free to comment and clean it up.  I want it readable so I
can modify it later ;)




More information about the Python-list mailing list