@@ -113,7 +113,7 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False, replace_or
113
113
is True.
114
114
115
115
If `recurse` is True, extract recursively archives nested inside other
116
- archives If `recurse` is false, then do not extract further an already
116
+ archives. If `recurse` is false, then do not extract further an already
117
117
extracted archive identified by the corresponding extract suffix location.
118
118
119
119
If `replace_originals` is True, the extracted archives are replaced by the
@@ -123,9 +123,16 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False, replace_or
123
123
if recurse and a nested archive is found, it is extracted to full depth
124
124
first before resuming the file system walk.
125
125
"""
126
- events = list (extract_files (location = location , kinds = kinds , recurse = recurse , ignored_extensions = ignored_extensions ))
126
+ processed_events = []
127
+ processed_events_append = processed_events .append
128
+ for event in extract_files (location , kinds , recurse , ignored_extensions ):
129
+ yield event
130
+ if replace_originals :
131
+ processed_events_append (event )
132
+
133
+ # move files around
127
134
if replace_originals :
128
- for xevent in reversed (events ):
135
+ for xevent in reversed (processed_events ):
129
136
if xevent .done :
130
137
source = xevent .source
131
138
target = xevent .target
@@ -134,12 +141,22 @@ def extract(location, kinds=extractcode.default_kinds, recurse=False, replace_or
134
141
fileutils .delete (source )
135
142
fileutils .copytree (target , source )
136
143
fileutils .delete (target )
137
- return events
144
+
138
145
139
146
def extract_files (location , kinds = extractcode .default_kinds , recurse = False , ignored_extensions = ()):
147
+ """
148
+ Extract the files found at `location`.
149
+
150
+ Extract only archives of a kind listed in the `kinds` kind tuple.
151
+
152
+ If `recurse` is True, extract recursively archives nested inside other
153
+ archives. If `recurse` is false, then do not extract further an already
154
+ extracted archive identified by the corresponding extract suffix location.
155
+ """
140
156
ignored = partial (ignore .is_ignored , ignores = ignore .default_ignores , unignores = {})
141
157
if TRACE :
142
158
logger .debug ('extract:start: %(location)r recurse: %(recurse)r\n ' % locals ())
159
+
143
160
abs_location = abspath (expanduser (location ))
144
161
for top , dirs , files in fileutils .walk (abs_location , ignored ):
145
162
if TRACE :
@@ -192,8 +209,8 @@ def extract_file(location, target, kinds=extractcode.default_kinds, verbose=Fals
192
209
extractor = archive .get_extractor (location , kinds )
193
210
if TRACE :
194
211
logger .debug ('extract_file: extractor: for: %(location)r with kinds: %(kinds)r : ' % locals ()
195
- + getattr (extractor , '__module__' , '' )
196
- + '.' + getattr (extractor , '__name__' , '' ))
212
+ + getattr (extractor , '__module__' , '' )
213
+ + '.' + getattr (extractor , '__name__' , '' ))
197
214
if extractor :
198
215
yield ExtractEvent (location , target , done = False , warnings = [], errors = [])
199
216
try :
0 commit comments