diff options
-rw-r--r-- | ranger/config/rifle.conf | 5 | ||||
-rw-r--r-- | ranger/core/fm.py | 6 | ||||
-rw-r--r-- | ranger/core/linemode.py | 5 | ||||
-rw-r--r-- | ranger/core/main.py | 11 | ||||
-rwxr-xr-x | ranger/data/scope.sh | 6 | ||||
-rw-r--r-- | ranger/ext/spawn.py | 49 | ||||
-rw-r--r-- | ranger/ext/vcs/vcs.py | 35 | ||||
-rw-r--r-- | ranger/gui/widgets/pager.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 2 |
9 files changed, 86 insertions, 35 deletions
diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf index d6165f21..aadc2f2c 100644 --- a/ranger/config/rifle.conf +++ b/ranger/config/rifle.conf @@ -181,8 +181,11 @@ ext xcf, X, flag f = gimp -- "$@" #------------------------------------------- # Archives #------------------------------------------- + +# avoid password prompt by providing empty password +ext 7z, has 7z = 7z -p l "$@" | "$PAGER" # This requires atool -ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has als = als -- "$@" | "$PAGER" +ext ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has als = als -- "$@" | "$PAGER" ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has als = als -- "$@" | "$PAGER" ext 7z|ace|ar|arc|bz2?|cab|cpio|cpt|deb|dgc|dmg|gz, has aunpack = aunpack -- "$@" ext iso|jar|msi|pkg|rar|shar|tar|tgz|xar|xpi|xz|zip, has aunpack = aunpack -- "$@" diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 8168b7d6..fb6dd6b9 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -49,7 +49,7 @@ class FM(Actions, SignalDispatcher): self.ui = ui self.start_paths = paths self.directories = dict() - self.log = deque(maxlen=20) + self.log = deque(maxlen=1000) self.bookmarks = bookmarks self.current_tab = 1 self.tabs = {} @@ -70,9 +70,9 @@ class FM(Actions, SignalDispatcher): self.hostname = socket.gethostname() self.home_path = os.path.expanduser('~') - self.log.append('ranger {0} started! Process ID is {1}.' + self.log.appendleft('ranger {0} started! Process ID is {1}.' .format(__version__, os.getpid())) - self.log.append('Running on Python ' + sys.version.replace('\n', '')) + self.log.appendleft('Running on Python ' + sys.version.replace('\n', '')) mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types')) mimetypes.knownfiles.append(self.relpath('data/mime.types')) diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index 96557515..a8ce4e6d 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -7,6 +7,7 @@ import sys from abc import * from datetime import datetime from ranger.ext.human_readable import human_readable +from ranger.ext.spawn import spawn DEFAULT_LINEMODE = "filename" @@ -97,9 +98,9 @@ class FileInfoLinemode(LinemodeBase): def infostring(self, file, metadata): if not file.is_directory: - from subprocess import check_output, CalledProcessError + from subprocess import Popen, PIPE, CalledProcessError try: - fileinfo = check_output(["file", "-bL", file.path]).strip() + fileinfo = spawn(["file", "-bL", file.path]).strip() except CalledProcessError: return "unknown" if sys.version_info[0] >= 3: diff --git a/ranger/core/main.py b/ranger/core/main.py index 118a7480..93c71e81 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -112,7 +112,7 @@ def main(): if fm.username == 'root': fm.settings.preview_files = False fm.settings.use_preview_script = False - fm.log.append("Running as root, disabling the file previews.") + fm.log.appendleft("Running as root, disabling the file previews.") if not arg.debug: from ranger.ext import curses_interrupt_handler curses_interrupt_handler.install_interrupt_handler() @@ -313,12 +313,11 @@ def load_settings(fm, clean): else: module = importlib.import_module('plugins.' + plugin) fm.commands.load_commands_from_module(module) - fm.log.append("Loaded plugin '%s'." % plugin) - except Exception as e: - fm.log.append("Error in plugin '%s'" % plugin) + fm.log.appendleft("Loaded plugin '%s'." % plugin) + except Exception: import traceback - for line in traceback.format_exception_only(type(e), e): - fm.log.append(line) + fm.log.extendleft(reversed(traceback.format_exc().splitlines())) + fm.notify("Error in plugin '%s'" % plugin, bad=True) ranger.fm = None # COMPAT: Load the outdated options.py diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 44fcec2b..a0fb2ec0 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -65,14 +65,18 @@ fi case "$extension" in # Archive extensions: - 7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ + a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip) try als "$path" && { dump | trim; exit 0; } try acat "$path" && { dump | trim; exit 3; } try bsdtar -lf "$path" && { dump | trim; exit 0; } exit 1;; rar) + # avoid password prompt by providing empty password try unrar -p- lt "$path" && { dump | trim; exit 0; } || exit 1;; + 7z) + # avoid password prompt by providing empty password + try 7z -p l "$path" && { dump | trim; exit 0; } || exit 1;; # PDF documents: pdf) try pdftotext -l 10 -nopgbrk -q "$path" - && \ diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py index 7c5c921c..393d48d9 100644 --- a/ranger/ext/spawn.py +++ b/ranger/ext/spawn.py @@ -1,18 +1,57 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. -from subprocess import Popen, PIPE +from subprocess import Popen, PIPE, CalledProcessError ENCODING = 'utf-8' -def spawn(*args): - """Runs a program, waits for its termination and returns its stdout""" +def spawn(*args, **kwargs): + """Runs a program, waits for its termination and returns its stdout + + This function is similar to python 2.7's subprocess.check_output, + but is favored due to python 2.6 compatibility. + + The arguments may be: + + spawn(string) + spawn(command, arg1, arg2...) + spawn([command, arg1, arg2]) + + The string will be run through a shell, otherwise the command is executed + directly. + + The keyword argument "decode" determines if the output shall be decoded + with the encoding '%s'. + + Further keyword arguments are passed to Popen. + """ % (ENCODING, ) + if len(args) == 1: popen_arguments = args[0] shell = isinstance(popen_arguments, str) else: popen_arguments = args shell = False - process = Popen(popen_arguments, stdout=PIPE, shell=shell) + + if 'decode' in kwargs: + do_decode = kwargs['decode'] + del kwargs['decode'] + else: + do_decode = True + if 'stdout' not in kwargs: + kwargs['stdout'] = PIPE + if 'shell' not in kwargs: + kwargs['shell'] = shell + + process = Popen(popen_arguments, **kwargs) stdout, stderr = process.communicate() - return stdout.decode(ENCODING) + return_value = process.poll() + if return_value: + error = CalledProcessError(return_value, popen_arguments[0]) + error.output = stdout + raise error + + if do_decode: + return stdout.decode(ENCODING) + else: + return stdout diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index 9c7be653..cfdc1e3b 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -7,6 +7,7 @@ import os import subprocess import threading import time +from ranger.ext.spawn import spawn # Python2 compatibility try: @@ -119,14 +120,13 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes with open(os.devnull, 'w') as devnull: try: if catchout: - output = subprocess.check_output(cmd, cwd=path, stderr=devnull) - if retbytes: - return output - else: - output = output.decode('UTF-8') + output = spawn(cmd, cwd=path, stderr=devnull, + decode=not retbytes) + if (not retbytes and rstrip_newline and + output.endswith('\n')): if rstrip_newline and output.endswith('\n'): return output[:-1] - return output + return output else: subprocess.check_call(cmd, cwd=path, stdout=devnull, stderr=devnull) except (subprocess.CalledProcessError, FileNotFoundError): @@ -460,15 +460,20 @@ class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attribut self.paused.clear() self.awoken.clear() - self._queue_process() - - if self.redraw: - self.redraw = False - for column in self.ui.browser.columns: - if column.target and column.target.is_directory: - column.need_redraw = True - self.ui.status.need_redraw = True - self.ui.redraw() + try: + self._queue_process() + + if self.redraw: + self.redraw = False + for column in self.ui.browser.columns: + if column.target and column.target.is_directory: + column.need_redraw = True + self.ui.status.need_redraw = True + self.ui.redraw() + except Exception: # pylint: disable=broad-except + import traceback + self.ui.fm.log.extendleft(reversed(traceback.format_exc().splitlines())) + self.ui.fm.notify('VCS Exception', bad=True) def pause(self): """Pause thread""" diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index 58b791cd..0c81079b 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -231,7 +231,7 @@ class Pager(Widget): line = ansi.char_slice(line, startx, self.wid) + ansi.reset else: line = line[startx:self.wid + startx] - yield line.rstrip() + yield line.rstrip().replace('\r\n', '\n') except IndexError: raise StopIteration i += 1 diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 0828c372..0ac62d86 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -290,7 +290,7 @@ class StatusBar(Widget): elif pos >= max_pos: right.add('Bot', base, 'bot') else: - right.add('{:0.0%}'.format(float(pos) / max_pos), + right.add('{0:0.0%}'.format(float(pos) / max_pos), base, 'percentage') else: right.add('0/0 All', base, 'all') |