mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
DRYer
This commit is contained in:
parent
807ba2fe8b
commit
a2e06b5132
@ -197,10 +197,9 @@ class Adder(QObject):
|
|||||||
def extract(source):
|
def extract(source):
|
||||||
tdir = tempfile.mkdtemp(suffix='_archive', dir=self.tdir)
|
tdir = tempfile.mkdtemp(suffix='_archive', dir=self.tdir)
|
||||||
if source.lower().endswith('.zip'):
|
if source.lower().endswith('.zip'):
|
||||||
from calibre.utils.zipfile import ZipFile
|
from calibre.utils.zipfile import extractall
|
||||||
try:
|
try:
|
||||||
with ZipFile(source) as zf:
|
extractall(source, tdir)
|
||||||
zf.extractall(tdir)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
prints('Corrupt ZIP file, trying to use local headers')
|
prints('Corrupt ZIP file, trying to use local headers')
|
||||||
from calibre.utils.localunzip import extractall
|
from calibre.utils.localunzip import extractall
|
||||||
|
@ -1624,6 +1624,11 @@ class PyZipFile(ZipFile):
|
|||||||
return (fname, archivename)
|
return (fname, archivename)
|
||||||
|
|
||||||
|
|
||||||
|
def extractall(source, dest):
|
||||||
|
with ZipFile(source) as zf:
|
||||||
|
zf.extractall(dest)
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
import textwrap
|
import textwrap
|
||||||
USAGE=textwrap.dedent("""\
|
USAGE=textwrap.dedent("""\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user