diff options
-rw-r--r-- | ranger/api/commands.py | 17 | ||||
-rw-r--r-- | ranger/core/actions.py | 69 |
2 files changed, 60 insertions, 26 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 9bbc0de0..f984342c 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -41,12 +41,9 @@ class CommandContainer(object): def load_commands_from_module(self, module): for varname, var in vars(module).items(): try: - if issubclass(var, Command) and var != Command: - classdict = var.__mro__[0].__dict__ - if 'name' in classdict and classdict['name']: - self.commands[var.name] = var - else: - self.commands[varname] = var + if issubclass(var, Command) and var != Command \ + and var != FunctionCommand: + self.commands[var.get_name()] = var except TypeError: pass @@ -97,6 +94,14 @@ class Command(FileManagerAware): self.args = line.split() self.quantifier = quantifier + @classmethod + def get_name(self): + classdict = self.__mro__[0].__dict__ + if 'name' in classdict and classdict['name']: + return self.name + else: + return self.__name__ + def execute(self): """Override this""" diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 935534ce..080d4b86 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -17,8 +17,8 @@ import codecs import os import re import shutil -import subprocess import string +import tempfile from os.path import join, isdir, realpath from os import link, symlink, getcwd from inspect import cleandoc @@ -771,10 +771,12 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): # -------------------------- def dump_keybindings(self, *contexts): - self.ui.suspend() - p = subprocess.Popen(['less'], stdin=subprocess.PIPE) + if not contexts: + contexts = 'browser', 'console', 'pager', 'taskview' + + temporary_file = tempfile.NamedTemporaryFile() def write(string): - p.stdin.write(string.encode('utf-8')) + temporary_file.write(string.encode('utf-8')) def recurse(before, pointer): for key, value in pointer.items(): @@ -782,23 +784,50 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): if isinstance(value, dict): recurse(keys, value) else: - write("%12s %s\n" % (construct_keybinding(keys), value)) - if not contexts: - contexts = 'browser', 'console', 'pager', 'taskview' + try: + write("%12s %s\n" % (construct_keybinding(keys), value)) + except: + write("olo\n") - try: - for context in contexts: - write("Keybindings in `%s'\n" % context) - if context in self.env.keymaps: - recurse([], self.env.keymaps[context]) - else: - write(" None\n") - write("\n") - p.stdin.close() - except IOError: - pass - p.wait() - self.ui.initialize() + for context in contexts: + write("Keybindings in `%s'\n" % context) + if context in self.env.keymaps: + recurse([], self.env.keymaps[context]) + else: + write(" None\n") + write("\n") + + temporary_file.flush() + self.run(app='pager', files=[File(temporary_file.name)]) + + def dump_commands(self): + from inspect import cleandoc + temporary_file = tempfile.NamedTemporaryFile() + def write(string): + temporary_file.write(string.encode('utf-8')) + + for cmd_name in sorted(self.commands.commands): + cmd = self.commands.commands[cmd_name] + if hasattr(cmd, '__doc__') and cmd.__doc__: + write(cleandoc(cmd.__doc__)) + else: + write(":%s - No documentation available." % cmd.get_name()) + write("\n\n" + "=" * 60 + "\n") + + temporary_file.flush() + self.run(app='pager', files=[File(temporary_file.name)]) + + def dump_settings(self): + from ranger.container.settingobject import ALLOWED_SETTINGS + temporary_file = tempfile.NamedTemporaryFile() + def write(string): + temporary_file.write(string.encode('utf-8')) + + for setting in sorted(ALLOWED_SETTINGS): + write("%30s = %s\n" % (setting, getattr(self.settings, setting))) + + temporary_file.flush() + self.run(app='pager', files=[File(temporary_file.name)]) # -------------------------- # -- File System Operations |