summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-24 01:09:32 +0100
committerhut <hut@lavabit.com>2009-11-24 01:09:32 +0100
commit556d84cd0fa94372c3fc2eb722f6925e61c42778 (patch)
tree986954f8d1ac5ac5c38e9b7bf2930e83641163b7 /code
parentfae694a03ebb52888a747010fcb92fa43b33b4a8 (diff)
downloadranger-556d84cd0fa94372c3fc2eb722f6925e61c42778.tar.gz
tweaks
Diffstat (limited to 'code')
-rw-r--r--code/directory.py1
-rw-r--r--code/file.py2
-rw-r--r--code/fsobject.py47
-rw-r--r--code/fstype.py5
4 files changed, 38 insertions, 17 deletions
diff --git a/code/directory.py b/code/directory.py
index 10ad163c..ef68d35f 100644
--- a/code/directory.py
+++ b/code/directory.py
@@ -10,6 +10,7 @@ class Directory(fsobject.FSObject):
 
 		self.filenames = None
 		self.files = None
+		self.filter = None
 		self.pointed_index = None
 	
 	def load_content(self):
diff --git a/code/file.py b/code/file.py
index 291e53b2..9d813aad 100644
--- a/code/file.py
+++ b/code/file.py
@@ -3,4 +3,4 @@ class File(fsobject.FSObject):
 	pass
 #	def __init__(self, path):
 #		fsobject.FSObject.__init__(self, path)
-		
+
diff --git a/code/fsobject.py b/code/fsobject.py
index d1cd1410..1e194ac9 100644
--- a/code/fsobject.py
+++ b/code/fsobject.py
@@ -1,8 +1,12 @@
+import fstype
+
 class FrozenException(Exception): pass
 class NotLoadedYet(Exception): pass
 
 class FSObject(object):
 	def __init__(self, path):
+		if type(self) == FSObject:
+			raise TypeError("FSObject is an abstract class and cannot be initialized.")
 		self.path = path
 		self.exists = False
 		self.accessible = False
@@ -10,14 +14,13 @@ class FSObject(object):
 		self.tagged = False
 		self.frozen = False
 		self.loaded = False
+		self.islink = False
+		self.brokenlink = False
 		self.stat = None
+		self.type = fstype.Unknown
 
-	def clone(self):
-		clone = type(self)(self.path)
-		for key in iter(self.__dict__):
-			clone.__dict__[key] = self.__dict__[key]
-		return clone
-
+	# load() reads useful information about the file from the file system
+	# and caches it in instance attributes.
 	def load(self):
 		self.stop_if_frozen()
 		self.loaded = True
@@ -25,23 +28,32 @@ class FSObject(object):
 		import os
 		try:
 			self.stat = os.stat(self.path)
+			self.islink = os.path.islink(self.path)
 			self.exists = True
 			self.accessible = True
+
+			if os.path.isdir(self.path):
+				self.type = fstype.Directory
+			elif os.path.isfile(self.path):
+				self.type = fstype.File
 		except OSError:
+			self.islink = False
+			self.type = fstype.Nonexistent
 			self.exists = False
 			self.accessible = False
 
 	def load_once(self):
 		self.stop_if_frozen()
-		if not self.loaded: self.load()
+		if not self.loaded:
+			self.load()
+			return True
+		return False
 
 	def load_if_outdated(self):
 		self.stop_if_frozen()
 		import os
 
-		if not self.loaded:
-			self.load()
-			return True
+		if self.load_once(): return True
 
 		real_mtime = os.stat(self.path).st_mtime
 		cached_mtime = self.stat.st_mtime
@@ -52,14 +64,17 @@ class FSObject(object):
 
 		return False
 
+	def clone(self):
+		clone = type(self)(self.path)
+		for key in iter(self.__dict__):
+			clone.__dict__[key] = self.__dict__[key]
+		return clone
+
 	def frozen_clone(self):
-		self.stop_if_frozen()
-		return self.clone().freeze()
+		clone = self.clone()
+		clone.frozen = True
+		return clone
 
 	def stop_if_frozen(self):
 		if self.frozen: raise FrozenException()
 
-	def freeze(self):
-		self.frozen = True
-		return self
-
diff --git a/code/fstype.py b/code/fstype.py
new file mode 100644
index 00000000..4bd0988d
--- /dev/null
+++ b/code/fstype.py
@@ -0,0 +1,5 @@
+class File: pass
+class Directory: pass
+class Nonexistent: pass
+class Unknown: pass
+
n335' href='#n335'>335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452