summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-05-05 22:45:22 +0200
committerhut <hut@lavabit.com>2010-05-05 22:45:22 +0200
commitc6953a55e46aee37a854dff3be5d965b19a7341a (patch)
tree8ab0bfc30ce640e879f6d75b5dc639cf64101e4d
parentda440d3a10b7ab05e9b55968344fff2cbc45da09 (diff)
downloadranger-c6953a55e46aee37a854dff3be5d965b19a7341a.tar.gz
cleanups
-rw-r--r--ranger/__main__.py2
-rw-r--r--ranger/core/environment.py8
-rw-r--r--ranger/core/fm.py2
-rw-r--r--ranger/defaults/commands.py2
-rw-r--r--ranger/fsobject/__init__.py6
-rw-r--r--ranger/fsobject/directory.py14
-rw-r--r--ranger/fsobject/file.py8
-rw-r--r--test/tc_directory.py7
-rw-r--r--test/tc_newkeys.py2
9 files changed, 21 insertions, 30 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py
index 8bb0bfa1..d63ec63b 100644
--- a/ranger/__main__.py
+++ b/ranger/__main__.py
@@ -35,7 +35,7 @@ from ranger.core.environment import Environment
 from ranger.shared import (EnvironmentAware, FileManagerAware,
 		SettingsAware)
 from ranger.gui.defaultui import DefaultUI as UI
-from ranger.fsobject.file import File
+from ranger.fsobject import File
 
 def parse_arguments():
 	"""Parse the program arguments"""
diff --git a/ranger/core/environment.py b/ranger/core/environment.py
index a485e277..296ba108 100644
--- a/ranger/core/environment.py
+++ b/ranger/core/environment.py
@@ -19,7 +19,7 @@ import pwd
 import socket
 from os.path import abspath, normpath, join, expanduser, isdir
 
-from ranger.fsobject.directory import Directory, NoDirectoryGiven
+from ranger.fsobject import Directory
 from ranger.container import KeyBuffer, KeyManager, History
 from ranger.ext.signal_dispatcher import SignalDispatcher
 from ranger.shared import SettingsAware
@@ -179,12 +179,8 @@ class Environment(SettingsAware, SignalDispatcher):
 		path = normpath(join(self.path, expanduser(path)))
 
 		if not isdir(path):
-			return
-
-		try:
-			new_cwd = self.get_directory(path)
-		except NoDirectoryGiven:
 			return False
+		new_cwd = self.get_directory(path)
 
 		try:
 			os.chdir(path)
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 0702e472..dfad3425 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -30,7 +30,7 @@ from ranger.container import Bookmarks
 from ranger.core.runner import Runner
 from ranger import relpath_conf
 from ranger.ext.get_executables import get_executables
-from ranger.fsobject.directory import Directory
+from ranger.fsobject import Directory
 from ranger.ext.signal_dispatcher import SignalDispatcher
 from ranger import __version__
 from ranger.core.loader import Loader
diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py
index 3fdf4ade..278fb8d5 100644
--- a/ranger/defaults/commands.py
+++ b/ranger/defaults/commands.py
@@ -412,7 +412,7 @@ class rename(Command):
 	"""
 
 	def execute(self):
-		from ranger.fsobject.file import File
+		from ranger.fsobject import File
 		line = parse(self.line)
 		if not line.rest(1):
 			return self.fm.notify('Syntax: rename <newname>', bad=True)
diff --git a/ranger/fsobject/__init__.py b/ranger/fsobject/__init__.py
index cd3944c3..5fb4b877 100644
--- a/ranger/fsobject/__init__.py
+++ b/ranger/fsobject/__init__.py
@@ -18,9 +18,7 @@ with fast access to their properties through caching"""
 
 BAD_INFO = '?'
 
-class NotLoadedYet(Exception):
-	pass
-
+# So they can be imported from other files more easily:
 from .fsobject import FileSystemObject
 from .file import File
