From 8736e09b45664fc0826a0f53184399ef56e88fdb Mon Sep 17 00:00:00 2001 From: Frederic Back Date: Thu, 28 Sep 2006 14:37:25 +0000 Subject: * Sort first ring as usual, but inner rings by size (Only for gnomevfs) git-svn-id: file:///home/lennart/svn/public/fring/trunk@43 d0d2c35f-0a1e-0410-abeb-dabff30a67ee --- src/fringlib/fringwalker.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fringlib/fringwalker.py b/src/fringlib/fringwalker.py index 25362c1..7f7111d 100644 --- a/src/fringlib/fringwalker.py +++ b/src/fringlib/fringwalker.py @@ -23,6 +23,8 @@ def print_tree( treearray, tab=0 ): for e in data: print_tree(e,tab+1) +def treearray_cmp_by_size( a, b ): + return cmp(a[2], b[2]) # compare sizes def treearray_cmp_fn( a, b ): """ a and b are tuples describing a directory tree. Compare first by directory @@ -104,6 +106,8 @@ class WalkThread( threading.Thread ): self.showhidden = showhidden self.method = method + self.max_recursion_sort = 3 + def __uri_tail(self, uri): """ Return the tail (the filename) of a gnomevfs uri """ f = format_uri_for_display(str(uri)) @@ -129,7 +133,7 @@ class WalkThread( threading.Thread ): return (os.path.split(path)[-1], l, total) - def build_tree_gnomevfs(self, uri): + def build_tree_gnomevfs(self, uri, recursionlvl=0): try: h = DirectoryHandle(uri) except InvalidURIError: @@ -148,14 +152,17 @@ class WalkThread( threading.Thread ): if not self.showhidden and d.name[0] == ".": continue if d.type == 2: # directory - sub = self.build_tree_gnomevfs(uri.append_path(d.name)) + sub = self.build_tree_gnomevfs(uri.append_path(d.name),recursionlvl+1) l.append( sub ) total += sub[2] else: l.append( (d.name, None, d.size) ) total += d.size + except StopIteration: pass - except StopIteration: pass + if recursionlvl <= self.max_recursion_sort: + l.sort(treearray_cmp_by_size) + return (self.__uri_tail(uri), l, total) -- cgit