From 99870addf7e23cd8bb34463c43dfc7ccd38b9545 Mon Sep 17 00:00:00 2001 From: toonn Date: Sat, 28 Dec 2019 18:16:50 +0100 Subject: Fix hash_chunks generator --- ranger/core/filter_stack.py | 12 +++++++----- ranger/ext/hash.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ranger/core/filter_stack.py b/ranger/core/filter_stack.py index ca8810e8..59495437 100644 --- a/ranger/core/filter_stack.py +++ b/ranger/core/filter_stack.py @@ -9,8 +9,7 @@ import re import mimetypes # pylint: disable=invalid-name try: - from itertools import izip_longest - zip_longest = izip_longest + from itertools import izip_longest as zip_longest except ImportError: from itertools import zip_longest # pylint: enable=invalid-name @@ -77,9 +76,12 @@ class MimeFilter(BaseFilter): @stack_filter("hash") class HashFilter(BaseFilter, FileManagerAware): - def __init__(self, filepath): - self.filepath = filepath if filepath else self.fm.thisfile.path - if not self.filepath: + def __init__(self, filepath = None): + if filepath is None: + self.filepath = self.fm.thisfile.path + else: + self.filepath = filepath + if self.filepath is None: self.fm.notify("Error: No file selected for hashing!", bad=True) # TODO: Lazily generated list would be more efficient, a generator # isn't enough because this object is reused for every fsobject diff --git a/ranger/ext/hash.py b/ranger/ext/hash.py index 20059dbf..1ed21a71 100644 --- a/ranger/ext/hash.py +++ b/ranger/ext/hash.py @@ -17,7 +17,8 @@ def hash_chunks(filepath, h=None): h.update(filepath) yield h.hexdigest() for fp in listdir(filepath): - hash_chunks(fp, h=h) + for fp_chunk in hash_chunks(fp, h=h): + yield fp_chunk elif getsize(filepath) == 0: yield h.hexdigest() else: -- cgit 1.4.1-2-gfad0