summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-04-19 18:12:05 +0200
committerhut <hut@lavabit.com>2011-04-19 18:12:23 +0200
commit7c33d7792efa6c4a1e56310c18ff04a721a2ea50 (patch)
tree0cf0fcc3f183f6050aebdc39af5a0cd29496b41d /ranger
parent47c394e3836699c5920965fee4c20d7a20343b32 (diff)
downloadranger-7c33d7792efa6c4a1e56310c18ff04a721a2ea50.tar.gz
use lazy_property for Directory.size/infostring
for more passive and faster loading of directories
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/actions.py2
-rw-r--r--ranger/fsobject/directory.py27
-rw-r--r--ranger/fsobject/fsobject.py14
3 files changed, 30 insertions, 13 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 4ea4cfbf..89bd9389 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -206,7 +206,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 				if not self.env.enter_dir(cf) and selection:
 					if self.execute_file(selection, mode=mode) is False:
 						self.open_console('open_with ')
-			elif direction.vertical():
+			elif direction.vertical() and cwd.files:
 				newpos = direction.move(
 						direction=direction.down(),
 						override=narg,
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:
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py
index bf71ac94..647b7604 100644
--- a/ranger/fsobject/fsobject.py
+++ b/ranger/fsobject/fsobject.py
@@ -231,20 +231,10 @@ class FileSystemObject(FileManagerAware):
 			else:
 				self.size = 0
 				self.infostring = '?'
-		elif self.is_directory:
-			try:
-				self.size = len(listdir(path))  # bite me
-			except OSError:
-				self.size = 0
-				self.infostring = '?'
-				self.accessible = False
-			else:
-				self.infostring = ' %d' % self.size
-				self.accessible = True
-				self.runnable = True
 		if is_link:
-			self.infostring = '->' + self.infostring
 			self.is_link = True
+			if not self.is_directory:
+				self.infostring = '->' + self.infostring
 
 		self.stat = new_stat