summary refs log tree commit diff stats
path: root/code/directory.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-23 22:26:35 +0100
committerhut <hut@lavabit.com>2009-11-23 22:26:35 +0100
commit92abe81a0d72dc4e12eb4702e9c1a5241a924c59 (patch)
tree718d42ac33983ede79e4ea9290205df700175625 /code/directory.py
parentb0f0027f94a9619652392f1df9ad6c7346f46c0f (diff)
downloadranger-92abe81a0d72dc4e12eb4702e9c1a5241a924c59.tar.gz
added the ability to freeze/clone directory objects
Diffstat (limited to 'code/directory.py')
-rw-r--r--code/directory.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/code/directory.py b/code/directory.py
index 4cb9fd72..d8855432 100644
--- a/code/directory.py
+++ b/code/directory.py
@@ -1,3 +1,4 @@
+class FrozenException(Exception): pass
 
 class Directory():
 	def __init__(self, path):
@@ -8,8 +9,11 @@ class Directory():
 		self.mtime = None
 		self.exists = True
 
+		self.frozen = False
+
 	def load_files(self):
 		import os
+		if self.frozen: raise FrozenException()
 		try:
 			self.files = os.listdir(self.path)
 			self.exists = True
@@ -18,6 +22,17 @@ class Directory():
 			self.exists = False
 		self.files_loaded = True
 
+	def clone(self):
+		clone = Directory(self.path)
+		for key in iter(self.__dict__):
+			clone.__dict__[key] = self.__dict__[key]
+		return clone
+
+	def frozenClone(self):
+		clone = self.clone()
+		clone.frozen = True
+		return clone
+
 	def __len__(self):
 		return len(self.files)