about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2019-05-19 20:09:01 +0200
committertoonn <toonn@toonn.io>2019-05-19 21:31:08 +0200
commitd8d855e7b379d7b647d97a0ce91c14976ab1ec7c (patch)
tree15ecbcfd895f4a4b662f6334ad198a2e42165559
parenteb3daffa19abbbd7403e4a6a8fb32945fef5b3c6 (diff)
downloadranger-d8d855e7b379d7b647d97a0ce91c14976ab1ec7c.tar.gz
Updated the style to be more modern and pythonic
Replaced the erroneous used of `extend` with `append`. It was working
out by coincidence but probably making the `join` much less efficient.
-rwxr-xr-xranger/config/commands.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 4d2357f6..2159802d 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1063,7 +1063,8 @@ class bulkrename(Command):
     After you close it, it will be executed.
     """
 
-    def execute(self):  # pylint: disable=too-many-locals,too-many-statements,too-many-branches
+    def execute(self):
+        # pylint: disable=too-many-locals,too-many-statements,too-many-branches
         import sys
         import tempfile
         from ranger.container.file import File
@@ -1092,17 +1093,23 @@ class bulkrename(Command):
         # Generate script
         cmdfile = tempfile.NamedTemporaryFile()
         script_lines = []
-        script_lines.append("# This file will be executed when you close the editor.\n")
-        script_lines.append("# Please double-check everything, clear the file to abort.\n")
+        script_lines.append("# This file will be executed when you close the"
+                            " editor.")
+        script_lines.append("# Please double-check everything, clear the file"
+                            " to abort.")
         new_dirs = []
         for old, new in zip(filenames, new_filenames):
             if old != new:
                 basepath, _ = os.path.split(new)
-                if basepath and basepath not in new_dirs and not os.path.isdir(basepath):
-                    script_lines.extend("mkdir -vp -- %s\n" % esc(basepath))
+                if (basepath is not None and basepath not in new_dirs
+                        and not os.path.isdir(basepath)):
+                    script_lines.append("mkdir -vp -- {dir}".format(
+                        dir=esc(basepath)))
                     new_dirs.append(basepath)
-                script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new)))
-        script_content = "".join(script_lines)
+                script_lines.append("mv -vi -- {old} {new}".format(
+                    old=esc(old), new=esc(new)))
+        # Make sure not to forget the ending newline
+        script_content = "\n".join(script_lines) + "\n"
         if py3:
             cmdfile.write(script_content.encode("utf-8"))
         else: