about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-19 19:54:02 +0200
committerhut <hut@lavabit.com>2010-04-19 20:17:44 +0200
commiteaaeed3da091fb293825403025dcc4a6dbd4dce3 (patch)
tree15b4db09276e8d85ca5a285e617a0c3c6ca2aae0
parentbf74ace46aa195414df0dcc9dcd57c8941589b44 (diff)
downloadranger-eaaeed3da091fb293825403025dcc4a6dbd4dce3.tar.gz
Clean up
Mostly remove unused imports and move imports from functions to
the module level
-rw-r--r--ranger/__main__.py33
-rw-r--r--ranger/api/apps.py1
-rw-r--r--ranger/container/bookmarks.py5
-rw-r--r--ranger/container/history.py3
-rw-r--r--ranger/container/tags.py3
-rw-r--r--ranger/core/environment.py3
-rw-r--r--ranger/core/fm.py7
-rw-r--r--ranger/ext/human_readable.py4
-rw-r--r--ranger/gui/colorscheme.py7
-rw-r--r--ranger/gui/defaultui.py13
-rw-r--r--ranger/gui/ui.py1
-rw-r--r--ranger/gui/widgets/browsercolumn.py5
-rw-r--r--ranger/gui/widgets/console.py3
-rw-r--r--ranger/gui/widgets/titlebar.py2
-rw-r--r--ranger/shared/settings.py2
15 files changed, 39 insertions, 53 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py
index b9847bf5..cbb87cc2 100644
--- a/ranger/__main__.py
+++ b/ranger/__main__.py
@@ -20,13 +20,24 @@ import os
 import sys
 import ranger
 
+from optparse import OptionParser, SUPPRESS_HELP
+from ranger.ext.openstruct import OpenStruct
+from ranger import __version__, USAGE, DEFAULT_CONFDIR
+import ranger.api.commands
+
+from signal import signal, SIGINT
+from locale import getdefaultlocale, setlocale, LC_ALL
+
+from ranger.ext import curses_interrupt_handler
+from ranger.core.fm import FM
+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
+
 def parse_arguments():
 	"""Parse the program arguments"""
