From 21152271e74d00a458349e05278833a0bd077c2a Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 12 Oct 2010 17:14:47 +0200 Subject: core.main: extended --copy-config option --- doc/ranger.1 | 5 +++-- ranger/core/fm.py | 20 ++++++++++++++------ ranger/core/helper.py | 5 +++-- ranger/core/main.py | 4 ++-- ranger/help/invocation.py | 1 + 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index f71c8a02..8eee794c 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -33,9 +33,10 @@ Activate the clean mode: Ranger will not access or create any configuration files nor will it leave any traces on your system. This is useful when your configuration is broken, when you want to avoid clutter, etc. .TP ---copy-config +--copy-config=\fIwhich\fR Create copies of the default configuration files in your local configuration -directory. Existing ones will not be overwritten. +directory. Existing ones will not be overwritten. Possible values: +all, apps, commands, keys, options, scope. .TP --fail-unless-cd Return the exit code 1 if ranger is used to run a file, for example with diff --git a/ranger/core/fm.py b/ranger/core/fm.py index fce6b3b2..37f79554 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -122,7 +122,7 @@ class FM(Actions, SignalDispatcher): self.input_blocked = False return self.input_blocked - def copy_config_files(self): + def copy_config_files(self, which): if ranger.arg.clean: sys.stderr.write("refusing to copy config files in clean mode\n") return @@ -136,11 +136,19 @@ class FM(Actions, SignalDispatcher): 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') + if which == 'apps' or which == 'all': + copy('defaults/apps.py', 'apps.py') + if which == 'commands' or which == 'all': + copy('defaults/commands.py', 'commands.py') + if which == 'keys' or which == 'all': + copy('defaults/keys.py', 'keys.py') + if which == 'options' or which == 'all': + copy('defaults/options.py', 'options.py') + if which == 'scope' or which == 'all': + copy('data/scope.sh', 'scope.sh') + if which not in \ + ('all', 'apps', 'scope', 'commands', 'keys', 'options'): + sys.stderr.write("Unknown config file `%s'\n" % which) 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 aa55b25b..3c018192 100644 --- a/ranger/core/helper.py +++ b/ranger/core/helper.py @@ -51,8 +51,9 @@ 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('--copy-config', type='string', metavar='which', + help="copy the default configs to the local config directory. " + "Possible values: all, apps, commands, keys, options, scope") 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 f5aba47e..36067a5d 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -42,9 +42,9 @@ def main(): os.environ['SHELL'] = 'bash' ranger.arg = arg = parse_arguments() - if arg.copy_config: + if arg.copy_config is not None: fm = FM() - fm.copy_config_files() + fm.copy_config_files(arg.copy_config) return 0 SettingsAware._setup(clean=arg.clean) diff --git a/ranger/help/invocation.py b/ranger/help/invocation.py index cad2a2b2..688308f1 100644 --- a/ranger/help/invocation.py +++ b/ranger/help/invocation.py @@ -47,6 +47,7 @@ command line. --copy-config Create copies of the default configuration files in your local configuration directory. Existing ones will not be overwritten. + Possible values: all, apps, commands, keys, options, scope. --fail-unless-cd Return the exit code 1 if ranger is used to run a file, for example -- cgit 1.4.1-2-gfad0