1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-01-14 07:44:12 +01:00

Added missing dump module

This commit is contained in:
2020-06-07 08:14:15 +02:00
parent ce89f5c9d1
commit 7419954e0c

View File

@@ -0,0 +1,38 @@
import os
import shutil
from lxml import etree
from ebook_converter import walk
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.utils.xml_parse import safe_xml_fromstring
def pretty_all_xml_in_dir(path):
for f in walk(path):
if f.endswith('.xml') or f.endswith('.rels'):
with open(f, 'r+b') as stream:
raw = stream.read()
if raw:
root = safe_xml_fromstring(raw)
stream.seek(0)
stream.truncate()
stream.write(etree.tostring(root, pretty_print=True,
encoding='utf-8',
xml_declaration=True))
def do_dump(path, dest):
if os.path.exists(dest):
shutil.rmtree(dest)
with ZipFile(path) as zf:
zf.extractall(dest)
pretty_all_xml_in_dir(dest)
def dump(path):
dest = os.path.splitext(os.path.basename(path))[0]
dest += '-dumped'
do_dump(path, dest)
print(path, 'dumped to', dest)