about summary refs log tree commit diff stats
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
parent47c394e3836699c5920965fee4c20d7a20343b32 (diff)
downloadranger-7c33d7792efa6c4a1e56310c18ff04a721a2ea50.tar.gz
use lazy_property for Directory.size/infostring
for more passive and faster loading of directories
-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
 
830bd24724f945e0d6ddf6a06adc0e'>77d5b5d6 ^
4c3e1f07 ^

87ef6a67 ^

1ead3562 ^
77d5b5d6 ^
4c3e1f07 ^



87ef6a67 ^

455fbac6 ^








87ef6a67 ^







fca48e92 ^
1ead3562 ^
fca48e92 ^
fca48e92 ^
455fbac6 ^
fca48e92 ^



afb467ea ^
1ead3562 ^
afb467ea ^
afb467ea ^
455fbac6 ^
afb467ea ^



1ead3562 ^
fca48e92 ^
fca48e92 ^


fca48e92 ^
1ead3562 ^
fca48e92 ^




455fbac6 ^
fca48e92 ^
1ead3562 ^
fca48e92 ^

455fbac6 ^
fca48e92 ^


afb467ea ^




1ead3562 ^
afb467ea ^





1ead3562 ^
afb467ea ^

455fbac6 ^
afb467ea ^
fca48e92 ^

67bc24e7 ^

455fbac6 ^
67bc24e7 ^
c9b98c21 ^
67bc24e7 ^


c9b98c21 ^
67bc24e7 ^

afb467ea ^


455fbac6 ^

afb467ea ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133