X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/1704f1ee2a43803f965c913c2cb88307b9bb820e..07793241cd7b314aadc8bad12d1c327545545e19:/librarian/epub.py diff --git a/librarian/epub.py b/librarian/epub.py index cdb5aae..c25ba19 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -11,34 +11,11 @@ from copy import deepcopy from lxml import etree import zipfile -from librarian import XMLNamespace, RDFNS, DCNS, WLNS, NoDublinCore -from librarian.dcparser import BookInfo - -NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/") -OPFNS = XMLNamespace("http://www.idpf.org/2007/opf") - - -class DocProvider(object): - class DoesNotExist(Exception): - pass - - def by_slug(self, slug): - raise NotImplemented - - def __getitem__(self, slug): - return self.by_slug(slug) +import sys +sys.path.append('..') # for running from working copy - def by_uri(self, uri): - return self.by_slug(uri.rsplit('/', 1)[1]) - - -class DirDocProvider(DocProvider): - def __init__(self, dir): - self.dir = dir - self.files = {} - - def by_slug(self, slug): - return open(os.path.join(self.dir, '%s.xml' % slug)) +from librarian import XMLNamespace, RDFNS, DCNS, WLNS, NCXNS, OPFNS, NoDublinCore +from librarian.dcparser import BookInfo def inner_xml(node): @@ -309,7 +286,7 @@ def transform(provider, slug, output_file=None, output_dir=None): if main_text is not None: replace_characters(main_text) - for chunk_no, chunk_xml in enumerate(chop(main_text), chunk_counter): + for chunk_xml in chop(main_text): chunk_html, chunk_toc = transform_chunk(chunk_xml, chunk_counter, annotations) toc.extend(chunk_toc) zip.writestr('OPS/part%d.html' % chunk_counter, chunk_html) @@ -410,7 +387,7 @@ def transform(provider, slug, output_file=None, output_dir=None): if __name__ == '__main__': - import sys + from librarian import DirDocProvider if len(sys.argv) < 2: print >> sys.stderr, 'Usage: python epub.py '