@@ -88,31 +88,32 @@ def extract(
88
88
ignore_pattern = (),
89
89
):
90
90
"""
91
- Walk and extract any archives found at `location` (either a file or
92
- directory). Extract only archives of a kind listed in the `kinds` kind tuple.
91
+ Walk and extract any archives found at ``location`` (either a file or
92
+ directory). Extract only archives of a kind listed in the ``kinds`` kind
93
+ tuple.
93
94
94
- Return an iterable of ExtractEvent tuples for each extracted archive. This
95
- can be used to track extraction progress:
95
+ Return an iterable of ExtractEvent for each extracted archive. This can be
96
+ used to track extraction progress:
96
97
97
98
- one event is emitted just before extracting an archive. The ExtractEvent
98
- warnings and errors are empty. The ` done` flag is False.
99
+ warnings and errors are empty. The " done" flag is False.
99
100
100
101
- one event is emitted right after extracting an archive. The ExtractEvent
101
- warnings and errors contains warnings and errors if any. The ` done` flag
102
+ warnings and errors contains warnings and errors if any. The " done" flag
102
103
is True.
103
104
104
- If `recurse` is True, extract recursively archives nested inside other
105
- archives. If `recurse` is false, then do not extract further an already
105
+ If `` recurse` ` is True, extract recursively archives nested inside other
106
+ archives. If `` recurse` ` is false, then do not extract further an already
106
107
extracted archive identified by the corresponding extract suffix location.
107
108
108
- If `replace_originals` is True, the extracted archives are replaced by the
109
- extracted content.
109
+ If `` replace_originals` ` is True, the extracted archives are replaced by the
110
+ extracted content, only if the extraction was successful .
110
111
111
112
``ignore_pattern`` is a list of glob patterns to ignore.
112
113
113
114
Note that while the original filesystem is walked top-down, breadth-first,
114
- if ``recurse`` and a nested archive is found, it is extracted at full depth
115
- first before resuming the filesystem walk.
115
+ if ``recurse`` and a nested archive is found, it is extracted first
116
+ recursively and at full depth- first before resuming the filesystem walk.
116
117
"""
117
118
118
119
extract_events = extract_files (
@@ -126,27 +127,19 @@ def extract(
126
127
processed_events_append = processed_events .append
127
128
for event in extract_events :
128
129
yield event
129
- if event .warnings or event .errors :
130
- if TRACE :
131
- logger .debug (
132
- f'extract:replace_originals: { event } has errors. '
133
- 'not replacing originals'
134
- )
135
- continue
136
130
if replace_originals :
137
131
processed_events_append (event )
138
132
139
-
140
- # move files around when done
133
+ # move files around when done, unless there are errors
141
134
if replace_originals :
142
135
for xevent in reversed (processed_events ):
143
- if xevent .done :
136
+ if xevent .done and not ( event . warnings or event . errors ) :
144
137
source = xevent .source
145
138
target = xevent .target
146
139
if TRACE :
147
140
logger .debug (
148
- 'extract:replace_originals: replace '
149
- '%( source)r by %( target)r' % locals ()
141
+ f 'extract:replace_originals: replacing '
142
+ f' { source !r } by { target !r } '
150
143
)
151
144
fileutils .delete (source )
152
145
fileutils .copytree (target , source )
0 commit comments