diff options
28 files changed, 255 insertions, 238 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 35e073cc..9985b996 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -423,9 +423,11 @@ class FunctionCommand(Command): if ranger.args.debug: raise else: - self.fm.notify("Bad arguments for %s.%s: %s, %s" % - (self._object_name, self._function_name, - repr(args), repr(keywords)), bad=True) + self.fm.notify( + "Bad arguments for %s.%s: %s, %s" % ( + self._object_name, self._function_name, repr(args), repr(keywords)), + bad=True, + ) class AliasCommand(Command): diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 1e7ac78c..2e84766a 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -443,8 +443,11 @@ class default_linemode(Command): # Extract and validate the line mode from the command line lmode = self.rest(1) if lmode not in FileSystemObject.linemode_dict: - self.fm.notify("Invalid linemode: %s; should be %s" % - (lmode, "/".join(FileSystemObject.linemode_dict)), bad=True) + self.fm.notify( + "Invalid linemode: %s; should be %s" % ( + lmode, "/".join(FileSystemObject.linemode_dict)), + bad=True, + ) # Add the prepared entry to the fm.default_linemodes entry = [method, argument, lmode] @@ -544,9 +547,11 @@ class delete(Command): confirm = self.fm.settings.confirm_on_delete if confirm != 'never' and (confirm != 'multiple' or many_files): - self.fm.ui.console.ask("Confirm deletion of: %s (y/N)" % - ', '.join(files), - partial(self._question_callback, files), ('n', 'N', 'y', 'Y')) + self.fm.ui.console.ask( + "Confirm deletion of: %s (y/N)" % ', '.join(files), + partial(self._question_callback, files), + ('n', 'N', 'y', 'Y'), + ) else: # no need for a confirmation, just delete self.fm.delete(files) @@ -614,8 +619,8 @@ class load_copy_buffer(Command): fname = self.fm.confpath(self.copy_buffer_filename) fobj = open(fname, 'r') except Exception: - return self.fm.notify("Cannot open %s" % - (fname or self.copy_buffer_filename), bad=True) + return self.fm.notify( + "Cannot open %s" % (fname or self.copy_buffer_filename), bad=True) self.fm.copy_buffer = set(File(g) for g in fobj.read().split("\n") if exists(g)) fobj.close() @@ -1138,20 +1143,22 @@ class scout(Command): Multiple flags can be combined. For example, ":scout -gpt" would create a :filter-like command using globbing. """ - AUTO_OPEN = 'a' + # pylint: disable=bad-whitespace + AUTO_OPEN = 'a' OPEN_ON_ENTER = 'e' - FILTER = 'f' - SM_GLOB = 'g' - IGNORE_CASE = 'i' - KEEP_OPEN = 'k' + FILTER = 'f' + SM_GLOB = 'g' + IGNORE_CASE = 'i' + KEEP_OPEN = 'k' SM_LETTERSKIP = 'l' - MARK = 'm' - UNMARK = 'M' - PERM_FILTER = 'p' - SM_REGEX = 'r' - SMART_CASE = 's' - AS_YOU_TYPE = 't' - INVERT = 'v' + MARK = 'm' + UNMARK = 'M' + PERM_FILTER = 'p' + SM_REGEX = 'r' + SMART_CASE = 's' + AS_YOU_TYPE = 't' + INVERT = 'v' + # pylint: enable=bad-whitespace def __init__(self, *args, **kws): Command.__init__(self, *args, **kws) @@ -1308,10 +1315,11 @@ class filter_inode_type(Command): f display files l display links """ - - FILTER_DIRS = 'd' + # pylint: disable=bad-whitespace + FILTER_DIRS = 'd' FILTER_FILES = 'f' FILTER_LINKS = 'l' + # pylint: enable=bad-whitespace def execute(self): if not self.arg(1): diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 1fa9065f..6c34641e 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -148,14 +148,13 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public self.marked_items = list() - for opt in ('sort_directories_first', 'sort', 'sort_reverse', - 'sort_case_insensitive'): - self.settings.signal_bind('setopt.' + opt, - self.request_resort, weak=True, autosort=False) + for opt in ('sort_directories_first', 'sort', 'sort_reverse', 'sort_case_insensitive'): + self.settings.signal_bind('setopt.' + opt, self.request_resort, + weak=True, autosort=False) for opt in ('hidden_filter', 'show_hidden'): - self.settings.signal_bind('setopt.' + opt, - self.refilter, weak=True, autosort=False) + self.settings.signal_bind('setopt.' + opt, self.refilter, + weak=True, autosort=False) self.settings = LocalSettings(path, self.settings) @@ -503,8 +502,7 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public def look_up_cumulative_size(self): self._cumulative_size_calculated = True self.size = self._get_cumulative_size() - self.infostring = ('-> ' if self.is_link else ' ') + \ - human_readable(self.size) + self.infostring = ('-> ' if self.is_link else ' ') + human_readable(self.size) @lazy_property def size(self): # pylint: disable=method-hidden diff --git a/ranger/container/file.py b/ranger/container/file.py index 2312761f..f98be1d7 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -7,8 +7,9 @@ import re from ranger.container.fsobject import FileSystemObject N_FIRST_BYTES = 256 -control_characters = set(chr(n) for n in # pylint: disable=invalid-name - set(range(0, 9)) | set(range(14, 32))) +# pylint: disable=invalid-name +control_characters = set(chr(n) for n in set(range(0, 9)) | set(range(14, 32))) +# pylint: enable=invalid-name # Don't even try to preview files which match this regular expression: PREVIEW_BLACKLIST = re.compile(r""" diff --git a/ranger/container/settings.py b/ranger/container/settings.py index acbf9d16..a83192ca 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -13,11 +13,13 @@ from ranger.gui.colorscheme import _colorscheme_name_to_class # Use these priority constants to trigger events at specific points in time # during processing of the signals "setopt" and "setopt.<some_setting_name>" -SIGNAL_PRIORITY_RAW = 2.0 # signal.value will be raw -SIGNAL_PRIORITY_SANITIZE = 1.0 # (Internal) post-processing signal.value -SIGNAL_PRIORITY_BETWEEN = 0.6 # sanitized signal.value, old fm.settings.XYZ -SIGNAL_PRIORITY_SYNC = 0.2 # (Internal) updating fm.settings.XYZ +# pylint: disable=bad-whitespace +SIGNAL_PRIORITY_RAW = 2.0 # signal.value will be raw +SIGNAL_PRIORITY_SANITIZE = 1.0 # (Internal) post-processing signal.value +SIGNAL_PRIORITY_BETWEEN = 0.6 # sanitized signal.value, old fm.settings.XYZ +SIGNAL_PRIORITY_SYNC = 0.2 # (Internal) updating fm.settings.XYZ SIGNAL_PRIORITY_AFTER_SYNC = 0.1 # after fm.settings.XYZ was updated +# pylint: enable=bad-whitespace ALLOWED_SETTINGS = { @@ -109,11 +111,9 @@ class Settings(SignalDispatcher, FileManagerAware): self.__dict__['_tagsettings'] = dict() self.__dict__['_settings'] = dict() for name in ALLOWED_SETTINGS: - self.signal_bind('setopt.' + name, - self._sanitize, + self.signal_bind('setopt.' + name, self._sanitize, priority=SIGNAL_PRIORITY_SANITIZE) - self.signal_bind('setopt.' + name, - self._raw_set_with_signal, + self.signal_bind('setopt.' + name, self._raw_set_with_signal, priority=SIGNAL_PRIORITY_SYNC) def _sanitize(self, signal): diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 1a6b5331..070bda8c 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -96,13 +96,12 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m def set_option_from_string(self, option_name, value, localpath=None, tags=None): if option_name not in ALLOWED_SETTINGS: - raise ValueError("The option named `%s' does not exist" % - option_name) + raise ValueError("The option named `%s' does not exist" % option_name) if not isinstance(value, str): raise ValueError("The value for an option needs to be a string.") - self.settings.set(option_name, self._parse_option_value( - option_name, value), localpath, tags) + self.settings.set(option_name, self._parse_option_value(option_name, value), + localpath, tags) def _parse_option_value(self, name, value): types = self.fm.settings.types_of(name) @@ -370,8 +369,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if ranger.args.debug: raise else: - self.notify('Error in line `%s\':\n %s' % - (line, str(ex)), bad=True) + self.notify('Error in line `%s\':\n %s' % (line, str(ex)), bad=True) def execute_file(self, files, **kw): """Uses the "rifle" module to open/execute a file @@ -474,8 +472,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m self._visual_start = None startpos = min(self._visual_start_pos, len(cwd)) # The files between here and _visual_start_pos - targets = set(cwd.files[min(startpos, newpos): - max(startpos, newpos) + 1]) + targets = set(cwd.files[min(startpos, newpos):(max(startpos, newpos) + 1)]) # The selection before activating visual mode old = self._previous_selection # The current selection @@ -762,8 +759,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m return cwd.cycle(forward=forward) def set_search_method(self, order, forward=True): # pylint: disable=unused-argument - if order in ('search', 'tag', 'size', 'mimetype', 'ctime', - 'mtime', 'atime'): + if order in ('search', 'tag', 'size', 'mimetype', 'ctime', 'mtime', 'atime'): self.search_method = order # -------------------------- @@ -846,12 +842,11 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m except Exception: self.ui.browser.draw_info = [] return - programs = [program for program in self.rifle.list_commands([target.path], - None)] + programs = [program for program in self.rifle.list_commands([target.path], None)] if programs: num_digits = max((len(str(program[0])) for program in programs)) - program_info = ['%s | %s' % (str(program[0]).rjust(num_digits), - program[1]) for program in programs] + program_info = ['%s | %s' % (str(program[0]).rjust(num_digits), program[1]) + for program in programs] self.ui.browser.draw_info = program_info def hide_console_info(self): @@ -874,8 +869,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m return if not command.__doc__: - self.notify("Command has no docstring. Try using python without -OO", - bad=True) + self.notify("Command has no docstring. Try using python without -OO", bad=True) return pager = self.ui.open_pager() @@ -925,11 +919,9 @@ 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.args.cachedir, - sha1(path).hexdigest()) + '.jpg' + return os.path.join(ranger.args.cachedir, sha1(path).hexdigest()) + '.jpg' return os.path.join(ranger.args.cachedir, - sha1(path.encode('utf-8', 'backslashreplace')) - .hexdigest()) + '.jpg' + sha1(path.encode('utf-8', 'backslashreplace')).hexdigest()) + '.jpg' def get_preview(self, fobj, width, height): # pylint: disable=too-many-return-statements pager = self.ui.get_pager() @@ -955,19 +947,30 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if data['loading']: return None - found = data.get((-1, -1), data.get( - (width, -1), data.get((-1, height), data.get((width, height), False)))) + found = data.get( + (-1, -1), data.get( + (width, -1), data.get( + (-1, height), data.get( + (width, height), False + ) + ) + ) + ) if found is False: try: stat_ = os.stat(self.settings.preview_script) except Exception: - self.fm.notify("Preview Script `%s' doesn't exist!" % - self.settings.preview_script, bad=True) + self.fm.notify( + "Preview Script `%s' doesn't exist!" % self.settings.preview_script, + bad=True, + ) return None if not stat_.st_mode & S_IEXEC: - self.fm.notify("Preview Script `%s' is not executable!" % - self.settings.preview_script, bad=True) + self.fm.notify( + "Preview Script `%s' is not executable!" % self.settings.preview_script, + bad=True, + ) return None data['loading'] = True @@ -988,10 +991,13 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m data['loading'] = False return cacheimg - loadable = CommandLoader(args=[self.settings.preview_script, - path, str(width), str(height), cacheimg, - str(self.settings.preview_images)], read=True, - silent=True, descr="Getting preview of %s" % path) + loadable = CommandLoader( + args=[self.settings.preview_script, path, str(width), str(height), + cacheimg, str(self.settings.preview_images)], + read=True, + silent=True, + descr="Getting preview of %s" % path, + ) def on_after(signal): rcode = signal.process.poll() @@ -1018,8 +1024,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m data[(-1, -1)] = fobj.read(1024 * 32) except UnicodeDecodeError: fobj.close() - fobj = codecs.open(path, 'r', encoding='latin-1', - errors='ignore') + fobj = codecs.open(path, 'r', encoding='latin-1', errors='ignore') data[(-1, -1)] = fobj.read(1024 * 32) fobj.close() else: @@ -1114,8 +1119,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m tab.enter_dir(tab.path, history=False) self.thistab = tab self.change_mode('normal') - self.signal_emit('tab.change', old=previous_tab, - new=self.thistab) + self.signal_emit('tab.change', old=previous_tab, new=self.thistab) break def tab_move(self, offset, narg=None): @@ -1285,9 +1289,8 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m else: direction = Direction(dirarg) offset = 1 - pos, selected = direction.select( - override=narg, lst=cwd.files, current=cwd.pointer, - pagesize=self.ui.termsize[0], offset=offset) + pos, selected = direction.select(override=narg, lst=cwd.files, current=cwd.pointer, + pagesize=self.ui.termsize[0], offset=offset) cwd.pointer = pos cwd.correct_pointer() if mode == 'set': diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 0a0be874..9b7c8fae 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -86,8 +86,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes def initialize(self): """If ui/bookmarks are None, they will be initialized here.""" - self.tabs = dict((n + 1, Tab(path)) for n, path in - enumerate(self.start_paths)) + self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths)) tab_list = self._get_tab_list() if tab_list: self.current_tab = tab_list[0] @@ -106,8 +105,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes def set_image_displayer(): self.image_displayer = self._get_image_displayer() set_image_displayer() - self.settings.signal_bind('setopt.preview_images_method', - set_image_displayer, + self.settings.signal_bind('setopt.preview_images_method', set_image_displayer, priority=settings.SIGNAL_PRIORITY_AFTER_SYNC) if not ranger.args.clean and self.tags is None: @@ -151,8 +149,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes re.match(r'^(feh|sxiv|imv|pqiv) ', command): images = [f.relative_path for f in self.thisdir.files if f.image] - escaped_filenames = " ".join(shell_quote(f) - for f in images if "\x00" not in f) + escaped_filenames = " ".join(shell_quote(f) for f in images if "\x00" not in f) if images and self.thisfile.relative_path in images and \ "$@" in command: @@ -160,28 +157,26 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes if command[0:5] == 'sxiv ': number = images.index(self.thisfile.relative_path) + 1 - new_command = command.replace("sxiv ", - "sxiv -n %d " % number, 1) + new_command = command.replace("sxiv ", "sxiv -n %d " % number, 1) if command[0:4] == 'feh ': - new_command = command.replace("feh ", - "feh --start-at %s " % - shell_quote(self.thisfile.relative_path), 1) + new_command = command.replace( + "feh ", + "feh --start-at %s " % shell_quote(self.thisfile.relative_path), + 1, + ) if command[0:4] == 'imv ': number = images.index(self.thisfile.relative_path) + 1 - new_command = command.replace("imv ", - "imv -n %d " % number, 1) + new_command = command.replace("imv ", "imv -n %d " % number, 1) if command[0:5] == 'pqiv ': number = images.index(self.thisfile.relative_path) - new_command = command.replace("pqiv ", - "pqiv --action \"goto_file_byindex(%d)\" " % - number, 1) + new_command = command.replace( + "pqiv ", "pqiv --action \"goto_file_byindex(%d)\" " % number, 1) if new_command: - command = "set -- %s; %s" % (escaped_filenames, - new_command) + command = "set -- %s; %s" % (escaped_filenames, new_command) return old_preprocessing_hook(command) self.rifle.hook_command_preprocessing = sxiv_workaround_hook @@ -190,9 +185,10 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes self.notify(text, bad=True) self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self) - self.settings.signal_bind('setopt.metadata_deep_search', - lambda signal: setattr(signal.fm.metadata, 'deep_search', - signal.value)) + self.settings.signal_bind( + 'setopt.metadata_deep_search', + lambda signal: setattr(signal.fm.metadata, 'deep_search', signal.value) + ) def destroy(self): debug = ranger.args.debug diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index e83dd10c..8b225787 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -85,8 +85,8 @@ class PermissionsLinemode(LinemodeBase): name = "permissions" def filetitle(self, fobj, metadata): - return "%s %s %s %s" % (fobj.get_permission_string(), - fobj.user, fobj.group, fobj.relative_path) + return "%s %s %s %s" % ( + fobj.get_permission_string(), fobj.user, fobj.group, fobj.relative_path) def infostring(self, fobj, metadata): return "" diff --git a/ranger/core/loader.py b/ranger/core/loader.py index b4a97394..db1f0651 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -98,12 +98,12 @@ class CopyLoader(Loadable, FileManagerAware): # pylint: disable=too-many-instan if path == fobj.path or str(path).startswith(fobj.path): tag = self.fm.tags.tags[path] self.fm.tags.remove(path) - self.fm.tags.tags[path.replace(fobj.path, self.original_path - + '/' + fobj.basename)] = tag + self.fm.tags.tags[ + path.replace(fobj.path, self.original_path + '/' + fobj.basename) + ] = tag self.fm.tags.dump() n = 0 - for n in shutil_g.move(src=fobj.path, - dst=self.original_path, + for n in shutil_g.move(src=fobj.path, dst=self.original_path, overwrite=self.overwrite): self.percent = float(done + n) / size * 100. yield @@ -116,19 +116,19 @@ class CopyLoader(Loadable, FileManagerAware): # pylint: disable=too-many-instan for fobj in self.copy_buffer: if os.path.isdir(fobj.path) and not os.path.islink(fobj.path): n = 0 - for n in shutil_g.copytree(src=fobj.path, - dst=os.path.join( - self.original_path, fobj.basename), - symlinks=True, - overwrite=self.overwrite): + for n in shutil_g.copytree( + src=fobj.path, + dst=os.path.join(self.original_path, fobj.basename), + symlinks=True, + overwrite=self.overwrite, + ): self.percent = float(done + n) / size * 100. yield done += n else: n = 0 for n in shutil_g.copy2(fobj.path, self.original_path, - symlinks=True, - overwrite=self.overwrite): + symlinks=True, overwrite=self.overwrite): self.percent = float(done + n) / size * 100. yield done += n diff --git a/ranger/core/metadata.py b/ranger/core/metadata.py index 238b709d..76ff2bb9 100644 --- a/ranger/core/metadata.py +++ b/ranger/core/metadata.py @@ -122,8 +122,7 @@ class MetadataManager(object): try: entries = json.load(fobj) except ValueError: - raise ValueError("Failed decoding JSON file %s" % - metafile) + raise ValueError("Failed decoding JSON file %s" % metafile) self.metafile_cache[metafile] = entries return entries diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index 01f61369..7c75214e 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -97,8 +97,7 @@ class W3MImageDisplayer(ImageDisplayer): fretint = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, farg) rows, cols, xpixels, ypixels = struct.unpack("HHHH", fretint) if xpixels == 0 and ypixels == 0: - process = Popen([self.binary_path, "-test"], - stdout=PIPE, universal_newlines=True) + process = Popen([self.binary_path, "-test"], stdout=PIPE, universal_newlines=True) output, _ = process.communicate() output = output.split() xpixels, ypixels = int(output[0]), int(output[1]) @@ -111,8 +110,7 @@ class W3MImageDisplayer(ImageDisplayer): def draw(self, path, start_x, start_y, width, height): if not self.is_initialized or self.process.poll() is not None: self.initialize() - self.process.stdin.write(self._generate_w3m_input(path, start_x, - start_y, width, height)) + self.process.stdin.write(self._generate_w3m_input(path, start_x, start_y, width, height)) self.process.stdin.flush() self.process.stdout.readline() @@ -127,8 +125,9 @@ class W3MImageDisplayer(ImageDisplayer): y=start_y * fonth, # y = int((start_y + 1) * fonth), # (for tmux top status bar) w=int((width + 0.4) * fontw), - h=height * fonth + 1) - # h = (height - 1) * fonth + 1) # (for tmux top status bar) + h=height * fonth + 1, + # h = (height - 1) * fonth + 1, # (for tmux top status bar) + ) try: self.process.stdin.write(cmd) @@ -181,7 +180,8 @@ class W3MImageDisplayer(ImageDisplayer): # y = (start_y + 1) * fonth, # (for tmux top status bar) w=width, h=height, - filename=path) + filename=path, + ) def quit(self): if self.is_initialized and self.process and self.process.poll() is None: diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 2f6c8823..6c5d70be 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -150,8 +150,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self.rules = None # get paths for mimetype files - self._mimetype_known_files = [ - os.path.expanduser("~/.mime.types")] + self._mimetype_known_files = [os.path.expanduser("~/.mime.types")] if __file__.endswith("ranger/ext/rifle.py"): # Add ranger's default mimetypes when run from ranger directory self._mimetype_known_files.append( @@ -178,8 +177,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes command = command.strip() self.rules.append((command, tests)) except Exception as ex: - self.hook_logger("Syntax error in %s line %d (%s)" % - (config_file, lineno, str(ex))) + self.hook_logger( + "Syntax error in %s line %d (%s)" % (config_file, lineno, str(ex))) fobj.close() def _eval_condition(self, condition, files, label): @@ -262,8 +261,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes self._mimetype, _ = mimetypes.guess_type(fname) if not self._mimetype: - process = Popen(["file", "--mime-type", "-Lb", fname], - stdout=PIPE, stderr=PIPE) + process = Popen(["file", "--mime-type", "-Lb", fname], stdout=PIPE, stderr=PIPE) mimetype, _ = process.communicate() self._mimetype = mimetype.decode(ENCODING).strip() return self._mimetype @@ -273,8 +271,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes if isinstance(flags, str): self._app_flags += flags self._app_flags = squash_flags(self._app_flags) - filenames = "' '".join(f.replace("'", "'\\\''") for f in files - if "\x00" not in f) + filenames = "' '".join(f.replace("'", "'\\\''") for f in files if "\x00" not in f) return "set -- '%s'; %s" % (filenames, action) def list_commands(self, files, mimetype=None): @@ -451,8 +448,7 @@ def main(): # pylint: disable=too-many-locals for count, cmd, label, flags in rifle.list_commands(positional): print("%d:%s:%s:%s" % (count, label or '', flags, cmd)) else: - result = rifle.execute(positional, number=number, label=label, - flags=options.f) + result = rifle.execute(positional, number=number, label=label, flags=options.f) if result == ASK_COMMAND: # TODO: implement interactive asking for file type? print("Unknown file type: %s" % diff --git a/ranger/ext/shell_escape.py b/ranger/ext/shell_escape.py index 17ad47a5..64ddb086 100644 --- a/ranger/ext/shell_escape.py +++ b/ranger/ext/shell_escape.py @@ -8,8 +8,7 @@ from __future__ import (absolute_import, print_function) META_CHARS = (' ', "'", '"', '`', '&', '|', ';', '#', '$', '!', '(', ')', '[', ']', '<', '>', '\t') -UNESCAPABLE = set(map(chr, list(range(9)) + list(range(10, 32)) - + list(range(127, 256)))) +UNESCAPABLE = set(map(chr, list(range(9)) + list(range(10, 32)) + list(range(127, 256)))) META_DICT = dict([(mc, '\\' + mc) for mc in META_CHARS]) diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py index 737ebec2..85d1d698 100644 --- a/ranger/ext/shutil_generatorized.py +++ b/ranger/ext/shutil_generatorized.py @@ -201,15 +201,13 @@ def copytree(src, dst, # pylint: disable=too-many-locals,too-many-branches copystat(srcname, dstname) elif os.path.isdir(srcname): n = 0 - for n in copytree(srcname, dstname, symlinks, - ignore, overwrite): + for n in copytree(srcname, dstname, symlinks, ignore, overwrite): yield done + n done += n else: # Will raise a SpecialFileError for unsupported file types n = 0 - for n in copy2(srcname, dstname, - overwrite=overwrite, symlinks=symlinks): + for n in copy2(srcname, dstname, overwrite=overwrite, symlinks=symlinks): yield done + n done += n # catch the Error from the recursive copytree so that we can diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py index f98b1562..caab1c80 100644 --- a/ranger/ext/widestring.py +++ b/ranger/ext/widestring.py @@ -83,8 +83,7 @@ class WideString(object): # pylint: disable=too-few-public-methods if isinstance(string, str): return WideString(self.string + string) elif isinstance(string, WideString): - return WideString(self.string + string.string, - self.chars + string.chars) + return WideString(self.string + string.string, self.chars + string.chars) def __radd__(self, string): """ @@ -94,8 +93,7 @@ class WideString(object): # pylint: disable=too-few-public-methods if isinstance(string, str): return WideString(string + self.string) elif isinstance(string, WideString): - return WideString(string.string + self.string, - string.chars + self.chars) + return WideString(string.string + self.string, string.chars + self.chars) def __str__(self): return self.string diff --git a/ranger/gui/color.py b/ranger/gui/color.py index cc2e9a52..06ed4d3a 100644 --- a/ranger/gui/color.py +++ b/ranger/gui/color.py @@ -49,23 +49,23 @@ def get_color(fg, bg): return COLOR_PAIRS[key] -# pylint: disable=invalid-name -black = curses.COLOR_BLACK -blue = curses.COLOR_BLUE -cyan = curses.COLOR_CYAN -green = curses.COLOR_GREEN -magenta = curses.COLOR_MAGENTA -red = curses.COLOR_RED -white = curses.COLOR_WHITE -yellow = curses.COLOR_YELLOW -default = -1 +# pylint: disable=invalid-name,bad-whitespace +black = curses.COLOR_BLACK +blue = curses.COLOR_BLUE +cyan = curses.COLOR_CYAN +green = curses.COLOR_GREEN +magenta = curses.COLOR_MAGENTA +red = curses.COLOR_RED +white = curses.COLOR_WHITE +yellow = curses.COLOR_YELLOW +default = -1 -normal = curses.A_NORMAL -bold = curses.A_BOLD -blink = curses.A_BLINK -reverse = curses.A_REVERSE -underline = curses.A_UNDERLINE -invisible = curses.A_INVIS +normal = curses.A_NORMAL +bold = curses.A_BOLD +blink = curses.A_BLINK +reverse = curses.A_REVERSE +underline = curses.A_UNDERLINE +invisible = curses.A_INVIS default_colors = (default, default, normal) -# pylint: enable=invalid-name +# pylint: enable=invalid-name,bad-whitespace diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index e077c2eb..9bd96b17 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -53,8 +53,7 @@ class ColorScheme(object): """ context = Context(keys) color = self.use(context) - if len(color) != 3 or not all(isinstance(value, int) - for value in color): + if len(color) != 3 or not all(isinstance(value, int) for value in color): raise ValueError("Bad Value from colorscheme. Need " "a tuple of (foreground_color, background_color, attribute).") return color @@ -125,8 +124,8 @@ def _colorscheme_name_to_class(signal): # pylint: disable=too-many-branches else: if usecustom: allow_access_to_confdir(ranger.args.confdir, True) - scheme_module = getattr(__import__(scheme_supermodule, - globals(), locals(), [scheme_name], 0), scheme_name) + scheme_module = getattr( + __import__(scheme_supermodule, globals(), locals(), [scheme_name], 0), scheme_name) if usecustom: allow_access_to_confdir(ranger.args.confdir, False) if hasattr(scheme_module, 'Scheme') \ diff --git a/ranger/gui/context.py b/ranger/gui/context.py index dd1320f5..dec00892 100644 --- a/ranger/gui/context.py +++ b/ranger/gui/context.py @@ -4,26 +4,28 @@ from __future__ import (absolute_import, print_function) -CONTEXT_KEYS = ['reset', 'error', 'badinfo', - 'in_browser', 'in_statusbar', 'in_titlebar', 'in_console', - 'in_pager', 'in_taskview', - 'active_pane', 'inactive_pane', - 'directory', 'file', 'hostname', - 'executable', 'media', 'link', 'fifo', 'socket', 'device', - 'video', 'audio', 'image', 'media', 'document', 'container', - 'selected', 'empty', 'main_column', 'message', 'background', - 'good', 'bad', - 'space', 'permissions', 'owner', 'group', 'mtime', 'nlink', - 'scroll', 'all', 'bot', 'top', 'percentage', 'filter', - 'flat', 'marked', 'tagged', 'tag_marker', 'cut', 'copied', - 'help_markup', # COMPAT - 'seperator', 'key', 'special', 'border', # COMPAT - 'title', 'text', 'highlight', 'bars', 'quotes', 'tab', 'loaded', - 'keybuffer', - 'infostring', - 'vcsfile', 'vcsremote', 'vcsinfo', 'vcscommit', 'vcsdate', - 'vcsconflict', 'vcschanged', 'vcsunknown', 'vcsignored', - 'vcsstaged', 'vcssync', 'vcsnone', 'vcsbehind', 'vcsahead', 'vcsdiverged'] +CONTEXT_KEYS = [ + 'reset', 'error', 'badinfo', + 'in_browser', 'in_statusbar', 'in_titlebar', 'in_console', + 'in_pager', 'in_taskview', + 'active_pane', 'inactive_pane', + 'directory', 'file', 'hostname', + 'executable', 'media', 'link', 'fifo', 'socket', 'device', + 'video', 'audio', 'image', 'media', 'document', 'container', + 'selected', 'empty', 'main_column', 'message', 'background', + 'good', 'bad', + 'space', 'permissions', 'owner', 'group', 'mtime', 'nlink', + 'scroll', 'all', 'bot', 'top', 'percentage', 'filter', + 'flat', 'marked', 'tagged', 'tag_marker', 'cut', 'copied', + 'help_markup', # COMPAT + 'seperator', 'key', 'special', 'border', # COMPAT + 'title', 'text', 'highlight', 'bars', 'quotes', 'tab', 'loaded', + 'keybuffer', + 'infostring', + 'vcsfile', 'vcsremote', 'vcsinfo', 'vcscommit', 'vcsdate', + 'vcsconflict', 'vcschanged', 'vcsunknown', 'vcsignored', + 'vcsstaged', 'vcssync', 'vcsnone', 'vcsbehind', 'vcsahead', 'vcsdiverged' +] class Context(object): # pylint: disable=too-few-public-methods diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py index 8c298440..16c78a91 100644 --- a/ranger/gui/displayable.py +++ b/ranger/gui/displayable.py @@ -161,9 +161,11 @@ class Displayable( # pylint: disable=too-many-instance-attributes "(x = %d, y = %d)" % (self, x, y), bad=True) if x + wid > maxx or y + hei > maxy: - self.fm.notify("Warning: Subwindow size out of bounds for <%s> " - "(x = %d, y = %d, hei = %d, wid = %d)" % (self, - x, y, hei, wid), bad=True) + self.fm.notify( + "Warning: Subwindow size out of bounds for <%s> " + "(x = %d, y = %d, hei = %d, wid = %d)" % (self, x, y, hei, wid), + bad=True, + ) window_is_cleared = False diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py index 2fd77a41..5a5f687f 100644 --- a/ranger/gui/mouse_event.py +++ b/ranger/gui/mouse_event.py @@ -7,11 +7,13 @@ import curses class MouseEvent(object): - PRESSED = [0, - curses.BUTTON1_PRESSED, - curses.BUTTON2_PRESSED, - curses.BUTTON3_PRESSED, - curses.BUTTON4_PRESSED] + PRESSED = [ + 0, + curses.BUTTON1_PRESSED, + curses.BUTTON2_PRESSED, + curses.BUTTON3_PRESSED, + curses.BUTTON4_PRESSED, + ] CTRL_SCROLLWHEEL_MULTIPLIER = 5 def __init__(self, getmouse): diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 0b171ae6..97938453 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -190,9 +190,11 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method if keybuffer.result is not None: try: - self.fm.execute_console(keybuffer.result, - wildcards=keybuffer.wildcards, - quantifier=keybuffer.quantifier) + self.fm.execute_console( + keybuffer.result, + wildcards=keybuffer.wildcards, + quantifier=keybuffer.quantifier, + ) finally: if keybuffer.finished_parsing: keybuffer.clear() @@ -344,9 +346,11 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method try: fixed_cwd = cwd.encode('utf-8', 'surrogateescape'). \ decode('utf-8', 'replace') - sys.stdout.write("%sranger:%s%s" % - (curses.tigetstr('tsl').decode('latin-1'), fixed_cwd, - curses.tigetstr('fsl').decode('latin-1'))) + sys.stdout.write("%sranger:%s%s" % ( + curses.tigetstr('tsl').decode('latin-1'), + fixed_cwd, + curses.tigetstr('fsl').decode('latin-1'), + )) sys.stdout.flush() except Exception: pass diff --git a/ranger/gui/widgets/__init__.py b/ranger/gui/widgets/__init__.py index 3dde76a6..7fa796f6 100644 --- a/ranger/gui/widgets/__init__.py +++ b/ranger/gui/widgets/__init__.py @@ -9,24 +9,39 @@ class Widget(Displayable): """A class for classification of widgets.""" vcsstatus_symb = { - 'conflict': ('X', ['vcsconflict']), - 'untracked': ('+', ['vcschanged']), - 'deleted': ('-', ['vcschanged']), - 'changed': ('*', ['vcschanged']), - 'staged': ('*', ['vcsstaged']), - 'ignored': ('·', ['vcsignored']), - 'sync': ('√', ['vcssync']), - 'none': (' ', []), - 'unknown': ('?', ['vcsunknown']), + 'conflict': ( + 'X', ['vcsconflict']), + 'untracked': ( + '+', ['vcschanged']), + 'deleted': ( + '-', ['vcschanged']), + 'changed': ( + '*', ['vcschanged']), + 'staged': ( + '*', ['vcsstaged']), + 'ignored': ( + '·', ['vcsignored']), + 'sync': ( + '√', ['vcssync']), + 'none': ( + ' ', []), + 'unknown': ( + '?', ['vcsunknown']), } vcsremotestatus_symb = { - 'diverged': ('Y', ['vcsdiverged']), - 'ahead': ('>', ['vcsahead']), - 'behind': ('<', ['vcsbehind']), - 'sync': ('=', ['vcssync']), - 'none': ('⌂', ['vcsnone']), - 'unknown': ('?', ['vcsunknown']), + 'diverged': ( + 'Y', ['vcsdiverged']), + 'ahead': ( + '>', ['vcsahead']), + 'behind': ( + '<', ['vcsbehind']), + 'sync': ( + '=', ['vcssync']), + 'none': ( + '⌂', ['vcsnone']), + 'unknown': ( + '?', ['vcsunknown']), } ellipsis = {False: '~', True: '…'} diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 578c61f8..222457c2 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -510,12 +510,10 @@ class BrowserColumn(Pager): # pylint: disable=too-many-instance-attributes return original if projected > upper_limit: - return min(dirsize - winsize, - original + (projected - upper_limit)) + return min(dirsize - winsize, original + (projected - upper_limit)) if projected < upper_limit: - return max(0, - original - (lower_limit - projected)) + return max(0, original - (lower_limit - projected)) return original diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py index 2e913f95..d7c5571b 100644 --- a/ranger/gui/widgets/taskview.py +++ b/ranger/gui/widgets/taskview.py @@ -53,10 +53,8 @@ class TaskView(Widget, Accumulator): clr.append('selected') descr = obj.get_description() - if obj.progressbar_supported and obj.percent >= 0 \ - and obj.percent <= 100: - self.addstr(y, 0, "%3.2f%% - %s" % - (obj.percent, descr), self.wid) + if obj.progressbar_supported and obj.percent >= 0 and obj.percent <= 100: + self.addstr(y, 0, "%3.2f%% - %s" % (obj.percent, descr), self.wid) wid = int(self.wid / 100.0 * obj.percent) self.color_at(y, 0, self.wid, tuple(clr)) self.color_at(y, 0, wid, tuple(clr), 'loaded') diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index a9f2caaf..fc5aeeab 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -43,8 +43,7 @@ class TitleBar(Widget): self._print_result(self.result) if self.wid > 2: self.color('in_titlebar', 'throbber') - self.addnstr(self.y, self.wid - 2 - self.tab_width, - self.throbber, 1) + self.addnstr(self.y, self.wid - 2 - self.tab_width, self.throbber, 1) def click(self, event): """Handle a MouseEvent""" diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index b91c7e21..001f40b3 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -57,7 +57,7 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan else: try: col_x = self.main_column.x - col_y = self.main_column.y + self.main_column.target.pointer\ + col_y = self.main_column.y + self.main_column.target.pointer \ - self.main_column.scroll_begin self.fm.ui.win.move(col_y, col_x) except Exception: @@ -69,9 +69,14 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan self.color_reset() self.need_clear = True - sorted_bookmarks = sorted((item for item in self.fm.bookmarks - if self.fm.settings.show_hidden_bookmarks or - '/.' not in item[1].path), key=lambda t: t[0].lower()) + sorted_bookmarks = sorted( + ( + item for item in self.fm.bookmarks + if self.fm.settings.show_hidden_bookmarks or + '/.' not in item[1].path + ), + key=lambda t: t[0].lower(), + ) hei = min(self.hei - 1, len(sorted_bookmarks)) ystart = self.hei - hei @@ -119,8 +124,7 @@ class ViewBase(Widget, DisplayableContainer): # pylint: disable=too-many-instan hei = min(self.hei - 1, len(hints)) ystart = self.hei - hei - self.addnstr(ystart - 1, 0, "key command".ljust(self.wid), - self.wid) + self.addnstr(ystart - 1, 0, "key command".ljust(self.wid), self.wid) try: self.win.chgat(ystart - 1, 0, curses.A_UNDERLINE) except Exception: diff --git a/ranger/gui/widgets/view_miller.py b/ranger/gui/widgets/view_miller.py index aaaba3d4..47e66060 100644 --- a/ranger/gui/widgets/view_miller.py +++ b/ranger/gui/widgets/view_miller.py @@ -124,8 +124,7 @@ class ViewMiller(ViewBase): # pylint: disable=too-many-ancestors,too-many-insta # Shift the rightmost vertical line to the left to create a padding, # but only when padding_right is on, the preview column is collapsed # and we did not open the pager to "zoom" in to the file. - if self.settings.padding_right and not self.pager.visible and \ - self.is_collapsed: + if self.settings.padding_right and not self.pager.visible and self.is_collapsed: right_end = self.columns[-1].x - 1 if right_end < left_start: right_end = self.wid - 1 @@ -134,8 +133,7 @@ class ViewMiller(ViewBase): # pylint: disable=too-many-ancestors,too-many-insta try: # pylint: disable=no-member win.hline(0, left_start, curses.ACS_HLINE, right_end - left_start) - win.hline(self.hei - 1, left_start, curses.ACS_HLINE, - right_end - left_start) + win.hline(self.hei - 1, left_start, curses.ACS_HLINE, right_end - left_start) win.vline(1, left_start, curses.ACS_VLINE, self.hei - 2) # pylint: enable=no-member except _curses.error: @@ -223,17 +221,14 @@ class ViewMiller(ViewBase): # pylint: disable=too-many-ancestors,too-many-insta continue if i == last_i - 1: - self.pager.resize(pad, left, hei - pad * 2, - max(1, self.wid - left - pad)) + self.pager.resize(pad, left, hei - pad * 2, max(1, self.wid - left - pad)) if cut_off: - self.columns[i].resize(pad, left, hei - pad * 2, - max(1, self.wid - left - pad)) + self.columns[i].resize(pad, left, hei - pad * 2, max(1, self.wid - left - pad)) continue try: - self.columns[i].resize(pad, left, hei - pad * 2, - max(1, wid - 1)) + self.columns[i].resize(pad, left, hei - pad * 2, max(1, wid - 1)) except KeyError: pass diff --git a/tox.ini b/tox.ini index 61d90815..f5072c08 100644 --- a/tox.ini +++ b/tox.ini @@ -1,2 +1,3 @@ [flake8] max-line-length = 99 +ignore = E221 |