about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xranger.py9
-rw-r--r--ranger/bookmark.py5
-rw-r--r--ranger/colorschemes/__init__.py22
-rw-r--r--ranger/colorschemes/snow.py (renamed from ranger/conf/colorschemes/snow.py)2
-rw-r--r--ranger/conf/__init__.py18
-rw-r--r--ranger/defaults/__init__.py (renamed from ranger/conf/colorschemes/__init__.py)0
-rw-r--r--ranger/defaults/apps.py (renamed from ranger/conf/apps.py)0
-rw-r--r--ranger/defaults/keys.py (renamed from ranger/conf/keys.py)0
-rw-r--r--ranger/defaults/options.py (renamed from ranger/conf/options.py)5
-rw-r--r--ranger/fm.py5
-rw-r--r--ranger/gui/colorscheme.py24
-rw-r--r--ranger/gui/wconsole.py4
-rw-r--r--ranger/helper.py9
-rw-r--r--ranger/main.py28
-rw-r--r--ranger/mimetype.py2
15 files changed, 118 insertions, 15 deletions
diff --git a/ranger.py b/ranger.py
index 9a2e59c1..090789c5 100755
--- a/ranger.py
+++ b/ranger.py
@@ -22,9 +22,12 @@ try:
 	from ranger.main import main
 
 except ImportError as errormessage:
-	print(errormessage)
-	print("To run an uninstalled copy of ranger,")
-	print("launch ranger.py in the top directory.")
+	if str(errormessage).endswith("main"):
+		print("Can't import the main module.")
+		print("To run an uninstalled copy of ranger,")
+		print("launch ranger.py in the top directory.")
+	else:
+		raise
 
 else:
 	main()
diff --git a/ranger/bookmark.py b/ranger/bookmark.py
index 4b931292..da54e8eb 100644
--- a/ranger/bookmark.py
+++ b/ranger/bookmark.py
@@ -37,7 +37,10 @@ class Bookmarks(object):
 
 	def get_mtime(self):
 		import os
-		return os.stat(self.path).st_mtime
+		try:
+			return os.stat(self.path).st_mtime
+		except OSError:
+			return None
 
 	def load(self):
 		try:
diff --git a/ranger/colorschemes/__init__.py b/ranger/colorschemes/__init__.py
new file mode 100644
index 00000000..6319fa96
--- /dev/null
+++ b/ranger/colorschemes/__init__.py
@@ -0,0 +1,22 @@
+from ranger.helper import get_all, log
+from os.path import expanduser, dirname, exists, join
+
+__all__ = get_all(dirname(__file__))
+
+from ranger.colorschemes import *
+
+confpath = expanduser('~/.ranger')
+if exists(join(confpath, 'colorschemes')):
+	initpy = join(confpath, 'colorschemes/__init__.py')
+	if not exists(initpy):
+		open(initpy, 'w').write("""import ranger.helper, os.path
+__all__ = ranger.helper.get_all( os.path.dirname( __file__ ) )
+""")
+
+	try:
+		import sys
+		sys.path[0:0] = [confpath]
+		from colorschemes import *
+	except ImportError:
+		pass
+
diff --git a/ranger/conf/colorschemes/snow.py b/ranger/colorschemes/snow.py
index 017a83db..baad5e43 100644
--- a/ranger/conf/colorschemes/snow.py
+++ b/ranger/colorschemes/snow.py
@@ -1,7 +1,7 @@
 from ranger.gui.colorscheme import ColorScheme
 from ranger.gui.color import *
 
-class MyColorScheme(ColorScheme):
+class Snow(ColorScheme):
 	def use(self, context):
 		fg, bg, attr = default_colors
 
diff --git a/ranger/conf/__init__.py b/ranger/conf/__init__.py
index e69de29b..4c02ae0a 100644
--- a/ranger/conf/__init__.py
+++ b/ranger/conf/__init__.py
@@ -0,0 +1,18 @@
+
+import sys, os
+sys.path[0:0] = [os.path.expanduser('~/.ranger')]
+
+try:
+	import keys
+except ImportError:
+	from ranger.defaults import keys
+
+try:
+	import apps
+except ImportError:
+	from ranger.defaults import apps
+
+try:
+	import options
+except ImportError:
+	from ranger.defaults import options
diff --git a/ranger/conf/colorschemes/__init__.py b/ranger/defaults/__init__.py
index e69de29b..e69de29b 100644
--- a/ranger/conf/colorschemes/__init__.py
+++ b/ranger/defaults/__init__.py
diff --git a/ranger/conf/apps.py b/ranger/defaults/apps.py
index 041b85c8..041b85c8 100644
--- a/ranger/conf/apps.py
+++ b/ranger/defaults/apps.py
diff --git a/ranger/conf/keys.py b/ranger/defaults/keys.py
index dc7362cf..dc7362cf 100644
--- a/ranger/conf/keys.py
+++ b/ranger/defaults/keys.py
diff --git a/ranger/conf/options.py b/ranger/defaults/options.py
index 00d2f9f3..874cf9fb 100644
--- a/ranger/conf/options.py
+++ b/ranger/defaults/options.py
@@ -1,3 +1,7 @@
+from ranger import colorschemes
+
+colorscheme = colorschemes.snow
+
 def get():
 	""" to be implemented. read the options from a file. """
 	pass
@@ -11,3 +15,4 @@ def dummy():
 		'preview_files' : False,
 		'max_history_size': 20
 	}
+
diff --git a/ranger/fm.py b/ranger/fm.py
index 9a13332e..b481086a 100644
--- a/ranger/fm.py
+++ b/ranger/fm.py
@@ -1,12 +1,13 @@
 from os import devnull
