diff options
-rw-r--r-- | .pylintrc | 3 | ||||
-rw-r--r-- | ranger/__init__.py | 2 | ||||
-rw-r--r-- | ranger/api/commands.py | 2 | ||||
-rw-r--r-- | ranger/core/actions.py | 26 | ||||
-rw-r--r-- | ranger/core/fm.py | 24 | ||||
-rw-r--r-- | ranger/core/main.py | 85 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 6 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 4 |
8 files changed, 77 insertions, 75 deletions
diff --git a/.pylintrc b/.pylintrc index fd886447..5a5c135f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -11,5 +11,4 @@ max-line-length = 99 disable=locally-disabled,locally-enabled,missing-docstring,duplicate-code,fixme,broad-except,cyclic-import,attribute-defined-outside-init,access-member-before-definition [TYPECHECK] -ignored-classes=ranger.ext.openstruct.OpenStruct,ranger.core.runner.Context,ranger.core.actions.Actions,ranger.gui.widgets.view_base.ViewBase,ranger.gui.curses_shortcuts.CursesShortcuts -generated-members=ranger.arg +ignored-classes=ranger.core.runner.Context,ranger.core.actions.Actions,ranger.gui.widgets.view_base.ViewBase,ranger.gui.curses_shortcuts.CursesShortcuts diff --git a/ranger/__init__.py b/ranger/__init__.py index 6f41eb98..a84bf3e8 100644 --- a/ranger/__init__.py +++ b/ranger/__init__.py @@ -35,4 +35,6 @@ VERSION = 'ranger-master %s\n\nPython %s' % (__version__, sys.version) # and the configuration directory will be $XDG_CONFIG_HOME/ranger instead. CONFDIR = '~/.config/ranger' +args = None # pylint: disable=invalid-name + from ranger.core.main import main # NOQA pylint: disable=wrong-import-position diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 2160dbd7..097ead2c 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -421,7 +421,7 @@ class FunctionCommand(Command): del keywords['narg'] return self._based_function(*args, **keywords) # pylint: disable=not-callable except TypeError: - if ranger.arg.debug: + if ranger.args.debug: raise else: self.fm.notify("Bad arguments for %s.%s: %s, %s" % diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 68fc4884..5270a8da 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -155,10 +155,10 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m Display the text in the statusbar. """ if isinstance(text, Exception): - if ranger.arg.debug: + if ranger.args.debug: raise text bad = True - elif bad is True and ranger.arg.debug: + elif bad is True and ranger.args.debug: raise Exception(str(text)) text = str(text) LOG.debug("Command notify invoked: [Bad: %s, Text: '%s']", bad, text) @@ -224,14 +224,14 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m string = self.substitute_macros(string, additional=macros, escape=cmd.escape_macros_for_shell) except ValueError as ex: - if ranger.arg.debug: + if ranger.args.debug: raise else: return self.notify(ex) try: cmd_class(string, quantifier=quantifier).execute() except Exception as ex: - if ranger.arg.debug: + if ranger.args.debug: raise else: self.notify(ex) @@ -366,7 +366,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m try: self.execute_console(line) except Exception as ex: - if ranger.arg.debug: + if ranger.args.debug: raise else: self.notify('Error in line `%s\':\n %s' % @@ -389,14 +389,14 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m # ranger can act as a file chooser when running with --choosefile=... if mode == 0 and 'label' not in kw: - if ranger.arg.choosefile: - open(ranger.arg.choosefile, 'w').write(self.fm.thisfile.path) + if ranger.args.choosefile: + open(ranger.args.choosefile, 'w').write(self.fm.thisfile.path) - if ranger.arg.choosefiles: - open(ranger.arg.choosefiles, 'w').write("".join( + if ranger.args.choosefiles: + open(ranger.args.choosefiles, 'w').write("".join( fobj.path + "\n" for fobj in self.fm.thistab.get_selection())) - if ranger.arg.choosefile or ranger.arg.choosefiles: + if ranger.args.choosefile or ranger.args.choosefiles: raise SystemExit() if isinstance(files, set): @@ -924,10 +924,10 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m @staticmethod def sha1_encode(path): if version_info[0] < 3: - return os.path.join(ranger.arg.cachedir, + return os.path.join(ranger.args.cachedir, sha1(path).hexdigest()) + '.jpg' else: - return os.path.join(ranger.arg.cachedir, + return os.path.join(ranger.args.cachedir, sha1(path.encode('utf-8', 'backslashreplace')) .hexdigest()) + '.jpg' @@ -979,7 +979,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m data['loading'] = False return path - cacheimg = os.path.join(ranger.arg.cachedir, self.sha1_encode(path)) + cacheimg = os.path.join(ranger.args.cachedir, self.sha1_encode(path)) if os.path.isfile(cacheimg) and \ os.path.getmtime(cacheimg) > os.path.getmtime(path): data['foundpreview'] = True diff --git a/ranger/core/fm.py b/ranger/core/fm.py index f7a58b64..ddad8c94 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -93,7 +93,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho self.current_tab = 1 self.tabs[self.current_tab] = self.thistab = Tab('.') - if not ranger.arg.clean and os.path.isfile(self.confpath('rifle.conf')): + if not ranger.args.clean and os.path.isfile(self.confpath('rifle.conf')): rifleconf = self.confpath('rifle.conf') else: rifleconf = self.relpath('config/rifle.conf') @@ -107,13 +107,13 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho set_image_displayer, priority=settings.SIGNAL_PRIORITY_AFTER_SYNC) - if not ranger.arg.clean and self.tags is None: + if not ranger.args.clean and self.tags is None: self.tags = Tags(self.confpath('tagged')) - elif ranger.arg.clean: + elif ranger.args.clean: self.tags = TagsDummy("") # pylint: disable=redefined-variable-type if self.bookmarks is None: - if ranger.arg.clean: + if ranger.args.clean: bookmarkfile = None else: bookmarkfile = self.confpath('bookmarks') @@ -192,7 +192,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho signal.value)) def destroy(self): - debug = ranger.arg.debug + debug = ranger.args.debug if self.ui: try: self.ui.destroy() @@ -253,7 +253,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho return self.input_blocked def copy_config_files(self, which): - if ranger.arg.clean: + if ranger.args.clean: sys.stderr.write("refusing to copy config files in clean mode\n") return import shutil @@ -265,11 +265,11 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho else: sys.stderr.write("creating: %s\n" % self.confpath(dest)) try: - os.makedirs(ranger.arg.confdir) + os.makedirs(ranger.args.confdir) except OSError as err: if err.errno != EEXIST: # EEXIST means it already exists print("This configuration directory could not be created:") - print(ranger.arg.confdir) + print(ranger.args.confdir) print("To run ranger without the need for configuration") print("files, use the --clean option.") raise SystemExit() @@ -305,10 +305,10 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho @staticmethod def confpath(*paths): """returns the path relative to rangers configuration directory""" - if ranger.arg.clean: + if ranger.args.clean: assert 0, "Should not access relpath_conf in clean mode!" else: - return os.path.join(ranger.arg.confdir, *paths) + return os.path.join(ranger.args.confdir, *paths) @staticmethod def relpath(*paths): @@ -397,9 +397,9 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes,abstract-metho finally: self.image_displayer.quit() - if ranger.arg.choosedir and self.thisdir and self.thisdir.path: + if ranger.args.choosedir and self.thisdir and self.thisdir.path: # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character # '\udcf6' in position 42: surrogates not allowed - open(ranger.arg.choosedir, 'w').write(self.thisdir.path) + open(ranger.args.choosedir, 'w').write(self.thisdir.path) self.bookmarks.remember(self.thisdir) self.bookmarks.save() diff --git a/ranger/core/main.py b/ranger/core/main.py index 3cd1b9c5..b5735f3e 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -27,9 +27,11 @@ def main( from ranger.core.shared import FileManagerAware, SettingsAware from ranger.core.fm import FM from ranger.ext.logutils import setup_logging + from ranger.ext.openstruct import OpenStruct - ranger.arg = arg = parse_arguments() - setup_logging(debug=arg.debug, logfile=arg.logfile) + ranger.args = args = parse_arguments() + ranger.arg = OpenStruct(args.__dict__) # COMPAT + setup_logging(debug=args.debug, logfile=args.logfile) LOG.info("Ranger version %s", __version__) LOG.info('Running on Python ' + sys.version.replace('\n', '')) @@ -50,14 +52,14 @@ def main( if 'SHELL' not in os.environ: os.environ['SHELL'] = 'sh' - LOG.debug("config dir: '%s'", arg.confdir) - LOG.debug("cache dir: '%s'", arg.cachedir) + LOG.debug("config dir: '%s'", args.confdir) + LOG.debug("cache dir: '%s'", args.cachedir) - if arg.copy_config is not None: + if args.copy_config is not None: fm = FM() - fm.copy_config_files(arg.copy_config) - return 1 if arg.fail_unless_cd else 0 # COMPAT - if arg.list_tagged_files: + fm.copy_config_files(args.copy_config) + return 1 if args.fail_unless_cd else 0 # COMPAT + if args.list_tagged_files: fm = FM() try: if sys.version_info[0] >= 3: @@ -69,21 +71,21 @@ def main( else: for line in fobj.readlines(): if len(line) > 2 and line[1] == ':': - if line[0] in arg.list_tagged_files: + if line[0] in args.list_tagged_files: sys.stdout.write(line[2:]) - elif len(line) > 0 and '*' in arg.list_tagged_files: + elif len(line) > 0 and '*' in args.list_tagged_files: sys.stdout.write(line) - return 1 if arg.fail_unless_cd else 0 # COMPAT + return 1 if args.fail_unless_cd else 0 # COMPAT SettingsAware._setup(Settings()) # pylint: disable=protected-access - if arg.selectfile: - arg.selectfile = os.path.abspath(arg.selectfile) - arg.targets.insert(0, os.path.dirname(arg.selectfile)) + if args.selectfile: + args.selectfile = os.path.abspath(args.selectfile) + args.targets.insert(0, os.path.dirname(args.selectfile)) - targets = arg.targets or ['.'] + targets = args.targets or ['.'] target = targets[0] - if arg.targets: # COMPAT + if args.targets: # COMPAT if target.startswith('file://'): target = target[7:] if not os.access(target, os.F_OK): @@ -96,23 +98,23 @@ def main( from ranger.ext.rifle import Rifle fm = FM() - if not arg.clean and os.path.isfile(fm.confpath('rifle.conf')): + if not args.clean and os.path.isfile(fm.confpath('rifle.conf')): rifleconf = fm.confpath('rifle.conf') else: rifleconf = fm.relpath('config/rifle.conf') rifle = Rifle(rifleconf) rifle.reload_config() - rifle.execute(targets, number=ranger.arg.mode, flags=ranger.arg.flags) - return 1 if arg.fail_unless_cd else 0 # COMPAT + rifle.execute(targets, number=ranger.args.mode, flags=ranger.args.flags) + return 1 if args.fail_unless_cd else 0 # COMPAT crash_traceback = None try: # Initialize objects fm = FM(paths=targets) FileManagerAware._setup(fm) # pylint: disable=protected-access - load_settings(fm, arg.clean) + load_settings(fm, args.clean) - if arg.list_unused_keys: + if args.list_unused_keys: from ranger.ext.keybinding_parser import (special_keys, reversed_special_keys) maps = fm.ui.keymaps['browser'] @@ -122,7 +124,7 @@ def main( for key in range(33, 127): if key not in maps: print(chr(key)) - return 1 if arg.fail_unless_cd else 0 # COMPAT + return 1 if args.fail_unless_cd else 0 # COMPAT if not sys.stdin.isatty(): sys.stderr.write("Error: Must run ranger from terminal\n") @@ -132,28 +134,28 @@ def main( fm.settings.preview_files = False fm.settings.use_preview_script = False LOG.info("Running as root, disabling the file previews.") - if not arg.debug: + if not args.debug: from ranger.ext import curses_interrupt_handler curses_interrupt_handler.install_interrupt_handler() # Create cache directory if fm.settings.preview_images and fm.settings.use_preview_script: - if not os.path.exists(arg.cachedir): - os.makedirs(arg.cachedir) + if not os.path.exists(args.cachedir): + os.makedirs(args.cachedir) # Run the file manager fm.initialize() ranger.api.hook_init(fm) fm.ui.initialize() - if arg.selectfile: - fm.select_file(arg.selectfile) + if args.selectfile: + fm.select_file(args.selectfile) - if arg.cmd: - for command in arg.cmd: + if args.cmd: + for command in args.cmd: fm.execute_console(command) - if ranger.arg.profile: + if ranger.args.profile: import cProfile import pstats profile = None @@ -177,7 +179,7 @@ def main( fm.ui.destroy() except (AttributeError, NameError): pass - if ranger.arg.profile and profile: + if ranger.args.profile and profile: profile.strip_dirs().sort_stats('cumulative').print_callees() if crash_traceback: print("ranger version: %s, executed with python %s" % @@ -200,7 +202,6 @@ def parse_arguments(): from optparse import OptionParser, SUPPRESS_HELP # pylint: disable=deprecated-module from os.path import expanduser from ranger import CONFDIR, CACHEDIR, USAGE, VERSION - from ranger.ext.openstruct import OpenStruct if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: default_confdir = os.environ['XDG_CONFIG_HOME'] + '/ranger' @@ -256,17 +257,17 @@ def parse_arguments(): help="Execute COMMAND after the configuration has been read. " "Use this option multiple times to run multiple commands.") - options, positional = parser.parse_args() - arg = OpenStruct(options.__dict__, targets=positional) - arg.confdir = expanduser(arg.confdir) - arg.cachedir = expanduser(default_cachedir) + args, positional = parser.parse_args() + args.targets = positional + args.confdir = expanduser(args.confdir) + args.cachedir = expanduser(default_cachedir) - if arg.fail_unless_cd: # COMPAT + if args.fail_unless_cd: # COMPAT sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n" "It was used to facilitate using ranger as a file launcher.\n" "Now, please use the standalone file launcher 'rifle' instead.\n") - return arg + return args COMMANDS_EXCLUDE = ['settings', 'notify'] @@ -286,7 +287,7 @@ def load_settings( # pylint: disable=too-many-locals,too-many-branches,too-many fm.commands.load_commands_from_module(commands_default) if not clean: - allow_access_to_confdir(ranger.arg.confdir, True) + allow_access_to_confdir(ranger.args.confdir, True) # Load custom commands custom_comm_path = fm.confpath('commands.py') @@ -303,7 +304,7 @@ def load_settings( # pylint: disable=too-many-locals,too-many-branches,too-many LOG.debug("Loaded custom commands from '%s'", custom_comm_path) sys.dont_write_bytecode = old_bytecode_setting - allow_access_to_confdir(ranger.arg.confdir, False) + allow_access_to_confdir(ranger.args.confdir, False) # Load rc.conf custom_conf = fm.confpath('rc.conf') @@ -314,7 +315,7 @@ def load_settings( # pylint: disable=too-many-locals,too-many-branches,too-many if os.access(custom_conf, os.R_OK): fm.source(custom_conf) - allow_access_to_confdir(ranger.arg.confdir, True) + allow_access_to_confdir(ranger.args.confdir, True) # XXX Load plugins (experimental) try: @@ -371,7 +372,7 @@ copy & paste it to a .py file in ~/.config/ranger/plugins/. Remove the options.py or discard stderr to get rid of this warning. ******************************\n""") - allow_access_to_confdir(ranger.arg.confdir, False) + allow_access_to_confdir(ranger.args.confdir, False) else: fm.source(fm.relpath('config', 'rc.conf')) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index e5909a09..87ba72e4 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -89,7 +89,7 @@ def _colorscheme_name_to_class(signal): # pylint: disable=too-many-branches signal.value = 'default' scheme_name = signal.value - usecustom = not ranger.arg.clean + usecustom = not ranger.args.clean def exists(colorscheme): return os.path.exists(colorscheme + '.py') or os.path.exists(colorscheme + '.pyc') @@ -124,11 +124,11 @@ def _colorscheme_name_to_class(signal): # pylint: disable=too-many-branches raise Exception("Cannot locate colorscheme `%s'" % scheme_name) else: if usecustom: - allow_access_to_confdir(ranger.arg.confdir, True) + allow_access_to_confdir(ranger.args.confdir, True) scheme_module = getattr(__import__(scheme_supermodule, globals(), locals(), [scheme_name], 0), scheme_name) if usecustom: - allow_access_to_confdir(ranger.arg.confdir, False) + allow_access_to_confdir(ranger.args.confdir, False) if hasattr(scheme_module, 'Scheme') \ and is_scheme(scheme_module.Scheme): signal.value = scheme_module.Scheme() diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 7558183a..dbd9a7ff 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -37,7 +37,7 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- self.clear() self.history = History(self.settings.max_console_history_size) # load history from files - if not ranger.arg.clean: + if not ranger.args.clean: self.historypath = self.fm.confpath('history') try: fobj = open(self.historypath, 'r') @@ -65,7 +65,7 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- def destroy(self): # save history to files - if ranger.arg.clean or not self.settings.save_console_history: + if ranger.args.clean or not self.settings.save_console_history: return if self.historypath: try: |