diff options
author | hut <hut@lavabit.com> | 2011-04-19 18:12:05 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-04-19 18:12:23 +0200 |
commit | 7c33d7792efa6c4a1e56310c18ff04a721a2ea50 (patch) | |
tree | 0cf0fcc3f183f6050aebdc39af5a0cd29496b41d /ranger/fsobject/directory.py | |
parent | 47c394e3836699c5920965fee4c20d7a20343b32 (diff) | |
download | ranger-7c33d7792efa6c4a1e56310c18ff04a721a2ea50.tar.gz |
use lazy_property for Directory.size/infostring
for more passive and faster loading of directories
Diffstat (limited to 'ranger/fsobject/directory.py')
-rw-r--r-- | ranger/fsobject/directory.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 3c0f680d..7b8a7563 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -26,6 +26,7 @@ from ranger.ext.mount_path import mount_path from ranger.fsobject import BAD_INFO, File, FileSystemObject from ranger.core.shared import SettingsAware from ranger.ext.accumulator import Accumulator +from ranger.ext.lazy_property import lazy_property import ranger.fsobject def sort_by_basename(path): @@ -320,6 +321,32 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware): else: self.correct_pointer() + @lazy_property + def size(self): + try: + size = len(os.listdir(self.path)) # bite me + except OSError: + self.infostring = '?' + self.accessible = False + return 0 + else: + self.infostring = ' %d' % size + self.accessible = True + self.runnable = True + return size + + @lazy_property + def infostring(self): + self.size # trigger the lazy property initializer + if self.is_link: + return '->' + self.infostring + return self.infostring + + @lazy_property + def runnable(self): + self.size # trigger the lazy property initializer + return self.runnable + def sort_if_outdated(self): """Sort the containing files if they are outdated""" if self.order_outdated: |