summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-14 12:44:36 +0100
committerhut <hut@lavabit.com>2009-12-14 12:44:36 +0100
commit733dbb9dbb608e8a0dec0e836c07b1dd7feb4d17 (patch)
tree61abfcb17d15108307bf2ca19201232c601f0d86
parent1159f9ec182496ddc5324f23fb1d5eae73fe63e3 (diff)
downloadranger-733dbb9dbb608e8a0dec0e836c07b1dd7feb4d17.tar.gz
Don't initialize options while importing.
-rw-r--r--ranger/__init__.py2
-rw-r--r--ranger/defaults/keys.py7
-rw-r--r--ranger/shared/settings.py79
3 files changed, 46 insertions, 42 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py
index 484ddbdd..b934d80c 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -35,6 +35,7 @@ def main():
 
 	from ranger.fm import FM
 	from ranger.container.environment import Environment
+	from ranger.shared.settings import SettingsAware
 	from ranger.gui.defaultui import DefaultUI as UI
 	from ranger.fsobject.file import File
 
@@ -75,6 +76,7 @@ def main():
 	else:
 		path = '.'
 
+	SettingsAware._setup()
 	Environment(path)
 
 	try:
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index ffd37646..29658dac 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -1,10 +1,11 @@
 import curses
 from curses.ascii import ctrl, ESC
+from ranger.actions import Actions as do
+from ranger.gui.widgets.console import Console
+from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
 
 def initialize_commands(command_list):
 	"""Initialize the commands for the main user interface"""
-	from ranger.actions import Actions as do
-	from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
 
 	def bind(fnc, *keys):
 		command_list.bind(fnc, *keys)
@@ -91,8 +92,6 @@ def initialize_commands(command_list):
 
 def initialize_console_commands(command_list):
 	"""Initialize the commands for the console widget only"""
-	from ranger.actions import Actions as do
-	from ranger.gui.widgets.console import Console
 
 	def bind(fnc, *keys):
 		command_list.bind(fnc, *keys)
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index cf1c00c8..820e81b0 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -1,49 +1,52 @@
-from inspect import isclass, ismodule
-from ranger.ext.openstruct import OpenStruct
-from ranger.gui.colorscheme import ColorScheme
-
 ALLOWED_SETTINGS = """
 show_hidden scroll_offset directories_first
 preview_files max_history_size colorscheme
 apps keys
 """.split()
 
-# overwrite single default options with custom options
-from ranger.defaults import options
-try:
-	import options as custom_options
-	for setting in ALLOWED_SETTINGS:
-		if hasattr(custom_options, setting):
-			setattr(options, setting, getattr(custom_options, setting))
-		elif not hasattr(options, setting):
-			raise Exception("Following option was not defined: " + setting)
-except ImportError:
-	pass
-
-# If a module is specified as the colorscheme, replace it with one
-# valid colorscheme inside that module.
-
-if isclass(options.colorscheme) and \
-		issubclass(options.colorscheme, ColorScheme):
-	options.colorscheme = options.colorscheme()
-
-elif ismodule(options.colorscheme):
-	for var_name in dir(options.colorscheme):
-		var = getattr(options.colorscheme, var_name)
-		if var != ColorScheme and isclass(var) and issubclass(var, ColorScheme):
-			options.colorscheme = var()
-			break
-	else:
-		raise Exception("The colorscheme module contains no valid colorscheme!")
-
-else:
-	raise Exception("Cannot locate colorscheme!")
-
-
 # -- globalize the settings --
+
+from ranger.ext.openstruct import OpenStruct
 class SettingsAware(object):
 	settings = OpenStruct()
 
-for setting in ALLOWED_SETTINGS:
-	SettingsAware.settings[setting] = getattr(options, setting)
+	@staticmethod
+	def _setup():
+		from inspect import isclass, ismodule
+		from ranger.gui.colorscheme import ColorScheme
+
+		# overwrite single default options with custom options
+		from ranger.defaults import options
+		try:
+			import options as custom_options
+			for setting in ALLOWED_SETTINGS:
+				if hasattr(custom_options, setting):
+					setattr(options, setting, getattr(custom_options, setting))
+				elif not hasattr(options, setting):
+					raise Exception("Following option was not defined: " + setting)
+		except ImportError:
+			pass
+
+		# If a module is specified as the colorscheme, replace it with one
+		# valid colorscheme inside that module.
+
+		if isclass(options.colorscheme) and \
+				issubclass(options.colorscheme, ColorScheme):
+			options.colorscheme = options.colorscheme()
+
+		elif ismodule(options.colorscheme):
+			for var_name in dir(options.colorscheme):
+				var = getattr(options.colorscheme, var_name)
+				if var != ColorScheme and isclass(var) \
+						and issubclass(var, ColorScheme):
+					options.colorscheme = var()
+					break
+			else:
+				raise Exception("The module contains no valid colorscheme!")
+
+		else:
+			raise Exception("Cannot locate colorscheme!")
+
+		for setting in ALLOWED_SETTINGS:
+			SettingsAware.settings[setting] = getattr(options, setting)
 
79'>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