summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-25 05:53:37 +0100
committerhut <hut@lavabit.com>2009-12-25 05:53:37 +0100
commit56134d8a42dfc0a88bab898aa8418e5c3837af16 (patch)
treefeb0bab20ce143d9cd1a826114c202668d0da211 /ranger
parent28150942f6033193ad61142f0f1a476b45a0a34d (diff)
downloadranger-56134d8a42dfc0a88bab898aa8418e5c3837af16.tar.gz
"generatorized" shutil
this is required so i can do the operations bit by bit and
it doesn't block the whole program.
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/shutil_generatorized.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py
index dc36820d..1b451278 100644
--- a/ranger/ext/shutil_generatorized.py
+++ b/ranger/ext/shutil_generatorized.py
@@ -32,6 +32,7 @@ def copyfileobj(fsrc, fdst, length=16*1024):
         if not buf:
             break
         fdst.write(buf)
+        yield
 
 def _samefile(src, dst):
     # Macintosh, Unix.
@@ -65,7 +66,8 @@ def copyfile(src, dst):
     try:
         fsrc = open(src, 'rb')
         fdst = open(dst, 'wb')
-        copyfileobj(fsrc, fdst)
+        for _ in copyfileobj(fsrc, fdst):
+            yield
     finally:
         if fdst:
             fdst.close()
@@ -99,7 +101,8 @@ def copy(src, dst):
     """
     if os.path.isdir(dst):
         dst = os.path.join(dst, os.path.basename(src))
-    copyfile(src, dst)
+    for _ in copyfile(src, dst):
+        yield
     copymode(src, dst)
 
 def copy2(src, dst):
@@ -110,7 +113,8 @@ def copy2(src, dst):
     """
     if os.path.isdir(dst):
         dst = os.path.join(dst, os.path.basename(src))
-    copyfile(src, dst)
+    for _ in copyfile(src, dst):
+        yield
     copystat(src, dst)
 
 def ignore_patterns(*patterns):
@@ -169,10 +173,12 @@ def copytree(src, dst, symlinks=False, ignore=None):
                 linkto = os.readlink(srcname)
                 os.symlink(linkto, dstname)
             elif os.path.isdir(srcname):
-                copytree(srcname, dstname, symlinks, ignore)
+                for _ in copytree(srcname, dstname, symlinks, ignore):
+                    yield
             else:
                 # Will raise a SpecialFileError for unsupported file types
-                copy2(srcname, dstname)
+                for _ in copy2(srcname, dstname):
+                    yield
         # catch the Error from the recursive copytree so that we can
         # continue with other files
         except Error as err:
@@ -272,10 +278,12 @@ def move(src, dst):
         if os.path.isdir(src):
             if _destinsrc(src, dst):
                 raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
-            copytree(src, real_dst, symlinks=True)
+            for _ in copytree(src, real_dst, symlinks=True):
+                yield
             rmtree(src)
         else:
-            copy2(src, real_dst)
+            for _ in copy2(src, real_dst):
+                yield
             os.unlink(src)
 
 def _destinsrc(src, dst):
@@ -286,3 +294,5 @@ def _destinsrc(src, dst):
     if not dst.endswith(os.path.sep):
         dst += os.path.sep
     return dst.startswith(src)
+
+# vi: expandtab sts=4 ts=4 sw=4
href='/akspecs/aerc/blame/widgets/aerc.go?h=0.1.2&id=e463c38476b96be99b4ae08af4db9e92da9d2a50'>^
1265d9c ^

1c41b63 ^
1265d9c ^

1c41b63 ^









cab3771 ^
1c41b63 ^

cab3771 ^
cab3771 ^







6728a11 ^



cab3771 ^














80e891a ^



cea9846 ^

6728a11 ^
cea9846 ^









80e891a ^




cea9846 ^
cab3771 ^
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114