summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-23 22:27:15 +0100
committerhut <hut@lavabit.com>2009-11-23 22:27:15 +0100
commit4f2df30807d145ff78ca7db8ca5601187e1f6e03 (patch)
treeeab75f14f780882415bf3fe6229c2ea2c908da42 /code
parent92abe81a0d72dc4e12eb4702e9c1a5241a924c59 (diff)
downloadranger-4f2df30807d145ff78ca7db8ca5601187e1f6e03.tar.gz
in directory.py raise errors if not loaded yet
Diffstat (limited to 'code')
-rw-r--r--code/directory.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/code/directory.py b/code/directory.py
index d8855432..e28bf35c 100644
--- a/code/directory.py
+++ b/code/directory.py
@@ -1,8 +1,10 @@
 class FrozenException(Exception): pass
+class NotLoadedYet(Exception): pass
 
 class Directory():
 	def __init__(self, path):
 		self.path = path
+		self.accessible = False
 		self.files_loaded = False
 		self.scheduled = False
 		self.files = None
@@ -17,9 +19,11 @@ class Directory():
 		try:
 			self.files = os.listdir(self.path)
 			self.exists = True
+			self.accessible = True
 		except OSError:
-			self.files = []
+			self.files = None
 			self.exists = False
+			self.accessible = False
 		self.files_loaded = True
 
 	def clone(self):
@@ -34,9 +38,11 @@ class Directory():
 		return clone
 
 	def __len__(self):
+		if not self.accessible: raise NotLoadedYet()
 		return len(self.files)
 	
 	def __getitem__(self, key):
+		if not self.accessible: raise NotLoadedYet()
 		return self.files[key]
 
 if __name__ == '__main__':
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236