summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-23 13:32:15 +0200
committerhut <hut@lavabit.com>2010-04-23 13:33:38 +0200
commit1f2ffbb34f63ffb0440795c4a6a0b9d93b3ab84f (patch)
treed354a392bd467636c36fcc0a6e46f1bd99ec6ba1 /ranger
parentd528952a414cde9d704f736339c1dcbe18abd2ae (diff)
downloadranger-1f2ffbb34f63ffb0440795c4a6a0b9d93b3ab84f.tar.gz
main: new function "allow_access_to_confdir"
Diffstat (limited to 'ranger')
-rw-r--r--ranger/__main__.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/ranger/__main__.py b/ranger/__main__.py
index cbb87cc2..3ae71fc0 100644
--- a/ranger/__main__.py
+++ b/ranger/__main__.py
@@ -60,19 +60,27 @@ def parse_arguments():
 	return arg
 
 
-def load_settings(fm, clean):
-	if not clean:
+def allow_access_to_confdir(confdir, allow):
+	if allow:
 		try:
-			os.makedirs(ranger.arg.confdir)
+			os.makedirs(confdir)
 		except OSError as err:
 			if err.errno != 17:  # 17 means it already exists
 				print("This configuration directory could not be created:")
-				print(ranger.arg.confdir)
+				print(confdir)
 				print("To run ranger without the need for configuration")
 				print("files, use the --clean option.")
 				raise SystemExit()
+		if not confdir in sys.path:
+			sys.path[0:0] = [confdir]
+	else:
+		if sys.path[0] == confdir:
+			del sys.path[0]
 
-		sys.path[0:0] = [ranger.arg.confdir]
+
+def load_settings(fm, clean):
+	if not clean:
+		allow_access_to_confdir(ranger.arg.confdir, True)
 
 		# Load commands
 		comcont = ranger.api.commands.CommandContainer()
@@ -107,7 +115,7 @@ def load_settings(fm, clean):
 			print("Warning: the syntax for ~/.ranger/keys.py has changed.")
 			print("Your custom keys are not loaded."\
 					"  Please update your configuration.")
-		del sys.path[0]
+		allow_access_to_confdir(ranger.arg.confdir, False)
 	else:
 		comcont = ranger.api.commands.CommandContainer()
 		ranger.api.commands.alias = comcont.alias