summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parentda440d3a10b7ab05e9b55968344fff2cbc45da09 (diff)
downloadranger-c6953a55e46aee37a854dff3be5d965b19a7341a.tar.gz
cleanups
Diffstat (limited to 'ranger')
-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
7 files changed, 15 insertions, 27 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
-