From: Marcin Koziej Date: Mon, 16 Sep 2013 14:44:03 +0000 (+0200) Subject: add resources to epub X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/40489b85c12aae16363f49d9b1bce1384f20a9e4?ds=sidebyside;hp=912d5504a52acabeac25501dfa25266efbf602d7 add resources to epub --- diff --git a/librarian/epub.py b/librarian/epub.py index fcc2bfe..841b7c5 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -331,7 +331,7 @@ def transform_chunk(chunk_xml, chunk_no, annotations, empty=False, _empty_html_s def transform(wldoc, verbose=False, style=None, html_toc=False, - sample=None, cover=None, flags=None): + sample=None, cover=None, flags=None, resources=None): """ produces a EPUB file sample=n: generate sample e-book (with at least n paragraphs) @@ -441,6 +441,16 @@ def transform(wldoc, verbose=False, if not style: style = get_resource('epub/style.css') zip.write(style, os.path.join('OPS', 'style.css')) + if resources: + if os.path.isdir(resources): + for dp, dirs, files in os.walk(resources): + for fname in files: + fpath = os.path.join(dp, fname) + if os.path.isfile(fpath): + zip.write(fpath, os.path.join('OPS', fname)) + else: + print "resources path %s is not directory" % resources + if cover: if cover is True: diff --git a/scripts/book2epub b/scripts/book2epub index 01ca79a..ff2c668 100755 --- a/scripts/book2epub +++ b/scripts/book2epub @@ -15,7 +15,9 @@ class Book2Epub(Book2Anything): transform_flags = [ Option('-w', '--working-copy', dest='working-copy', action='store_true', default=False, - help='mark the output as a working copy') + help='mark the output as a working copy'), + Option('-R', '--resources', dest='resources', metavar='DIR', + help='a directory with additional resources'), ]