summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorarappold <a_rappold@gmx.at>2015-08-17 14:45:47 +0200
committerarappold <a_rappold@gmx.at>2015-08-17 14:45:47 +0200
commita258b5c10d3710c4bb4895bd3c6698ed7cb2e28e (patch)
tree13d0a4b54890669038b1afe14afc2e4c1c2cf409
parent2344714fcbaa3697f77dd0cb4477a8f8019c7dc4 (diff)
downloadranger-a258b5c10d3710c4bb4895bd3c6698ed7cb2e28e.tar.gz
make mv/cp generators yield progress
-rw-r--r--ranger/core/loader.py13
-rw-r--r--ranger/ext/shutil_generatorized.py34
2 files changed, 27 insertions, 20 deletions
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index 1f9ec9cf..e672bbed 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -77,7 +77,6 @@ class CopyLoader(Loadable, FileManagerAware):
             # TODO: Don't calculate size when renaming (needs detection)
             bytes_per_tick = shutil_g.BLOCK_SIZE
             size = max(1, self._calculate_size(bytes_per_tick))
-            bar_tick = 100.0 / (float(size) / bytes_per_tick)
             if self.do_cut:
                 self.original_copy_buffer.clear()
                 if len(self.copy_buffer) == 1:
@@ -92,10 +91,10 @@ class CopyLoader(Loadable, FileManagerAware):
                             self.fm.tags.tags[tf.replace(f.path, self.original_path \
                                     + '/' + f.basename)] = tag
                             self.fm.tags.dump()
