[fbt-commit] SF.net SVN: fbt:[96] trunk/bin/DepList.py
Status: Beta
Brought to you by:
dave_infj
From: <dav...@us...> - 2010-05-24 16:01:58
|
Revision: 96 http://fbt.svn.sourceforge.net/fbt/?rev=96&view=rev Author: dave_infj Date: 2010-05-24 16:01:51 +0000 (Mon, 24 May 2010) Log Message: ----------- Clean up tabs and empty lines add_dep() now will merge deps lists for dep records for the same ent/source file, rather than ending up with duplicate dep records merge() now simplified by calling add_dep() Modified Paths: -------------- trunk/bin/DepList.py Modified: trunk/bin/DepList.py =================================================================== --- trunk/bin/DepList.py 2010-05-13 16:11:12 UTC (rev 95) +++ trunk/bin/DepList.py 2010-05-24 16:01:51 UTC (rev 96) @@ -41,41 +41,46 @@ class DepList: """ Helper class for storing lists of entity dependencies - + Usage: Inputs are individual candidates added via DepList.add_dep() Outputs are always sets of candidates indexed by entity """ - + def __init__(self): self.list = {} # Regex for parsing dependency caches self.m_deps = re.compile( '(\w+)\s*\(\s*([\w.-]+)\s*\)\s*:(.*)' ) - + def add_dep(self, ent, hdl_src, deps, core_src = '' ): """ Add a dependency to the list """ - - try: - self.list[ent].append( (hdl_src, deps, core_src) ) - except KeyError: - self.list[ent] = [ (hdl_src, deps, core_src) ] - + if ent in self.list: + # If this source file is already known, merge the new deps list + # with the existing entry + for _src, _deps, _core_src in self.list[ent]: + if _src == hdl_src : + _deps.update(deps) + return + # Else add a new entry + self.list[ent].append( (hdl_src, set(deps), core_src) ) + else: + self.list[ent] = [ (hdl_src, set(deps), core_src) ] + + def merge(self, src): """ Update a dependencies dictionary with a new entry, merging if required. """ - - for ent, dep_rec in src.list.iteritems(): - try: - self.list[ent] = self.list[ent] + dep_rec - except KeyError: - self.list[ent] = dep_rec - + for ent, deps in src.list.iteritems(): + for dep in deps: + self.add_dep( ent, *dep ) + + def write_deps_cache(self, df): """ Write out the DepList in a linear .depends cache file. df is an handle @@ -97,13 +102,13 @@ os.path.basename(core_src), ' '.join(deps)) ) - + def read_deps_cache(self, df, path): """ Import depencency data from a .depends cache file. df is an handle and must already be open """ - + with df: for lno, dep_line in enumerate(df): # Delete any comments @@ -125,7 +130,7 @@ ) ent, hdl_src, deps = match.groups() deps = deps.split() - + # If deps contains a single object ending in '.xco', then it # is a core reference. if len(deps) == 1 and deps[0].endswith('.xco'): @@ -147,21 +152,18 @@ def iterkeys(self): return self.list.iterkeys() - + def iteritems(self): return self.list.iteritems() - + def __iter__(self): return self.iterkeys() - + def __contains__(self, ent): return ent in self.list def __getitem__(self, ent): return self.list[ent] - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |