summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-10-11 08:00:16 +0200
committerhut <hut@lavabit.com>2010-10-11 08:00:16 +0200
commita0ca73c855d4925780253c8294d725892455cc51 (patch)
tree13a7cb3199aa3e557e1ea2508224d82079b0fc55 /ranger
parent2bcb509a0834828829b8ca01d5679ee22c416267 (diff)
downloadranger-a0ca73c855d4925780253c8294d725892455cc51.tar.gz
core.main: added --copy-config flag
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/fm.py22
-rw-r--r--ranger/core/helper.py2
-rw-r--r--ranger/core/main.py6
-rw-r--r--ranger/help/invocation.py4
4 files changed, 29 insertions, 5 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index bfcebb92..fce6b3b2 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -123,10 +123,24 @@ class FM(Actions, SignalDispatcher):
 		return self.input_blocked
 
 	def copy_config_files(self):
-		if not (ranger.arg.clean or os.path.exists(self.confpath('scope.sh'))):
-			import shutil
-			shutil.copy(self.relpath('data/scope.sh'),
-					self.confpath('scope.sh'))
+		if ranger.arg.clean:
+			sys.stderr.write("refusing to copy config files in clean mode\n")
+			return
+		import shutil
+		def copy(_from, to):
+			if os.path.exists(self.confpath(to)):
+				sys.stderr.write("already exists: %s\n" % self.confpath(to))
+			else:
+				sys.stderr.write("creating: %s\n" % self.confpath(to))
+				try:
+					shutil.copy(self.relpath(_from), self.confpath(to))
+				except Exception as e:
+					sys.stderr.write("  ERROR: %s\n" % str(e))
+		copy('defaults/apps.py', 'apps.py')
+		copy('defaults/commands.py', 'commands.py')
+		copy('defaults/keys.py', 'keys.py')
+		copy('defaults/options.py', 'options.py')
+		copy('data/scope.sh', 'scope.sh')
 
 	def confpath(self, *paths):
 		"""returns the path relative to rangers configuration directory"""
diff --git a/ranger/core/helper.py b/ranger/core/helper.py
index 38460bb6..aa55b25b 100644
--- a/ranger/core/helper.py
+++ b/ranger/core/helper.py
@@ -51,6 +51,8 @@ def parse_arguments():
 			help="don't touch/require any config files. ")
 	parser.add_option('--fail-if-run', action='store_true', # COMPAT
 			help=SUPPRESS_HELP)
+	parser.add_option('--copy-config', action='store_true', # COMPAT
+			help="copy the default configs to the local config directory")
 	parser.add_option('--fail-unless-cd', action='store_true',
 			help="experimental: return the exit code 1 if ranger is" \
 					"used to run a file (with `ranger filename`)")
diff --git a/ranger/core/main.py b/ranger/core/main.py
index ed555a8d..19e28db3 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -42,6 +42,11 @@ def main():
 		os.environ['SHELL'] = 'bash'
 
 	ranger.arg = arg = parse_arguments()
+	if arg.copy_config:
+		fm = FM()
+		fm.copy_config_files()
+		return 0
+
 	SettingsAware._setup(clean=arg.clean)
 
 	targets = arg.targets or ['.']
@@ -65,7 +70,6 @@ def main():
 		# Initialize objects
 		EnvironmentAware.env = Environment(target)
 		fm = FM()
-		fm.copy_config_files()
 		fm.tabs = dict((n+1, os.path.abspath(path)) for n, path \
 				in enumerate(targets[:9]))
 		load_settings(fm, arg.clean)
diff --git a/ranger/help/invocation.py b/ranger/help/invocation.py
index 27ab5a67..cad2a2b2 100644
--- a/ranger/help/invocation.py
+++ b/ranger/help/invocation.py
@@ -44,6 +44,10 @@ command line.
       This is useful when your configuration is broken, when you want
       to avoid clutter, etc.
 
+--copy-config
+      Create copies of the default configuration files in your local
+      configuration directory.  Existing ones will not be overwritten.
+
 --fail-unless-cd
       Return the exit code 1 if ranger is used to run a file, for example
       with `ranger --fail-unless-cd filename`.  This can be useful for scripts.