From f6f26231a1a2c886f43d9ec965eb7903180067fb Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 24 Nov 2009 16:50:20 +0100 Subject: corrected test, added some stuff --- code/directory.py | 22 +++++++++++++++++++--- code/fsobject.py | 6 ++---- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'code') diff --git a/code/directory.py b/code/directory.py index da7c0948..2554ca72 100644 --- a/code/directory.py +++ b/code/directory.py @@ -12,6 +12,7 @@ class Directory(fsobject.FSObject): self.files = None self.filter = None self.pointed_index = None + self.pointed_file = None def load_content(self): self.stop_if_frozen() @@ -22,8 +23,7 @@ class Directory(fsobject.FSObject): basenames = os.listdir(self.path) mapped = map(lambda name: os.path.join(self.path, name), basenames) self.filenames = list(mapped) - self.infostring = ' %d' % len(self.filenames) - debug.log('infostring set!') + self.infostring = ' %d' % len(self.filenames) # update the infostring self.files = [] for name in self.filenames: if os.path.isdir(name): @@ -35,7 +35,23 @@ class Directory(fsobject.FSObject): def load_content_once(self): self.stop_if_frozen() - if not self.content_loaded: self.load_content() + if not self.content_loaded: + self.load_content() + return True + return False + + def load_content_if_outdated(self): + self.stop_if_frozen() + if self.load_content_once(): return True + + import os + real_mtime = os.stat(self.path).st_mtime + cached_mtime = self.stat.st_mtime + + if real_mtime != cached_mtime: + self.load_content() + return True + return False def __len__(self): if not self.accessible: raise fsobject.NotLoadedYet() diff --git a/code/fsobject.py b/code/fsobject.py index 148976d2..6e93140f 100644 --- a/code/fsobject.py +++ b/code/fsobject.py @@ -36,7 +36,7 @@ class FSObject(object): if os.path.isdir(self.path): self.type = fstype.Directory - self.infostring = '--' + self.infostring = ' %d' % len(os.listdir(self.path)) elif os.path.isfile(self.path): self.type = fstype.File self.infostring = ' %d' % self.stat.st_size @@ -60,17 +60,15 @@ class FSObject(object): def load_if_outdated(self): self.stop_if_frozen() - import os - if self.load_once(): return True + import os real_mtime = os.stat(self.path).st_mtime cached_mtime = self.stat.st_mtime if real_mtime != cached_mtime: self.load() return True - return False def clone(self): -- cgit 1.4.1-2-gfad0