diff options
author | hut <hut@lavabit.com> | 2011-10-08 05:32:02 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-08 06:09:02 +0200 |
commit | 1d27a413986bfdcecb3c7ea67f327d20dc9a029f (patch) | |
tree | 474aaf669d4ddd9cb0d2e5304bb65d9ad735969f /ranger | |
parent | f383db8f2fa350e404f880d00981279d1a2af188 (diff) | |
download | ranger-1d27a413986bfdcecb3c7ea67f327d20dc9a029f.tar.gz |
core.main: Automatically copy config files
This removes --copy-config=X and adds --dont-copy-config.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/fm.py | 46 | ||||
-rw-r--r-- | ranger/core/helper.py | 5 | ||||
-rw-r--r-- | ranger/core/main.py | 6 | ||||
-rw-r--r-- | ranger/data/config_examples/rc.conf | 0 |
4 files changed, 27 insertions, 30 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 6d772054..e2a86399 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -122,35 +122,35 @@ class FM(Actions, SignalDispatcher): self.input_blocked = False return self.input_blocked - def copy_config_files(self, which): + def _copy_config_files(self): 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)) + files = {'data/config_examples/apps.py': 'apps.py', + 'data/config_examples/rc.conf': 'rc.conf', + 'data/config_examples/commands.py': 'commands.py', + 'data/config_examples/options.py': 'options.py', + 'data/scope.sh': 'scope.sh'} + copied_any = False + for fname, target in files.items(): + if not os.path.exists(self.confpath(target)): + if not copied_any: + copied_any = True + try: + os.makedirs(self.confpath()) + except: + pass + sys.stderr.write("creating: %s\n" % self.confpath(target)) try: - shutil.copy(self.relpath(_from), self.confpath(to)) + shutil.copy(self.relpath(fname), self.confpath(target)) except Exception as e: sys.stderr.write(" ERROR: %s\n" % str(e)) - 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 == 'rc' or which == 'all': - copy('defaults/rc.conf', 'rc.conf') - if which == 'options' or which == 'all': - copy('defaults/options.py', 'options.py') - if which == 'scope' or which == 'all': - copy('data/scope.sh', 'scope.sh') - os.chmod(self.confpath('scope.sh'), - os.stat(self.confpath('scope.sh')).st_mode | stat.S_IXUSR) - if which not in \ - ('all', 'apps', 'scope', 'commands', 'rc', 'options'): - sys.stderr.write("Unknown config file `%s'\n" % which) + if target == 'scope.sh': + os.chmod(self.confpath('scope.sh'), os.stat( + self.confpath('scope.sh')).st_mode | stat.S_IXUSR) + if copied_any: + sys.stderr.write("Use --dont-copy-config to disable " + "automatic copying of example config files.\n") 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 f4035ef8..64508ef7 100644 --- a/ranger/core/helper.py +++ b/ranger/core/helper.py @@ -40,9 +40,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', 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('--dont-copy-config', action='store_true', + help="dont copy the sample configs if they're not found") 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 bed5d82d..d58081bc 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -42,10 +42,6 @@ def main(): os.environ['SHELL'] = 'bash' ranger.arg = arg = parse_arguments() - if arg.copy_config is not None: - fm = FM() - fm.copy_config_files(arg.copy_config) - return 1 if arg.fail_unless_cd else 0 SettingsAware._setup(clean=arg.clean) @@ -72,6 +68,8 @@ def main(): # Initialize objects from ranger.core.environment import Environment fm = FM() + if not arg.dont_copy_config and not arg.clean: + fm._copy_config_files() FileManagerAware.fm = fm EnvironmentAware.env = Environment(target) fm.tabs = dict((n+1, os.path.abspath(path)) for n, path \ diff --git a/ranger/data/config_examples/rc.conf b/ranger/data/config_examples/rc.conf new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ranger/data/config_examples/rc.conf |