from shutil import rmtree
from librarian import RDFNS, WLNS, NCXNS, OPFNS, XHTMLNS, IOFile
-from librarian.cover import WLCover
from librarian import functions, get_resource
add_to_spine(spine, chunk_counter)
chunk_counter += 1
- for child in wldoc.parts():
- child_toc, chunk_counter, chunk_chars, sample = transform_file(
- child, chunk_counter, first=False, sample=sample)
- toc.append(child_toc)
- chars = chars.union(chunk_chars)
+ # for child in wldoc.parts():
+ # child_toc, chunk_counter, chunk_chars, sample = transform_file(
+ # child, chunk_counter, first=False, sample=sample)
+ # toc.append(child_toc)
+ # chars = chars.union(chunk_chars)
return toc, chunk_counter, chars, sample
document.edoc.getroot().set(flag, 'yes')
# add editors info
- document.edoc.getroot().set('editors', u', '.join(sorted(
- editor.readable() for editor in document.editors())))
+ # document.edoc.getroot().set('editors', u', '.join(sorted(
+ # editor.readable() for editor in document.editors())))
opf = xslt(document.book_info.to_etree(), get_resource('epub/xsltContent.xsl'))
manifest = opf.find('.//' + OPFNS('manifest'))
zip.write(style, os.path.join('OPS', 'style.css'))
if cover:
- if cover is True:
- cover = WLCover
-
cover_file = StringIO()
bound_cover = cover(document.book_info)
bound_cover.save(cover_file)
@classmethod
def from_file(cls, xmlfile, *args, **kwargs):
- if isinstance(xmlfile, basestring):
- iofile = IOFile.from_filename(xmlfile)
- else:
- iofile = IOFile.from_file(xmlfile)
+ iofile = IOFile.from_filename(xmlfile)
return cls(iofile, *args, **kwargs)
elem.insert(0, ins)
elem.text = chunks.pop(0)
- def parts(self):
- if self.book_info is None:
- raise NoDublinCore('No Dublin Core in document.')
- if self.book_info.parts and self.provider is None:
- raise NoProvider('No document provider supplied.')
- for part_uri in self.book_info.parts:
- yield self.from_file(self.provider.by_uri(part_uri),
- provider=self.provider)
-
def chunk(self, path):
# convert the path to XPath
expr = self.path_to_xpath(path)
node.tag = 'span'
node.tail = tail
- def editors(self):
- """Returns a set of all editors for book and its children.
-
- :returns: set of dcparser.Person objects
- """
- if self.book_info is None:
- raise NoDublinCore('No Dublin Core in document.')
- persons = set(self.book_info.editors +
- self.book_info.technical_editors)
- for child in self.parts():
- persons.update(child.editors())
- if None in persons:
- persons.remove(None)
- return persons
-
# Converters
def as_html(self, *args, **kwargs):
return p == 0
+# not used
def load_including_children(wldoc=None, provider=None, uri=None):
""" Makes one big xml file with children inserted at end.
if uri and provider:
f = provider.by_uri(uri)
+ # WTF DocProvider.by_uri() returns IOFile, so no .read() there
text = f.read().decode('utf-8')
f.close()
elif wldoc is not None:
""" For use in XSLT. """
return u','.join(k for k, v in self.customization.items() if v)
- def get_document(self):
- document = load_including_children(self.wldoc)
- root = document.edoc.getroot()
- root.set('editors', u', '.join(sorted(
- editor.readable() for editor in document.editors())))
-
- # hack the tree
- move_motifs_inside(document.edoc)
- hack_motifs(document.edoc)
- parse_creator(document.edoc)
- substitute_hyphens(document.edoc)
- fix_hanging(document.edoc)
- return document
-
def get_texml(self):
- style_filename = get_stylesheet("wl2tex")
- functions.reg_get(self)
- try:
- style = etree.parse(style_filename)
- texml = self.get_document().transform(style)
- return texml
- except (XMLSyntaxError, XSLTApplyError), e:
- raise ParseError(e)
+ raise NotImplementedError
def get_tex_dir(self):
texml = self.get_texml()