-from ranger.conf.apps import CustomApplications as Applications
+#from ranger.conf.apps import CustomApplications as Applications
+from ranger.conf import apps
 null = open(devnull, 'a')
 
 class FM():
 	def __init__(self, environment, ui, bookmarks):
 		self.env = environment
 		self.ui = ui
-		self.apps = Applications()
+		self.apps = apps.CustomApplications()
 		self.bookmarks = bookmarks
 		self.bookmarks.enter_dir_function = self.enter_dir
 
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index d7833016..790112ec 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -8,7 +8,29 @@ CONTEXT_KEYS = [ 'reset', 'error',
 class ColorSchemeContext():
 	pass
 
-class ColorScheme():
+# colorscheme specification:
+#
+# A colorscheme must...
+#
+# 1. be inside either of these directories:
+# ~/.ranger/colorschemes/
+# path/to/ranger/colorschemes/
+#
+# 2. be a subclass ofranger.gui.colorscheme.ColorScheme
+# 
+# 3. have a use(self, context) method which returns a tuple of 3 integers.
+# the first integer is the foreground color, the second is the background
+# color, the third is the attribute, as specified by the curses module.
+#
+#
+# define which colorscheme to use by having this to your options.py:
+# from ranger import colorschemes
+# colorscheme = colorschemes.filename
+# 
+# If your colorscheme-file contains more than one colorscheme, specify it with:
+# colorscheme = colorschemes.filename.classname
+
+class ColorScheme(object):
 	def __init__(self):
 		self.cache = {}
 
diff --git a/ranger/gui/wconsole.py b/ranger/gui/wconsole.py
index 611790f8..9078d781 100644
--- a/ranger/gui/wconsole.py
+++ b/ranger/gui/wconsole.py
@@ -7,12 +7,12 @@ CONSOLE_MODES_DICTIONARY = { '@': 'open with: ' }
 class WConsole(SuperClass):
 	def __init__(self, win, colorscheme):
 		from ranger.command import CommandList
-		from ranger.conf.keys import initialize_console_commands
+		from ranger.conf import keys
 		SuperClass.__init__(self, win, colorscheme)
 		self.mode = None
 		self.visible = False
 		self.commandlist = CommandList()
-		initialize_console_commands(self.commandlist)
+		keys.initialize_console_commands(self.commandlist)
 		self.last_cursor_mode = 1
 		self.clear()
 		self.prompt = None
diff --git a/ranger/helper.py b/ranger/helper.py
index 150f4f9d..0a457837 100644
--- a/ranger/helper.py
+++ b/ranger/helper.py
@@ -12,6 +12,15 @@ ONE_KB = 1024
 UNITS = tuple('BKMGTP')
 NINE_THOUSAND = len(UNITS) - 1
 
+def get_all(dirname):
+	import os
+	lst = []
+	for f in os.listdir(dirname):
+		if f.endswith('.py') and not f.startswith('_'):
+			lst.append(f [0:f.index('.')])
+	return lst
+
+
 def human_readable(byte):
 	import math
 
diff --git a/ranger/main.py b/ranger/main.py
index e6718122..960bab65 100644
--- a/ranger/main.py
+++ b/ranger/main.py
@@ -1,6 +1,7 @@
 import sys
 import os
-import locale
+from inspect import isclass, ismodule
+from locale import setlocale, LC_ALL
 from optparse import OptionParser, SUPPRESS_HELP
 
 from ranger.fm import FM
@@ -9,7 +10,7 @@ from ranger.command import CommandList
 from ranger.bookmark import Bookmarks
 from ranger.conf import keys, options
 from ranger.gui.defaultui import DefaultUI as UI
-from ranger.conf.colorschemes.snow import MyColorScheme
+from ranger.gui.colorscheme import ColorScheme
 
 VERSION = '1.0.0'
 
@@ -23,7 +24,7 @@ def main():
 		print('ranger requires the python curses module. Aborting.')
 		sys.exit(1)
 
-	locale.setlocale(locale.LC_ALL, 'en_US.utf8')
+	setlocale(LC_ALL, 'en_US.utf8')
 	os.stat_float_times(True)
 
 	# Parse options
@@ -63,9 +64,28 @@ def main():
 
 	opt = options.dummy()
 
+	# get colorscheme
+	scheme = options.colorscheme
+	if isclass(scheme) and issubclass(scheme, ColorScheme):
+		colorscheme = scheme()
+
+	elif ismodule(scheme):
+		for var_name in dir(scheme):
+			var = getattr(scheme, var_name)
+			if var != ColorScheme and isclass(var) and\
+					issubclass(var, ColorScheme):
+				colorscheme = var()
+				break
+		else:
+			print("The given colorscheme module contains no valid colorscheme!")
+			sys.exit(1)
+
+	else:
+		print("Cannot locate colorscheme!")
+		sys.exit(1)
+
 	env = Environment(path, opt)
 	commandlist = CommandList()
-	colorscheme = MyColorScheme()
 	keys.initialize_commands(commandlist)
 	bookmarks = Bookmarks()
 	bookmarks.load()
diff --git a/ranger/mimetype.py b/ranger/mimetype.py
index 4346d9c8..5e70f2e7 100644
--- a/ranger/mimetype.py
+++ b/ranger/mimetype.py
@@ -4,7 +4,7 @@ def load():
 	import sys, os, pickle
 	types.clear()
 
-	f = open(os.path.join(sys.path[0], 'data/mime.dat'), 'rb')
+	f = open(os.path.join(os.path.dirname(__file__), '../data/mime.dat'), 'rb')
 	types.update(pickle.load(f))
 	f.close()