-
-	from optparse import OptionParser, SUPPRESS_HELP
-	from ranger.ext.openstruct import OpenStruct
-	from ranger import __version__, USAGE, DEFAULT_CONFDIR
-
 	parser = OptionParser(usage=USAGE, version='ranger ' + __version__)
 
 	parser.add_option('-d', '--debug', action='store_true',
@@ -50,7 +61,6 @@ def parse_arguments():
 
 
 def load_settings(fm, clean):
-	import ranger.api.commands
 	if not clean:
 		try:
 			os.makedirs(ranger.arg.confdir)
@@ -118,17 +128,6 @@ def main():
 		print('ranger requires the python curses module. Aborting.')
 		sys.exit(1)
 
-	from signal import signal, SIGINT
-	from locale import getdefaultlocale, setlocale, LC_ALL
-
-	from ranger.ext import curses_interrupt_handler
-	from ranger.core.fm import FM
-	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
-
 	# Ensure that a utf8 locale is set.
 	if getdefaultlocale()[1] not in ('utf8', 'UTF-8'):
 		for locale in ('en_US.utf8', 'en_US.UTF-8'):
diff --git a/ranger/api/apps.py b/ranger/api/apps.py
index 309c0db6..126f9c2a 100644
--- a/ranger/api/apps.py
+++ b/ranger/api/apps.py
@@ -18,7 +18,6 @@ This module provides helper functions/classes for ranger.apps.
 """
 
 import os, sys, re
-from subprocess import Popen, PIPE
 from ranger.ext.iter_tools import flatten
 from ranger.ext.get_executables import get_executables
 from ranger.shared import FileManagerAware
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py
index d4e12f62..f06b7498 100644
--- a/ranger/container/bookmarks.py
+++ b/ranger/container/bookmarks.py
@@ -15,7 +15,7 @@
 
 import string
 import re
-import os
+import os.path
 ALLOWED_KEYS = string.ascii_letters + string.digits + "`'"
 
 class Bookmarks(object):
@@ -148,7 +148,6 @@ class Bookmarks(object):
 	def save(self):
 		"""Save the bookmarks to the bookmarkfile.
 		This is done automatically after every modification if autosave is True."""
-		import os
 		self.update()
 		if self.path is None:
 			return
@@ -163,7 +162,6 @@ class Bookmarks(object):
 		self._update_mtime()
 
 	def _load_dict(self):
-		import os
 		dct = {}
 
 		if self.path is None:
@@ -198,7 +196,6 @@ class Bookmarks(object):
 		self._update_mtime()
 
 	def _get_mtime(self):
-		import os
 		if self.path is None:
 			return None
 		try:
diff --git a/ranger/container/history.py b/ranger/container/history.py
index d2c48e4a..ba13775d 100644
--- a/ranger/container/history.py
+++ b/ranger/container/history.py
@@ -13,12 +13,13 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from collections import deque
+
 class HistoryEmptyException(Exception):
 	pass
 
 class History(object):
 	def __init__(self, maxlen = None):
-		from collections import deque
 		self.history = deque(maxlen = maxlen)
 		self.history_forward = deque(maxlen = maxlen)
 
diff --git a/ranger/container/tags.py b/ranger/container/tags.py
index 11ac3a5d..9ef8a1b2 100644
--- a/ranger/container/tags.py
+++ b/ranger/container/tags.py
@@ -13,9 +13,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from os.path import isdir, exists, dirname, abspath, realpath, expanduser
+
 class Tags(object):
 	def __init__(self, filename):
-		from os.path import isdir, exists, dirname, abspath, realpath, expanduser
 
 		self._filename = realpath(abspath(expanduser(filename)))
 
diff --git a/ranger/core/environment.py b/ranger/core/environment.py
index 6b2d692c..a485e277 100644
--- a/ranger/core/environment.py
+++ b/ranger/core/environment.py
@@ -145,8 +145,7 @@ class Environment(SettingsAware, SignalDispatcher):
 			return obj
 
 	def get_free_space(self, path):
-		from os import statvfs
-		stat = statvfs(path)
+		stat = os.statvfs(path)
 		return stat.f_bavail * stat.f_bsize
 
 	def assign_cursor_positions_for_subdirs(self):
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 1124f355..a426a9ae 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -24,10 +24,13 @@ import sys
 
 import ranger
 from ranger.core.actions import Actions
+from ranger.container.tags import Tags
+from ranger.gui.defaultui import DefaultUI
 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.ext.signal_dispatcher import SignalDispatcher
 from ranger import __version__
 from ranger.fsobject import Loader
@@ -63,8 +66,6 @@ class FM(Actions, SignalDispatcher):
 
 	def initialize(self):
 		"""If ui/bookmarks are None, they will be initialized here."""
-		from ranger.fsobject.directory import Directory
-
 		if self.bookmarks is None:
 			if ranger.arg.clean:
 				bookmarkfile = None
@@ -79,12 +80,10 @@ class FM(Actions, SignalDispatcher):
 		else:
 			self.bookmarks = bookmarks
 
-		from ranger.container.tags import Tags
 		if not ranger.arg.clean and self.tags is None:
 			self.tags = Tags(relpath_conf('tagged'))
 
 		if self.ui is None:
-			from ranger.gui.defaultui import DefaultUI
 			self.ui = DefaultUI()
 			self.ui.initialize()
 
diff --git a/ranger/ext/human_readable.py b/ranger/ext/human_readable.py
index c8c15946..1a3d1ec9 100644
--- a/ranger/ext/human_readable.py
+++ b/ranger/ext/human_readable.py
@@ -13,13 +13,13 @@
 # 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 math
+
 ONE_KB = 1024
 UNITS = 'BKMGTP'
 MAX_EXPONENT = len(UNITS) - 1
 
 def human_readable(byte, seperator=' '):
-	import math
-
 	if not byte:
 		return '0'
 
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index dffacffb..8c81763f 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -43,7 +43,6 @@ colorscheme = colorschemes.filename.classname
 
 import os
 from curses import color_pair
-from inspect import isclass, ismodule
 
 import ranger
 from ranger.gui.color import get_color
@@ -134,7 +133,10 @@ def _colorscheme_name_to_class(signal):
 		return os.path.exists(colorscheme + '.py')
 
 	def is_scheme(x):
-		return isclass(x) and issubclass(x, ColorScheme)
+		try:
+			return issubclass(x, ColorScheme)
+		except:
+			return False
 
 	# create ~/.ranger/colorschemes/__init__.py if it doesn't exist
 	if usecustom:
@@ -160,7 +162,6 @@ def _colorscheme_name_to_class(signal):
 	else:
 		scheme_module = getattr(__import__(scheme_supermodule,
 				globals(), locals(), [scheme_name], 0), scheme_name)
-		assert ismodule(scheme_module)
 		if hasattr(scheme_module, 'Scheme') \
 				and is_scheme(scheme_module.Scheme):
 			signal.value = scheme_module.Scheme()
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index a0a5da4e..4baea756 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -14,17 +14,16 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from ranger.gui.ui import UI
+from ranger.gui.widgets.browserview import BrowserView
+from ranger.gui.widgets.titlebar import TitleBar
+from ranger.gui.widgets.console import Console
+from ranger.gui.widgets.statusbar import StatusBar
+from ranger.gui.widgets.taskview import TaskView
+from ranger.gui.widgets.pager import Pager
 
 class DefaultUI(UI):
 	def setup(self):
 		"""Build up the UI by initializing widgets."""
-		from ranger.gui.widgets.browserview import BrowserView
-		from ranger.gui.widgets.titlebar import TitleBar
-		from ranger.gui.widgets.console import Console
-		from ranger.gui.widgets.statusbar import StatusBar
-		from ranger.gui.widgets.taskview import TaskView
-		from ranger.gui.widgets.pager import Pager
-
 		# Create a title bar
 		self.titlebar = TitleBar(self.win)
 		self.add_child(self.titlebar)
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index a2a54d9e..e40003a2 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -14,7 +14,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
-import socket
 import sys
 import curses
 import _curses
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index d7dbac4f..b193a523 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -87,15 +87,13 @@ class BrowserColumn(Pager):
 
 	def click(self, event):
 		"""Handle a MouseEvent"""
-		from ranger.fsobject.fsobject import T_DIRECTORY
-
 		if not (event.pressed(1) or event.pressed(3)):
 			return False
 
 		if self.target is None:
 			pass
 
-		elif self.target.type is T_DIRECTORY:
+		elif self.target.is_directory:
 			if self.target.accessible and self.target.content_loaded:
 				index = self.scroll_begin + event.y - self.y
 
@@ -209,7 +207,6 @@ class BrowserColumn(Pager):
 
 	def _draw_directory(self):
 		"""Draw the contents of a directory"""
-		import stat
 
 		if self.level > 0 and not self.settings.preview_directories:
 			return
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 0aa1f147..59a779de 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -20,7 +20,6 @@ commands, searching and executing files.
 
 import string
 import curses
-import re
 from collections import deque
 
 from . import Widget
@@ -220,8 +219,6 @@ class Console(Widget):
 		self.history.modify(self.line)
 
 	def move(self, **keywords):
-		from ranger import log
-		log(keywords)
 		direction = Direction(keywords)
 		if direction.horizontal():
 			self.pos = direction.move(
diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py
index 20ae62b4..17da7748 100644
--- a/ranger/gui/widgets/titlebar.py
+++ b/ranger/gui/widgets/titlebar.py
@@ -20,7 +20,6 @@ It displays the current path among other things.
 """
 
 from os.path import basename
-from math import floor
 
 from . import Widget
 from ranger.gui.bar import Bar
@@ -151,7 +150,6 @@ class TitleBar(Widget):
 			return ' ' + str(tabname)
 
 	def _print_result(self, result):
-		import _curses
 		self.win.move(0, 0)
 		for part in result:
 			self.color(*part.lst)
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index 1822c38a..f5d8614f 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
+from inspect import isfunction
 import ranger
 from ranger.ext.signal_dispatcher import SignalDispatcher
 from ranger.ext.openstruct import OpenStruct
@@ -107,7 +108,6 @@ class SettingObject(SignalDispatcher):
 
 
 	def _check_type(self, name, value):
-		from inspect import isfunction
 		typ = ALLOWED_SETTINGS[name]
 		if isfunction(typ):
 			assert typ(value), \