diff options
Diffstat (limited to 'src/fringlib/fringwalker.py')
-rw-r--r-- | src/fringlib/fringwalker.py | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/src/fringlib/fringwalker.py b/src/fringlib/fringwalker.py index d328627..f04858a 100644 --- a/src/fringlib/fringwalker.py +++ b/src/fringlib/fringwalker.py @@ -1,6 +1,6 @@ import os, sys import threading -import time +from time import time import gobject, gtk import posixpath from gnomevfs import * @@ -34,6 +34,8 @@ class FringWalker( gobject.GObject ): if self.thread: self.emit("manually-stopped") self.thread.stopsignal = True + # remove unfinished sumlist from collection + self.collection.rem_sumlist(unicode(self.thread.uri)) self.thread = None def _progress_fn(self, walkthread, c, l, r, currentlyScanning): @@ -64,8 +66,8 @@ class WalkThread( threading.Thread ): self.master = master self.uri = URI(uri) self.showhidden = showhidden - - self.max_recursion_sort = 3 + self.max_recursion_sort = 3 + self.progresstimer = 0 def build_tree_gnomevfs(self, uri, recursionlvl=0): result = SumList(self.__uri_tail(uri), None, 0) @@ -89,16 +91,21 @@ class WalkThread( threading.Thread ): result.sort_by_size() self.master.collection.set_sumlist(unicode(uri),result) + if recursionlvl <= 1: + self.__check_progress() + return result def run(self): """ Parse the root directory """ + self.progresstimer = time() + self.result = SumList(self.__uri_tail(self.uri), None, 0) self.master._progress_fn(self, 0, 1, self.result, self.uri) # write some debug information - starttime = time.time() + starttime = time() print "start walking",self.uri # scan root directory first (using gnomevfs) @@ -115,28 +122,29 @@ class WalkThread( threading.Thread ): else: self.result.append_child( SumList(d.name, None, d.size) ) except StopIteration: pass - # emit an intermediate version to fill up the screen while waiting - self.result.sort() - self.master.collection.set_sumlist(unicode(self.uri),self.result) - # walk the subdirectories - c = 0 - for directory in subdirectories: - c += 1 - - sub = self.build_tree_gnomevfs(self.uri.append_path(directory)) + self.progress_total = len(subdirectories) + self.progress_count = 0 + for self.directory in subdirectories: + sub = self.build_tree_gnomevfs(self.uri.append_path(self.directory)) self.result.append_child( sub ) if self.stopsignal: return - - self.result.sort() - self.master.collection.set_sumlist(unicode(self.uri),self.result) - - self.master._progress_fn(self, c, len(subdirectories), self.result, sub.name) + self.progress_count += 1 # emit final signal self.master._finished_fn(self,self.result) - print "finished walking",self.uri,"(time=%s)"%round(time.time()-starttime,2) - + self.master.collection.set_sumlist(unicode(self.uri),self.result) + print "finished walking",self.uri,"(time=%s)"%round(time()-starttime,2) + + def __check_progress(self): + if time()-self.progresstimer > .25: + self.progresstimer = time() + #self.result.sort_by_size() + self.master._progress_fn(self, + self.progress_count, self.progress_total, + self.result, + self.directory) + def __uri_tail(self, uri): """ Return the tail (the filename) of a gnomevfs uri """ f = format_uri_for_display(str(uri)) @@ -145,5 +153,6 @@ class WalkThread( threading.Thread ): def __open_directory(self, uri): try: return DirectoryHandle(uri) - except InvalidURIError: print uri,"is not a valid uri, skipped" - except NotFoundError: print uri,"not found, skipped" + except InvalidURIError: print "Could not open",uri,"(not a valid uri)" + except NotFoundError: print "Could not open",uri,"(not found)" + except AccessDeniedError: print "Could not open",uri,"(access denied)" |