diff options
author | hut <hut@lavabit.com> | 2012-08-15 03:01:05 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-08-15 03:05:36 +0200 |
commit | 23fed83c9afe1938261360cf10efc1bb60f9e5d5 (patch) | |
tree | c303d8b3351e090baa8192111a46675f15d1ffc5 /ranger | |
parent | 85b8afded8637a7d42f2e4c454cabbed93a582af (diff) | |
download | ranger-23fed83c9afe1938261360cf10efc1bb60f9e5d5.tar.gz |
core.actions: move paste() logic to core.loader.CopyLoader
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/actions.py | 53 | ||||
-rw-r--r-- | ranger/core/loader.py | 50 |
2 files changed, 52 insertions, 51 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 3fef3db3..c8964157 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -22,8 +22,7 @@ from ranger.core.shared import FileManagerAware, EnvironmentAware, \ SettingsAware from ranger.core.tab import Tab from ranger.fsobject import File -from ranger.core.loader import CommandLoader, Loadable -from ranger.ext import shutil_generatorized as shutil_g +from ranger.core.loader import CommandLoader, CopyLoader MACRO_FAIL = "<\x01\x01MACRO_HAS_NO_VALUE\x01\01>" @@ -1062,54 +1061,8 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware): def paste(self, overwrite=False): """Paste the selected items into the current directory""" - copied_files = tuple(self.copy_buffer) - - if not copied_files: - return - - original_path = self.thistab.path - try: - one_file = copied_files[0] - except: - one_file = None - - if self.do_cut: - self.copy_buffer.clear() - self.do_cut = False - if len(copied_files) == 1: - descr = "moving: " + one_file.path - else: - descr = "moving files from: " + one_file.dirname - def generate(): - for f in copied_files: - for _ in shutil_g.move(src=f.path, - dst=original_path, - overwrite=overwrite): - yield - cwd = self.get_directory(original_path) - cwd.load_content() - else: - if len(copied_files) == 1: - descr = "copying: " + one_file.path - else: - descr = "copying files from: " + one_file.dirname - def generate(): - for f in self.copy_buffer: - if isdir(f.path): - for _ in shutil_g.copytree(src=f.path, - dst=join(original_path, f.basename), - symlinks=True, - overwrite=overwrite): - yield - else: - for _ in shutil_g.copy2(f.path, original_path, - symlinks=True, - overwrite=overwrite): - yield - cwd = self.get_directory(original_path) - cwd.load_content() - - self.loader.add(Loadable(generate(), descr)) + self.loader.add(CopyLoader(self.copy_buffer, self.do_cut, overwrite)) + self.do_cut = False def delete(self): # XXX: warn when deleting mount points/unseen marked files? diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 6e64e535..58f23821 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -6,7 +6,7 @@ from time import time, sleep from subprocess import Popen, PIPE from ranger.core.shared import FileManagerAware from ranger.ext.signals import SignalDispatcher -import os +import os.path import sys import select try: @@ -39,6 +39,54 @@ class Loadable(object): pass +class CopyLoader(Loadable, FileManagerAware): + progressbar_supported = True + def __init__(self, copy_buffer, do_cut=False, overwrite=False): + self.copy_buffer = tuple(copy_buffer) + self.do_cut = do_cut + self.original_copy_buffer = copy_buffer + self.original_path = self.fm.thistab.path + self.overwrite = overwrite + self.percent = 0 + if self.copy_buffer: + self.one_file = self.copy_buffer[0] + Loadable.__init__(self, self.generate(), 'copying/moving...') + + def generate(self): + from ranger.ext import shutil_generatorized as shutil_g + if self.copy_buffer: + if self.do_cut: + self.original_copy_buffer.clear() + if len(self.copy_buffer) == 1: + self.description = "moving: " + self.one_file.path + else: + self.description = "moving files from: " + self.one_file.dirname + for f in self.copy_buffer: + for _ in shutil_g.move(src=f.path, + dst=self.original_path, + overwrite=self.overwrite): + yield + else: + if len(self.copy_buffer) == 1: + self.description = "copying: " + self.one_file.path + else: + self.description = "copying files from: " + self.one_file.dirname + for f in self.copy_buffer: + if os.path.isdir(f.path): + for _ in shutil_g.copytree(src=f.path, + dst=os.path.join(self.original_path, f.basename), + symlinks=True, + overwrite=self.overwrite): + yield + else: + for _ in shutil_g.copy2(f.path, self.original_path, + symlinks=True, + overwrite=self.overwrite): + yield + cwd = self.fm.get_directory(self.original_path) + cwd.load_content() + + class CommandLoader(Loadable, SignalDispatcher, FileManagerAware): """ Run an external command with the loader. |