summary refs log tree commit diff stats
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
parent92abe81a0d72dc4e12eb4702e9c1a5241a924c59 (diff)
downloadranger-4f2df30807d145ff78ca7db8ca5601187e1f6e03.tar.gz
in directory.py raise errors if not loaded yet
-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__':