Skip to content

Commit b92a7bc

Browse files
committed
Allow extraction of libre-office-docs
1 parent 6bd8917 commit b92a7bc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/extractcode/extract.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import logging
1111
import traceback
12+
import zipfile
1213

1314
from collections import namedtuple
1415
from functools import partial
@@ -229,14 +230,15 @@ def extract_files(
229230
if TRACE:
230231
logger.debug('extract:walk:recurse:extraction event: %(xevent)r' % locals())
231232
yield xevent
232-
233+
233234
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.")
240242

241243

242244
def extract_file(

0 commit comments

Comments
 (0)