diff options
author | stepshal <nessento@openmailbox.org> | 2016-06-16 18:22:57 +0700 |
---|---|---|
committer | stepshal <nessento@openmailbox.org> | 2016-06-16 18:22:57 +0700 |
commit | ab41c7766ced3f1b8f6b4ed317f0db4e0d71b897 (patch) | |
tree | 3315bb7587acb020cee88dbc0382d68671d7383e /ranger | |
parent | 7c760ac0256aa1d27433e8f410ae014be2da2334 (diff) | |
download | ranger-ab41c7766ced3f1b8f6b4ed317f0db4e0d71b897.tar.gz |
Add two blank lines where is expected
Diffstat (limited to 'ranger')
62 files changed, 127 insertions, 0 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py index b562ebf5..093a01d5 100644 --- a/ranger/__init__.py +++ b/ranger/__init__.py @@ -46,6 +46,8 @@ CONFDIR = '~/.config/ranger' # Debugging functions. These will be activated when run with --debug. # Example usage in the code: # import ranger; ranger.log("hello world") + + def log(*objects, **keywords): """Writes objects to a logfile (for the purpose of debugging only.) Has the same arguments as print() in python3. diff --git a/ranger/api/__init__.py b/ranger/api/__init__.py index 7baa661d..5981c31a 100644 --- a/ranger/api/__init__.py +++ b/ranger/api/__init__.py @@ -5,6 +5,7 @@ # Hooks for use in plugins: + def hook_init(fm): """A hook that is called when ranger starts up. @@ -18,6 +19,7 @@ def hook_init(fm): keybindings and such. """ + def hook_ready(fm): """A hook that is called after the ranger UI is initialized. @@ -32,6 +34,7 @@ def hook_ready(fm): from ranger.core.linemode import LinemodeBase + def register_linemode(linemode_class): """Add a custom linemode class. See ranger.core.linemode""" from ranger.container.fsobject import FileSystemObject diff --git a/ranger/api/commands.py b/ranger/api/commands.py index c3e0a59a..6ab2c135 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -14,6 +14,7 @@ from ranger.ext.lazy_property import lazy_property _SETTINGS_RE = re.compile(r'^\s*([^\s]+?)=(.*)$') + class CommandContainer(object): def __init__(self): self.commands = {} @@ -426,6 +427,7 @@ class FunctionCommand(Command): (self._object_name, self._function_name, repr(args), repr(keywords)), bad=True) + class AliasCommand(Command): _based_function = None _object_name = "" diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py index 37b372a3..1f5f3c8e 100644 --- a/ranger/colorschemes/default.py +++ b/ranger/colorschemes/default.py @@ -4,6 +4,7 @@ from ranger.gui.colorscheme import ColorScheme from ranger.gui.color import * + class Default(ColorScheme): progress_bar_color = blue diff --git a/ranger/colorschemes/jungle.py b/ranger/colorschemes/jungle.py index 6a9c3c52..d87706e8 100644 --- a/ranger/colorschemes/jungle.py +++ b/ranger/colorschemes/jungle.py @@ -4,6 +4,7 @@ from ranger.gui.color import * from ranger.colorschemes.default import Default + class Scheme(Default): progress_bar_color = green def use(self, context): diff --git a/ranger/colorschemes/snow.py b/ranger/colorschemes/snow.py index 849f15e4..90090854 100644 --- a/ranger/colorschemes/snow.py +++ b/ranger/colorschemes/snow.py @@ -4,6 +4,7 @@ from ranger.gui.colorscheme import ColorScheme from ranger.gui.color import * + class Snow(ColorScheme): def use(self, context): fg, bg, attr = default_colors diff --git a/ranger/colorschemes/solarized.py b/ranger/colorschemes/solarized.py index 2177ca3d..8cdfb5ce 100644 --- a/ranger/colorschemes/solarized.py +++ b/ranger/colorschemes/solarized.py @@ -8,6 +8,7 @@ from ranger.gui.colorscheme import ColorScheme from ranger.gui.color import * + class Solarized(ColorScheme): progress_bar_color = 33 diff --git a/ranger/config/commands.py b/ranger/config/commands.py index e09e1f10..ef415d44 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -85,6 +85,7 @@ from ranger.api.commands import * + class alias(Command): """:alias <newcommand> <oldcommand> @@ -237,6 +238,7 @@ class shell(Command): for file in self.fm.thisdir.files or [] \ if file.shell_escaped_basename.startswith(start_of_word)) + class open_with(Command): def execute(self): app, flags, mode = self._get_app_flags_mode(self.rest(1)) @@ -789,6 +791,7 @@ class rename(Command): def tab(self, tabnum): return self._tab_directory_content() + class rename_append(Command): """:rename_append @@ -803,6 +806,7 @@ class rename_append(Command): else: self.fm.open_console('rename ' + path) + class chmod(Command): """:chmod <octal number> @@ -920,6 +924,7 @@ class bulkrename(Command): else: fm.notify("files have not been retagged") + class relink(Command): """:relink <newpath> @@ -1325,6 +1330,7 @@ class grep(Command): action.extend(f.path for f in self.fm.thistab.get_selection()) self.fm.execute_command(action, flags='p') + class flat(Command): """ :flat <level> @@ -1350,6 +1356,7 @@ class flat(Command): # Version control commands # -------------------------------- + class stage(Command): """ :stage @@ -1369,6 +1376,7 @@ class stage(Command): else: self.fm.notify('Unable to stage files: Not in repository') + class unstage(Command): """ :unstage @@ -1391,6 +1399,7 @@ class unstage(Command): # Metadata commands # -------------------------------- + class prompt_metadata(Command): """ :prompt_metadata <key1> [<key2> [<key3> ...]] diff --git a/ranger/config/commands_sample.py b/ranger/config/commands_sample.py index ce48eb37..ea74b7d6 100644 --- a/ranger/config/commands_sample.py +++ b/ranger/config/commands_sample.py @@ -15,6 +15,8 @@ import os # Any class that is a subclass of "Command" will be integrated into ranger as a # command. Try typing ":my_edit<ENTER>" in ranger! + + class my_edit(Command): # The so-called doc-string of the class will be visible in the built-in # help that is accessible by typing "?c" inside ranger. diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py index 02f3e3bc..704c1c5f 100644 --- a/ranger/container/bookmarks.py +++ b/ranger/container/bookmarks.py @@ -6,6 +6,7 @@ import re import os ALLOWED_KEYS = string.ascii_letters + string.digits + "`'" + class Bookmarks(object): """Bookmarks is a container which associates keys with bookmarks. diff --git a/ranger/container/directory.py b/ranger/container/directory.py index e7c2b4b6..4ffd9bc2 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -20,29 +20,36 @@ from ranger.ext.human_readable import human_readable from ranger.container.settings import LocalSettings from ranger.ext.vcs import Vcs + def sort_by_basename(path): """returns path.relative_path (for sorting)""" return path.relative_path + def sort_by_basename_icase(path): """returns case-insensitive path.relative_path (for sorting)""" return path.relative_path_lower + def sort_by_directory(path): """returns 0 if path is a directory, otherwise 1 (for sorting)""" return 1 - path.is_directory + def sort_naturally(path): return path.basename_natural + def sort_naturally_icase(path): return path.basename_natural_lower + def sort_unicode_wrapper_string(old_sort_func): def sort_unicode(path): return locale.strxfrm(old_sort_func(path)) return sort_unicode + def sort_unicode_wrapper_list(old_sort_func): def sort_unicode(path): return [locale.strxfrm(str(c)) for c in old_sort_func(path)] @@ -63,6 +70,7 @@ def accept_file(file, filters): return False return True + def walklevel(some_dir, level): some_dir = some_dir.rstrip(os.path.sep) followlinks = True if level > 0 else False @@ -74,6 +82,7 @@ def walklevel(some_dir, level): if level != -1 and num_sep + level <= num_sep_this: del dirs[:] + def mtimelevel(path, level): mtime = os.stat(path).st_mtime for dirpath, dirnames, filenames in walklevel(path, level): @@ -82,6 +91,7 @@ def mtimelevel(path, level): mtime = max(mtime, max([-1] + [os.stat(d).st_mtime for d in dirlist])) return mtime + class Directory(FileSystemObject, Accumulator, Loadable): is_directory = True enterable = False diff --git a/ranger/container/file.py b/ranger/container/file.py index 2c6d8315..40a4f73d 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -37,6 +37,7 @@ PREVIEW_WHITELIST = re.compile(r""" $ """, re.VERBOSE | re.IGNORECASE) + class File(FileSystemObject): is_file = True preview_data = None diff --git a/ranger/container/fsobject.py b/ranger/container/fsobject.py index fff29c36..a61fc00a 100644 --- a/ranger/container/fsobject.py +++ b/ranger/container/fsobject.py @@ -33,9 +33,11 @@ _safe_string_table = maketrans(_unsafe_chars, '?' * len(_unsafe_chars)) _extract_number_re = re.compile(r'(\d+|\D)') _integers = set("0123456789") + def safe_path(path): return path.translate(_safe_string_table) + class FileSystemObject(FileManagerAware, SettingsAware): (basename, relative_path, diff --git a/ranger/container/history.py b/ranger/container/history.py index 69c3da57..d92f2910 100644 --- a/ranger/container/history.py +++ b/ranger/container/history.py @@ -3,9 +3,11 @@ # TODO: rewrite to use deque instead of list + class HistoryEmptyException(Exception): pass + class History(object): def __init__(self, maxlen=None, unique=True): assert maxlen is not None, "maxlen cannot be None" diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 85729907..95aca140 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -87,6 +87,7 @@ DEFAULT_VALUES = { tuple: tuple([]), } + class Settings(SignalDispatcher, FileManagerAware): def __init__(self): SignalDispatcher.__init__(self) diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 555ef8b0..cf2f359d 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -9,6 +9,7 @@ import sys ALLOWED_KEYS = string.ascii_letters + string.digits + string.punctuation + class Tags(object): default_tag = '*' diff --git a/ranger/core/actions.py b/ranger/core/actions.py index a39cef21..c75a652d 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -31,11 +31,13 @@ from ranger.core.linemode import DEFAULT_LINEMODE MACRO_FAIL = "<\x01\x01MACRO_HAS_NO_VALUE\x01\01>" + class _MacroTemplate(string.Template): """A template for substituting macros in commands""" delimiter = ranger.MACRO_DELIMITER idpattern = r"[_a-z0-9]*" + class Actions(FileManagerAware, SettingsAware): # -------------------------- # -- Basic Commands diff --git a/ranger/core/fm.py b/ranger/core/fm.py index 052584a6..b27a0fa2 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -27,6 +27,7 @@ from ranger.ext.signals import SignalDispatcher from ranger import __version__ from ranger.core.loader import Loader + class FM(Actions, SignalDispatcher): input_blocked = False input_blocked_until = 0 diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index be559578..96557515 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -108,6 +108,7 @@ class FileInfoLinemode(LinemodeBase): else: raise NotImplementedError + class MtimeLinemode(LinemodeBase): name = "mtime" @@ -117,6 +118,7 @@ class MtimeLinemode(LinemodeBase): def infostring(self, file, metadata): return datetime.fromtimestamp(file.stat.st_mtime).strftime("%Y-%m-%d %H:%M") + class SizeMtimeLinemode(LinemodeBase): name = "sizemtime" diff --git a/ranger/core/loader.py b/ranger/core/loader.py index b1aabb53..7ecfed7b 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -17,6 +17,7 @@ try: except: HAVE_CHARDET = False + class Loadable(object): paused = False progressbar_supported = False diff --git a/ranger/core/main.py b/ranger/core/main.py index 2972a1eb..924b3aa3 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -8,6 +8,7 @@ import sys import tempfile import importlib + def main(): """initialize objects and run the filemanager""" import locale diff --git a/ranger/core/metadata.py b/ranger/core/metadata.py index e7f90efd..299d2b85 100644 --- a/ranger/core/metadata.py +++ b/ranger/core/metadata.py @@ -18,6 +18,7 @@ import copy from os.path import join, dirname, exists, basename from ranger.ext.openstruct import DefaultOpenStruct as ostruct + class MetadataManager(object): def __init__(self): # metadata_cache maps filenames to dicts containing their metadata diff --git a/ranger/core/shared.py b/ranger/core/shared.py index 177ba15d..38b0d35a 100644 --- a/ranger/core/shared.py +++ b/ranger/core/shared.py @@ -5,12 +5,14 @@ from ranger.ext.lazy_property import lazy_property + class FileManagerAware(object): """Subclass this to gain access to the global "FM" object.""" @staticmethod def _setup(fm): FileManagerAware.fm = fm + class SettingsAware(object): """Subclass this to gain access to the global "SettingObject" object.""" @staticmethod diff --git a/ranger/core/tab.py b/ranger/core/tab.py index f8de953f..dc76568b 100644 --- a/ranger/core/tab.py +++ b/ranger/core/tab.py @@ -9,6 +9,7 @@ from ranger.container.history import History from ranger.core.shared import FileManagerAware, SettingsAware from ranger.ext.signals import SignalDispatcher + class Tab(FileManagerAware, SettingsAware): def __init__(self, path): self.thisdir = None # Current Working Directory diff --git a/ranger/ext/accumulator.py b/ranger/ext/accumulator.py index 278600c7..863a59df 100644 --- a/ranger/ext/accumulator.py +++ b/ranger/ext/accumulator.py @@ -3,6 +3,7 @@ from ranger.ext.direction import Direction + class Accumulator(object): def __init__(self): self.pointer = 0 diff --git a/ranger/ext/cached_function.py b/ranger/ext/cached_function.py index bce2b5ca..d2c695f9 100644 --- a/ranger/ext/cached_function.py +++ b/ranger/ext/cached_function.py @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. + def cached_function(fnc): cache = {} def inner_cached_function(*args): diff --git a/ranger/ext/curses_interrupt_handler.py b/ranger/ext/curses_interrupt_handler.py index 9ee12846..606cbd62 100644 --- a/ranger/ext/curses_interrupt_handler.py +++ b/ranger/ext/curses_interrupt_handler.py @@ -13,6 +13,7 @@ import signal _do_catch_interrupt = True + def catch_interrupt(boolean=True): """Should interrupts be caught and simulate a ^C press in curses?""" global _do_catch_interrupt @@ -21,6 +22,8 @@ def catch_interrupt(boolean=True): return old_value # The handler which will be used in signal.signal() + + def _interrupt_handler(a1, a2): global _do_catch_interrupt # if a keyboard-interrupt occurs... @@ -31,10 +34,12 @@ def _interrupt_handler(a1, a2): # use the default handler signal.default_int_handler(a1, a2) + def install_interrupt_handler(): """Install the custom interrupt_handler""" signal.signal(signal.SIGINT, _interrupt_handler) + def restore_interrupt_handler(): """Restore the default_int_handler""" signal.signal(signal.SIGINT, signal.default_int_handler) diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py index 572ce271..f236e7e3 100644 --- a/ranger/ext/direction.py +++ b/ranger/ext/direction.py @@ -18,6 +18,7 @@ has been defined. False """ + class Direction(dict): def __init__(self, dictionary=None, **keywords): if dictionary is not None: diff --git a/ranger/ext/human_readable.py b/ranger/ext/human_readable.py index af371370..31d5d279 100644 --- a/ranger/ext/human_readable.py +++ b/ranger/ext/human_readable.py @@ -1,6 +1,7 @@ # This file is part of ranger, the console file manager. # License: GNU GPL version 3, see the file "AUTHORS" for details. + def human_readable(byte, separator=' '): """Convert a large number of bytes to an easily readable format. diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index 0c6a11d4..cf883900 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -31,9 +31,11 @@ W3MIMGDISPLAY_PATHS = [ '/usr/libexec64/w3m/w3mimgdisplay' ] + class ImgDisplayUnsupportedException(Exception): pass + class ImageDisplayer(object): """Image display provider functions for drawing images in the terminal""" def draw(self, path, start_x, start_y, width, height): @@ -48,6 +50,7 @@ class ImageDisplayer(object): """Cleanup and close""" pass + class W3MImageDisplayer(ImageDisplayer): """Implementation of ImageDisplayer using w3mimgdisplay, an utilitary program from w3m (a text-based web browser). w3mimgdisplay can display @@ -178,6 +181,8 @@ class W3MImageDisplayer(ImageDisplayer): # TODO: remove FileManagerAwareness, as stuff in ranger.ext should be # ranger-independent libraries. + + class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): """Implementation of ImageDisplayer using iTerm2 image display support (http://iterm2.com/images.html). diff --git a/ranger/ext/iter_tools.py b/ranger/ext/iter_tools.py index d583d060..838d8aff 100644 --- a/ranger/ext/iter_tools.py +++ b/ranger/ext/iter_tools.py @@ -3,6 +3,7 @@ from collections import deque + def flatten(lst): """Flatten an iterable. @@ -22,6 +23,7 @@ def flatten(lst): else: yield elem + def unique(iterable): """Return an iterable of the same type which contains unique items. diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py index 8efb337f..4e9375bf 100644 --- a/ranger/ext/keybinding_parser.py +++ b/ranger/ext/keybinding_parser.py @@ -149,6 +149,7 @@ def _unbind_traverse(pointer, keys, pos=0): except: pass + class KeyMaps(dict): def __init__(self, keybuffer=None): dict.__init__(self) diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py index 9e3454b0..4bdcda1e 100644 --- a/ranger/ext/lazy_property.py +++ b/ranger/ext/lazy_property.py @@ -1,5 +1,6 @@ # From http://blog.pythonisito.com/2008/08/lazy-descriptors.html + class lazy_property(object): """A @property-like decorator with lazy evaluation diff --git a/ranger/ext/mount_path.py b/ranger/ext/mount_path.py index fdf11883..69a277af 100644 --- a/ranger/ext/mount_path.py +++ b/ranger/ext/mount_path.py @@ -3,6 +3,7 @@ from os.path import realpath, abspath, dirname, ismount + def mount_path(path): """Get the mount root of a directory""" path = abspath(realpath(path)) diff --git a/ranger/ext/next_available_filename.py b/ranger/ext/next_available_filename.py index 77a73c00..c408b35d 100644 --- a/ranger/ext/next_available_filename.py +++ b/ranger/ext/next_available_filename.py @@ -3,6 +3,7 @@ import os.path + def next_available_filename(fname, directory="."): existing_files = os.listdir(directory) diff --git a/ranger/ext/openstruct.py b/ranger/ext/openstruct.py index 96a75f49..6479d158 100644 --- a/ranger/ext/openstruct.py +++ b/ranger/ext/openstruct.py @@ -3,6 +3,7 @@ import collections + class OpenStruct(dict): """The fusion of dict and struct""" def __init__(self, *args, **keywords): diff --git a/ranger/ext/popen_forked.py b/ranger/ext/popen_forked.py index ffe8438e..d4a75a48 100644 --- a/ranger/ext/popen_forked.py +++ b/ranger/ext/popen_forked.py @@ -4,6 +4,7 @@ import os import subprocess + def Popen_forked(*args, **kwargs): """Forks process and runs Popen with the given args and kwargs. diff --git a/ranger/ext/relative_symlink.py b/ranger/ext/relative_symlink.py index fe15a98a..247d1318 100644 --- a/ranger/ext/relative_symlink.py +++ b/ranger/ext/relative_symlink.py @@ -3,15 +3,18 @@ from os import symlink, sep + def relative_symlink(src, dst): common_base = get_common_base(src, dst) symlink(get_relative_source_file(src, dst, common_base), dst) + def get_relative_source_file(src, dst, common_base=None): if common_base is None: common_base = get_common_base(src, dst) return '../' * dst.count('/', len(common_base)) + src[len(common_base):] + def get_common_base(src, dst): if not src or not dst: return '/' diff --git a/ranger/ext/shell_escape.py b/ranger/ext/shell_escape.py index a7be2068..44984405 100644 --- a/ranger/ext/shell_escape.py +++ b/ranger/ext/shell_escape.py @@ -9,10 +9,12 @@ 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]) + def shell_quote(string): """Escapes by quoting""" return "'" + str(string).replace("'", "'\\''") + "'" + def shell_escape(arg): """Escapes by adding backslashes""" arg = str(arg) diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py index 7958b048..1bf95842 100644 --- a/ranger/ext/shutil_generatorized.py +++ b/ranger/ext/shutil_generatorized.py @@ -16,9 +16,11 @@ __all__ = ["copyfileobj", "copyfile", "copystat", "copy2", "BLOCK_SIZE", APPENDIX = '_' BLOCK_SIZE = 16 * 1024 + class Error(EnvironmentError): pass + class SpecialFileError(EnvironmentError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" @@ -28,6 +30,7 @@ try: except NameError: WindowsError = None + def copyfileobj(fsrc, fdst, length=BLOCK_SIZE): """copy data from file-like object fsrc to file-like object fdst""" done = 0 @@ -39,6 +42,7 @@ def copyfileobj(fsrc, fdst, length=BLOCK_SIZE): done += len(buf) yield done + def _samefile(src, dst): # Macintosh, Unix. if hasattr(os.path, 'samefile'): @@ -51,6 +55,7 @@ def _samefile(src, dst): return (os.path.normcase(abspath(src)) == os.path.normcase(abspath(dst))) + def copyfile(src, dst): """Copy data from src to dst""" if _samefile(src, dst): @@ -79,6 +84,7 @@ def copyfile(src, dst): if fsrc: fsrc.close() + def copystat(src, dst): """Copy all stat info (mode bits, atime, mtime, flags) from src to dst""" st = os.lstat(src) @@ -93,6 +99,7 @@ def copystat(src, dst): try: os.chflags(dst, st.st_flags) except: pass + def copy2(src, dst, overwrite=False, symlinks=False): """Copy data and all stat info ("cp -p src dst"). @@ -113,6 +120,7 @@ def copy2(src, dst, overwrite=False, symlinks=False): yield done copystat(src, dst) + def get_safe_path(dst): if not os.path.exists(dst): return dst @@ -128,6 +136,7 @@ def get_safe_path(dst): return test_dst + def copytree(src, dst, symlinks=False, ignore=None, overwrite=False): """Recursively copy a directory tree using copy2(). @@ -210,6 +219,7 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False): if errors: raise Error(errors) + def rmtree(path, ignore_errors=False, onerror=None): """Recursively delete a directory tree. @@ -264,6 +274,7 @@ def _basename(path): # Thus we always get the last component of the path, even for directories. return os.path.basename(path.rstrip(os.path.sep)) + def move(src, dst, overwrite=False): """Recursively move a file or directory to another location. This is similar to the Unix "mv" command. @@ -298,6 +309,7 @@ def move(src, dst, overwrite=False): yield done os.unlink(src) + def _destinsrc(src, dst): src = abspath(src) dst = abspath(dst) diff --git a/ranger/ext/signals.py b/ranger/ext/signals.py index bcac66fe..3e536fc6 100644 --- a/ranger/ext/signals.py +++ b/ranger/ext/signals.py @@ -60,6 +60,7 @@ True import weakref from types import MethodType + class Signal(dict): """Signals are passed to the bound functions as an argument. diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py index 6c1b17b4..7c5c921c 100644 --- a/ranger/ext/spawn.py +++ b/ranger/ext/spawn.py @@ -4,6 +4,7 @@ from subprocess import Popen, PIPE ENCODING = 'utf-8' + def spawn(*args): """Runs a program, waits for its termination and returns its stdout""" if len(args) == 1: diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py index 06d32830..b042c45b 100644 --- a/ranger/ext/widestring.py +++ b/ranger/ext/widestring.py @@ -11,6 +11,7 @@ NARROW = 1 WIDE = 2 WIDE_SYMBOLS = set('WF') + def uwid(string): """Return the width of a string""" if not PY3: diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py index 601d6004..57a69442 100644 --- a/ranger/gui/ansi.py +++ b/ranger/gui/ansi.py @@ -11,11 +11,14 @@ ansi_re = re.compile('(\x1b' + r'\[\d*(?:;\d+)*?[a-zA-Z])') codesplit_re = re.compile('38;5;(\d+);|48;5;(\d+);|(\d*);') reset = '\x1b[0m' + def split_ansi_from_text(ansi_text): return ansi_re.split(ansi_text) # For information on the ANSI codes see # githttp://en.wikipedia.org/wiki/ANSI_escape_code + + def text_with_fg_bg_attr(ansi_text): fg, bg, attr = -1, -1, 0 for chunk in split_ansi_from_text(ansi_text): @@ -93,6 +96,7 @@ def text_with_fg_bg_attr(ansi_text): else: yield chunk + def char_len(ansi_text): """Count the number of visible characters. @@ -109,6 +113,7 @@ def char_len(ansi_text): """ return len(ansi_re.sub('', ansi_text)) + def char_slice(ansi_text, start, length): """Slices a string with respect to ansi code sequences diff --git a/ranger/gui/bar.py b/ranger/gui/bar.py index 27462e54..12c44488 100644 --- a/ranger/gui/bar.py +++ b/ranger/gui/bar.py @@ -5,6 +5,7 @@ from ranger.ext.widestring import WideString, utf_char_width import sys PY3 = sys.version_info[0] >= 3 + class Bar(object): left = None right = None diff --git a/ranger/gui/color.py b/ranger/gui/color.py index 89b58092..78f0ccda 100644 --- a/ranger/gui/color.py +++ b/ranger/gui/color.py @@ -19,6 +19,7 @@ DEFAULT_FOREGROUND = curses.COLOR_WHITE DEFAULT_BACKGROUND = curses.COLOR_BLACK COLOR_PAIRS = {10: 0} + def get_color(fg, bg): """Returns the curses color pair for the given fg/bg combination.""" diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index d2b3b2d2..fa553aea 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -34,6 +34,7 @@ from ranger.core.main import allow_access_to_confdir from ranger.ext.cached_function import cached_function from ranger.ext.iter_tools import flatten + class ColorScheme(object): """This is the class that colorschemes must inherit from. @@ -72,6 +73,7 @@ class ColorScheme(object): """ return (-1, -1, 0) + def _colorscheme_name_to_class(signal): # Find the colorscheme. First look in ~/.config/ranger/colorschemes, # then at RANGERDIR/colorschemes. If the file contains a class @@ -132,6 +134,7 @@ def _colorscheme_name_to_class(signal): else: raise Exception("The module contains no valid colorscheme!") + def get_all_colorschemes(): colorschemes = set() # Load colorscheme names from main ranger/colorschemes dir diff --git a/ranger/gui/context.py b/ranger/gui/context.py index 2d23d4f1..d5352a0a 100644 --- a/ranger/gui/context.py +++ b/ranger/gui/context.py @@ -22,6 +22,7 @@ CONTEXT_KEYS = ['reset', 'error', 'badinfo', 'vcsconflict', 'vcschanged', 'vcsunknown', 'vcsignored', 'vcsstaged', 'vcssync', 'vcsnone', 'vcsbehind', 'vcsahead', 'vcsdiverged'] + class Context(object): def __init__(self, keys): # set all given keys to True diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py index e7573f17..7078897a 100644 --- a/ranger/gui/curses_shortcuts.py +++ b/ranger/gui/curses_shortcuts.py @@ -10,10 +10,12 @@ from ranger.core.shared import SettingsAware REVERSE_ADDCH_ARGS = sys.version[0:5] == '3.4.0' + def _fix_surrogates(args): return [isinstance(arg, str) and arg.encode('utf-8', 'surrogateescape') .decode('utf-8', 'replace') or arg for arg in args] + class CursesShortcuts(SettingsAware): """This class defines shortcuts to faciliate operations with curses. diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py index c6e21d54..e8b627e8 100644 --- a/ranger/gui/displayable.py +++ b/ranger/gui/displayable.py @@ -4,6 +4,7 @@ from ranger.core.shared import FileManagerAware from ranger.gui.curses_shortcuts import CursesShortcuts + class Displayable(FileManagerAware, CursesShortcuts): """Displayables are objects which are displayed on the screen. @@ -199,6 +200,7 @@ class Displayable(FileManagerAware, CursesShortcuts): def __str__(self): return self.__class__.__name__ + class DisplayableContainer(Displayable): """DisplayableContainers are Displayables which contain other Displayables. diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py index 0de3eea2..6931648f 100644 --- a/ranger/gui/mouse_event.py +++ b/ranger/gui/mouse_event.py @@ -3,6 +3,7 @@ import curses + class MouseEvent(object): PRESSED = [0, curses.BUTTON1_PRESSED, diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 5c4e2ee0..200f3625 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -16,9 +16,12 @@ from ranger.ext.signals import Signal MOUSEMASK = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION _ASCII = ''.join(chr(c) for c in range(32, 127)) + + def ascii_only(string): return ''.join(c if c in _ASCII else '?' for c in string) + def _setup_mouse(signal): if signal['value']: curses.mousemask(MOUSEMASK) @@ -34,6 +37,7 @@ def _setup_mouse(signal): else: curses.mousemask(0) + class UI(DisplayableContainer): ALLOWED_VIEWMODES = 'miller', 'multipane' diff --git a/ranger/gui/widgets/__init__.py b/ranger/gui/widgets/__init__.py index f61e18eb..9a95509c 100644 --- a/ranger/gui/widgets/__init__.py +++ b/ranger/gui/widgets/__init__.py @@ -2,6 +2,7 @@ from ranger.gui.displayable import Displayable + class Widget(Displayable): """A class for classification of widgets.""" diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index 919a8f19..0a73e013 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -16,6 +16,7 @@ from ranger.core import linemode from ranger.gui.color import * + class BrowserColumn(Pager): main_column = False display_infostring = False diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 5383fc21..64474ac7 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -13,6 +13,7 @@ from ranger.ext.widestring import uwid, WideString from ranger.container.history import History, HistoryEmptyException import ranger + class Console(Widget): visible = False last_cursor_mode = None diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index 0d185f98..8deb7cd0 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -10,6 +10,8 @@ from ranger.ext.direction import Direction from ranger.ext.img_display import ImgDisplayUnsupportedException # TODO: Scrolling in embedded pager + + class Pager(Widget): source = None source_is_stream = False diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 8786af06..a1617aa8 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -18,6 +18,7 @@ from ranger.ext.human_readable import human_readable from . import Widget from ranger.gui.bar import Bar + class StatusBar(Widget): __doc__ = __doc__ owners = {} @@ -314,10 +315,12 @@ class StatusBar(Widget): self.color_at(0, 0, int(barwidth), ("in_statusbar", "loaded")) self.color_reset() + def get_free_space(path): stat = os.statvfs(path) return stat.f_bavail * stat.f_frsize + class Message(object): elapse = None text = None diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py index 04fdfe0e..b748ae7a 100644 --- a/ranger/gui/widgets/taskview.py +++ b/ranger/gui/widgets/taskview.py @@ -6,6 +6,7 @@ from . import Widget from ranger.ext.accumulator import Accumulator + class TaskView(Widget, Accumulator): old_lst = None diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index dbd08981..a4e091b2 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -8,9 +8,11 @@ It displays the current path among other things. from os.path import basename + from . import Widget from ranger.gui.bar import Bar + class TitleBar(Widget): old_thisfile = None old_keybuffer = None diff --git a/ranger/gui/widgets/view_base.py b/ranger/gui/widgets/view_base.py index 9fbd9586..613353c3 100644 --- a/ranger/gui/widgets/view_base.py +++ b/ranger/gui/widgets/view_base.py @@ -8,6 +8,7 @@ from ranger.ext.keybinding_parser import key_to_string from . import Widget from ..displayable import DisplayableContainer + class ViewBase(Widget, DisplayableContainer): draw_bookmarks = False need_clear = False diff --git a/ranger/gui/widgets/view_miller.py b/ranger/gui/widgets/view_miller.py index dbf59ff8..2c0bc300 100644 --- a/ranger/gui/widgets/view_miller.py +++ b/ranger/gui/widgets/view_miller.py @@ -10,6 +10,7 @@ from .pager import Pager from ..displayable import DisplayableContainer from ranger.gui.widgets.view_base import ViewBase + class ViewMiller(ViewBase): ratios = None preview = True diff --git a/ranger/gui/widgets/view_multipane.py b/ranger/gui/widgets/view_multipane.py index 1899687e..7b77b3db 100644 --- a/ranger/gui/widgets/view_multipane.py +++ b/ranger/gui/widgets/view_multipane.py @@ -4,6 +4,7 @@ from ranger.gui.widgets.view_base import ViewBase from ranger.gui.widgets.browsercolumn import BrowserColumn + class ViewMultipane(ViewBase): def __init__(self, win): ViewBase.__init__(self, win) |