diff options
author | Frederic Back <fredericback@gmail.com> | 2006-10-03 11:02:22 +0000 |
---|---|---|
committer | Frederic Back <fredericback@gmail.com> | 2006-10-03 11:02:22 +0000 |
commit | 03ad44ccf9bd1fdbc2fd89adb494289d5623d47f (patch) | |
tree | 2db0091b99d83693ea0d95be9aa536396fbd7d6b /src/fringlib/fringdata.py | |
parent | 9f5926851fab9e3e5129a62efd1044214691b531 (diff) |
* Put sumlists in a central repository. Load from memory if a path
is already walked.
git-svn-id: file:///home/lennart/svn/public/fring/trunk@62 d0d2c35f-0a1e-0410-abeb-dabff30a67ee
Diffstat (limited to 'src/fringlib/fringdata.py')
-rw-r--r-- | src/fringlib/fringdata.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/fringlib/fringdata.py b/src/fringlib/fringdata.py index a9bea69..1da49c0 100644 --- a/src/fringlib/fringdata.py +++ b/src/fringlib/fringdata.py @@ -13,6 +13,10 @@ class SumList: self.children.append(sumlist) self.size += sumlist.size + def has_children(self): + if len(self.children) > 0: return True + return False + def printout(self, tab=0 ): print " "*tab,"%s (%i)"%(sumlist.name,sumlist.size) if not sumlist.children: return @@ -54,5 +58,43 @@ class SumList: return 3 +#================================================================================== +class SumListCollection: + """ A repository for folder data. + + Is filled by the walker, and retrieved by the UI class. + An int is used to track changes in a path. + + Since sumlists are objects, python will store references to them instead + of copying the data (as it would with tuples). + """ + + def __init__(self): + self.clear() + + def set_sumlist(self, uri, sumlist): + if not isinstance(sumlist,SumList): raise ValueError + if not isinstance(uri,unicode): raise ValueError + if not sumlist.has_children(): return # skip files + self.collection[uri] = sumlist + if uri in self.versionControl: + self.versionControl[uri] += 1 + else: + self.versionControl[uri] = 0 + + def get_sumlist(self, uri): + if uri in self.collection: + return self.collection[uri] + + def has_changed(self, uri, version): + if uri in self.versionControl: + if version != self.versionControl[uri]: + return True + return False + + def clear(self): + self.collection = {} + self.versionControl = {} + gc.collect() |