File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 9
9
10
10
import logging
11
11
import traceback
12
+ import zipfile
12
13
13
14
from collections import namedtuple
14
15
from functools import partial
@@ -229,14 +230,15 @@ def extract_files(
229
230
if TRACE :
230
231
logger .debug ('extract:walk:recurse:extraction event: %(xevent)r' % locals ())
231
232
yield xevent
232
-
233
+
233
234
def extract_libre_office_document (location , target ):
234
- """ Extract Libre Office documents (e.g., .ods files) as ZIP archives. """
235
- if not zipfile .is_zipfile (location ):
236
- return
237
- with zipfile .ZipFile (location , 'r' ) as zip_ref :
238
- zip_ref .extractall (target )
239
- print (f"Extracted Libre Office document from { location } to { target } " )
235
+ """Extract Libre Office documents (e.g., .ods files) as ZIP archives."""
236
+ try :
237
+ with zipfile .ZipFile (location , 'r' ) as zip_ref :
238
+ zip_ref .extractall (target )
239
+ logger .info (f"Extracted Libre Office document from { location } to { target } " )
240
+ except zipfile .BadZipFile :
241
+ raise ValueError (f"File at { location } is not a valid ZIP archive." )
240
242
241
243
242
244
def extract_file (
You can’t perform that action at this time.
0 commit comments