-                    for _ in shutil_g.move(src=f.path,
+                    for done in shutil_g.move(src=f.path,
                             dst=self.original_path,
                             overwrite=self.overwrite):
-                        self.percent += bar_tick
+                        self.percent = float(done) / size * 100.
                         yield
             else:
                 if len(self.copy_buffer) == 1:
@@ -104,17 +103,17 @@ class CopyLoader(Loadable, FileManagerAware):
                     self.description = "copying files from: " + self.one_file.dirname
                 for f in self.copy_buffer:
                     if os.path.isdir(f.path) and not os.path.islink(f.path):
-                        for _ in shutil_g.copytree(src=f.path,
+                        for done in shutil_g.copytree(src=f.path,
                                 dst=os.path.join(self.original_path, f.basename),
                                 symlinks=True,
                                 overwrite=self.overwrite):
-                            self.percent += bar_tick
+                            self.percent = float(done) / size * 100.
                             yield
                     else:
-                        for _ in shutil_g.copy2(f.path, self.original_path,
+                        for done in shutil_g.copy2(f.path, self.original_path,
                                 symlinks=True,
                                 overwrite=self.overwrite):
-                            self.percent += bar_tick
+                            self.percent = float(done) / size * 100.
                             yield
             cwd = self.fm.get_directory(self.original_path)
             cwd.load_content()
diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py
index b20d5cef..e2d07110 100644
--- a/ranger/ext/shutil_generatorized.py
+++ b/ranger/ext/shutil_generatorized.py
@@ -8,6 +8,7 @@ XXX The functions here don't copy the resource fork or other metadata on Mac.
 import os
 import sys
 import stat
+import time
 from os.path import abspath
 
 __all__ = ["copyfileobj","copyfile","copystat","copy2","BLOCK_SIZE",
@@ -30,12 +31,14 @@ except NameError:
 
 def copyfileobj(fsrc, fdst, length=BLOCK_SIZE):
     """copy data from file-like object fsrc to file-like object fdst"""
+    total = 0
     while 1:
         buf = fsrc.read(length)
         if not buf:
             break
         fdst.write(buf)
-        yield
+        total += len(buf)
+        yield total
 
 def _samefile(src, dst):
     # Macintosh, Unix.
@@ -69,8 +72,8 @@ def copyfile(src, dst):
     try:
         fsrc = open(src, 'rb')
         fdst = open(dst, 'wb')
-        for _ in copyfileobj(fsrc, fdst):
-            yield
+        for done in copyfileobj(fsrc, fdst):
+            yield done
     finally:
         if fdst:
             fdst.close()
@@ -107,8 +110,8 @@ def copy2(src, dst, overwrite=False, symlinks=False):
             os.unlink(dst)
         os.symlink(linkto, dst)
     else:
-        for _ in copyfile(src, dst):
-            yield
+        for done in copyfile(src, dst):
+            yield done
         copystat(src, dst)
 
 def get_safe_path(dst):
@@ -165,6 +168,7 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False):
         if not overwrite:
             dst = get_safe_path(dst)
             os.makedirs(dst)
+    total = 0
     for name in names:
         if name in ignored_names:
             continue
@@ -178,14 +182,18 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False):
                 os.symlink(linkto, dstname)
                 copystat(srcname, dstname)
             elif os.path.isdir(srcname):
-                for _ in copytree(srcname, dstname, symlinks,
+                done = 0
+                for done in copytree(srcname, dstname, symlinks,
                         ignore, overwrite):
-                    yield
+                    yield total + done
+                total += done
             else:
                 # Will raise a SpecialFileError for unsupported file types
-                for _ in copy2(srcname, dstname,
+                done = 0
+                for done in copy2(srcname, dstname,
                         overwrite=overwrite, symlinks=symlinks):
-                    yield
+                    yield total + done
+                total += done
         # catch the Error from the recursive copytree so that we can
         # continue with other files
         except Error as err:
@@ -283,12 +291,12 @@ def move(src, dst, overwrite=False):
         if os.path.isdir(src):
             if _destinsrc(src, dst):
                 raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
-            for _ in copytree(src, real_dst, symlinks=True, overwrite=overwrite):
-                yield
+            for done in copytree(src, real_dst, symlinks=True, overwrite=overwrite):
+                yield done
             rmtree(src)
         else:
-            for _ in copy2(src, real_dst, symlinks=True, overwrite=overwrite):
-                yield
+            for done in copy2(src, real_dst, symlinks=True, overwrite=overwrite):
+                yield done
             os.unlink(src)
 
 def _destinsrc(src, dst):
h=v1.9.3&id=15fb093cae01dd5c160d319a19557c52da759963'>^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
                     

                                                                 
 





                                                        
              

             
                        

                                                                       
 
                          
          






                                            
                                       
                                                    




                                 
                             
                                
                              
                                          
                                                    

                                                                
                                                              
                                                                
          








                                                            
                               
                                       
                                    
#!/usr/bin/env python
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

# Setuptools is superior but not available in the stdlib
try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

import os.path
import ranger

def _findall(directory):
    return [os.path.join(directory, f) for f in os.listdir(directory) \
            if os.path.isfile(os.path.join(directory, f))]

if __name__ == '__main__':
    setup(
        name='ranger',
        description='Vim-like file manager',
        long_description=ranger.__doc__,
        version=ranger.__version__,
        author=ranger.__author__,
        author_email=ranger.__email__,
        license=ranger.__license__,
        url='http://ranger.nongnu.org',
        scripts=['scripts/ranger', 'scripts/rifle'],
        data_files=[
            ('share/man/man1',
                ['doc/ranger.1',
                 'doc/rifle.1']),
            ('share/doc/ranger',
                ['README.md',
                 'CHANGELOG.md',
                 'HACKING.md',
                 'doc/colorschemes.txt']),
            ('share/doc/ranger/config/colorschemes',
                _findall('doc/config/colorschemes')),
            ('share/doc/ranger/config', _findall('doc/config')),
            ('share/doc/ranger/tools', _findall('doc/tools')),
            ('share/doc/ranger/examples', _findall('examples')),
        ],
        package_data={'ranger': ['data/*', 'config/rc.conf',
            'config/rifle.conf']},
        packages=('ranger',
                  'ranger.api',
                  'ranger.colorschemes',
                  'ranger.container',
                  'ranger.core',
                  'ranger.config',
                  'ranger.ext',
                  'ranger.gui',
                  'ranger.gui.widgets',
                  'ranger.ext.vcs'))