-from .directory import Directory, NoDirectoryGiven
+from .directory import Directory
diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py
index 43af772a..ca071510 100644
--- a/ranger/fsobject/directory.py
+++ b/ranger/fsobject/directory.py
@@ -13,7 +13,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
+import os.path
 from collections import deque
 from time import time
 
@@ -34,9 +34,6 @@ def sort_by_directory(path):
 	"""returns 0 if path is a directory, otherwise 1 (for sorting)"""
 	return 1 - path.is_directory
 
-class NoDirectoryGiven(Exception):
-	pass
-
 class Directory(FileSystemObject, Accumulator, SettingsAware):
 	is_directory = True
 	enterable = False
@@ -69,10 +66,7 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 	}
 
 	def __init__(self, path):
-		from os.path import isfile
-
-		if isfile(path):
-			raise NoDirectoryGiven()
+		assert not os.path.isfile(path), "No directory given!"
 
 		Accumulator.__init__(self)
 		FileSystemObject.__init__(self, path)
@@ -402,8 +396,8 @@ class Directory(FileSystemObject, Accumulator, SettingsAware):
 
 	def __len__(self):
 		"""The number of containing files"""
-		if not self.accessible or not self.content_loaded:
-			raise ranger.fsobject.NotLoadedYet()
+		assert self.accessible
+		assert self.content_loaded
 		assert self.files is not None
 		return len(self.files)
 
diff --git a/ranger/fsobject/file.py b/ranger/fsobject/file.py
index aa44016e..4618df33 100644
--- a/ranger/fsobject/file.py
+++ b/ranger/fsobject/file.py
@@ -13,11 +13,12 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-control_characters = set(chr(n) for n in set(range(0, 9)) | set(range(14,32)))
 N_FIRST_BYTES = 20
+control_characters = set(chr(n) for n in
+		set(range(0, 9)) | set(range(14, 32)))
 
-from .fsobject import FileSystemObject as SuperClass
-class File(SuperClass):
+from ranger.fsobject import FileSystemObject
+class File(FileSystemObject):
 	is_file = True
 
 	@property
@@ -37,4 +38,3 @@ class File(SuperClass):
 		if self.firstbytes and control_characters & set(self.firstbytes):
 			return True
 		return False
-
diff --git a/test/tc_directory.py b/test/tc_directory.py
index f1b204c3..024ebc9d 100644
--- a/test/tc_directory.py
+++ b/test/tc_directory.py
@@ -15,6 +15,7 @@
 
 if __name__ == '__main__': from __init__ import init; init()
 
+import sys
 from os.path import realpath, join, dirname
 
 from ranger import fsobject
@@ -38,7 +39,8 @@ class Test1(unittest.TestCase):
 		self.assertFalse(dir.content_loaded)
 		self.assertEqual(dir.filenames, None)
 		self.assertEqual(dir.files, None)
-		self.assertRaises(fsobject.NotLoadedYet, len, dir)
+		if not sys.flags.optimize:  # asserts are ignored with python -O
+			self.assertRaises(AssertionError, len, dir)
 
 	def test_after_content_loaded(self):
 		import os
@@ -79,7 +81,8 @@ class Test1(unittest.TestCase):
 		self.assertFalse(dir.exists)
 		self.assertFalse(dir.accessible)
 		self.assertEqual(dir.filenames, None)
-		self.assertRaises(fsobject.NotLoadedYet, len, dir)
+		if not sys.flags.optimize:  # asserts are ignored with python -O
+			self.assertRaises(AssertionError, len, dir)
 
 	def test_load_if_outdated(self):
 		import os
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py
index 2a44e0e8..c7a33025 100644
--- a/test/tc_newkeys.py
+++ b/test/tc_newkeys.py
@@ -424,7 +424,7 @@ class Test(PressTestCase):
 		self.assertPressFails(kb, 'xzy')
 		self.assertPressIncomplete(kb, 'xx')
 		self.assertPressIncomplete(kb, 'x')
-		if not sys.flags.optimize:
+		if not sys.flags.optimize:  # asserts are ignored with python -O
 			self.assertRaises(AssertionError, simulate_press, kb, 'xxx')
 		kb.clear()