From 2a333aa46a789b74516423a88da6e11f517170f6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 29 Mar 2014 15:38:15 +0530 Subject: [PATCH] Implement dumping for odt in addition to docx --- src/calibre/debug.py | 4 ++-- src/calibre/ebooks/docx/dump.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/calibre/debug.py b/src/calibre/debug.py index e00a5ab950..fe0fe9e6de 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -279,10 +279,10 @@ def main(args=sys.argv): main(['calibre-diff'] + args[1:]) elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'py', 'recipe'}: run_script(args[1], args[2:]) - elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'mobi', 'azw', 'azw3', 'docx'}: + elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'mobi', 'azw', 'azw3', 'docx', 'odt'}: for path in args[1:]: ext = path.rpartition('.')[-1] - if ext == 'docx': + if ext in {'docx', 'odt'}: from calibre.ebooks.docx.dump import dump dump(path) elif ext in {'mobi', 'azw', 'azw3'}: diff --git a/src/calibre/ebooks/docx/dump.py b/src/calibre/ebooks/docx/dump.py index 103236f05f..be04f02ef3 100644 --- a/src/calibre/ebooks/docx/dump.py +++ b/src/calibre/ebooks/docx/dump.py @@ -25,10 +25,11 @@ def dump(path): if f.endswith('.xml') or f.endswith('.rels'): with open(f, 'r+b') as stream: raw = stream.read() - root = etree.fromstring(raw) - stream.seek(0) - stream.truncate() - stream.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True)) + if raw: + root = etree.fromstring(raw) + stream.seek(0) + stream.truncate() + stream.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True)) print (path, 'dumped to', dest)