Ejemplo n.º 1
0
 def build_guide_xml(self):
     guideout = []
     guideout.append('<guide>\n')
     for (type, title, href) in self.guide:
         href = quoteurl(href)
         guideout.append('<reference type="%s" href="%s" title="%s"/>\n' % (type, href, title))
     guideout.append('</guide>\n')
     return "".join(guideout)
Ejemplo n.º 2
0
 def build_guide_xml(self):
     guideout = []
     guideout.append('<guide>\n')
     for (type, title, href) in self.guide:
         href = quoteurl(href)
         guideout.append('<reference type="%s" href="%s" title="%s"/>\n' % (type, href, title))
     guideout.append('</guide>\n')
     return "".join(guideout)
Ejemplo n.º 3
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         manout.append('<item id="%s" href="%s" media-type="%s" />\n' % (id, href, mime))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 4
0
 def build_guide_xml(self):
     guideout = []
     if len(self.guide) > 0 or self.epub_version.startswith('2'):
         guideout.append('  <guide>\n')
         for (type, title, href) in self.guide:
             href = quoteurl(href)
             guideout.append('    <reference type="%s" href="%s" title="%s"/>\n' % (type, href, title))
         guideout.append('  </guide>\n')
     return "".join(guideout)
Ejemplo n.º 5
0
 def build_guide_xml(self):
     guideout = []
     if len(self.guide) > 0 or self.epub_version.startswith('2'):
         guideout.append('  <guide>\n')
         for (type, title, href) in self.guide:
             href = quoteurl(href)
             guideout.append('    <reference type="%s" href="%s" title="%s"/>\n' % (type, href, title))
         guideout.append('  </guide>\n')
     return "".join(guideout)
Ejemplo n.º 6
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         manout.append('<item id="%s" href="%s" media-type="%s" />\n' %
                       (id, href, mime))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 7
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         props = ''
         properties = self.id_to_props[id]
         if properties is not None:
             props = ' properties="%s"' % properties
         manout.append('<item id="%s" href="%s" media-type="%s"%s />\n' % (id, href, mime, props))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 8
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         props = ''
         properties = self.id_to_props[id]
         if properties is not None:
             props = ' properties="%s"' % properties
         manout.append('<item id="%s" href="%s" media-type="%s"%s />\n' % (id, href, mime, props))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 9
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         props = ''
         properties = self.id_to_props[id]
         if properties is not None:
             props = ' properties="%s"' % properties
         fall = ''
         fallback = self.id_to_fall[id]
         if fallback is not None:
             fall = ' fallback="%s"' % fallback
         over = ''
         overlay = self.id_to_over[id]
         if overlay is not None:
             over = ' media-overlay="%s"' % overlay
         manout.append('<item id="%s" href="%s" media-type="%s"%s%s%s />\n' % (id, href, mime, props, fall, over))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 10
0
 def build_manifest_xml(self):
     manout = []
     manout.append('<manifest>\n')
     for id in sorted(self.id_to_mime):
         href = quoteurl(self.id_to_href[id])
         mime = self.id_to_mime[id]
         props = ''
         properties = self.id_to_props[id]
         if properties is not None:
             props = ' properties="%s"' % properties
         fall = ''
         fallback = self.id_to_fall[id]
         if fallback is not None:
             fall = ' fallback="%s"' % fallback
         over = ''
         overlay = self.id_to_over[id]
         if overlay is not None:
             over = ' media-overlay="%s"' % overlay
         manout.append('<item id="%s" href="%s" media-type="%s"%s%s%s />\n' % (id, href, mime, props, fall, over))
     manout.append('</manifest>\n')
     return "".join(manout)
Ejemplo n.º 11
0
 def launch(self):
     script_module = self.script_module
     script_type = self.script_type
     container = self.container
     sys.stdout = SavedStream(sys.stdout, 'stdout', self)
     sys.stderr = SavedStream(sys.stderr, 'stderr', self)
     try:
         target_script = __import__(script_module)
         self.exitcode = target_script.run(container)
         sys.stdout = sys.stdout.stream
         sys.stderr = sys.stderr.stream
     except Exception as e:
         sys.stderr.write(traceback.format_exc())
         sys.stderr.write("Error: %s\n" % e)
         sys.stdout = sys.stdout.stream
         sys.stderr = sys.stderr.stream
         self.exitcode = -1
         pass
     if self.exitcode != 0:
         self.wrapout.append(_XML_HEADER)
         self.wrapout.append(
             '<wrapper type="%s">\n<result>failed</result>\n<changes/>\n' %
             script_type)
         return self.exitcode
     if script_type == "edit":
         # write out the final updated opf to the outdir
         container._w.write_opf()
     # save the wrapper results to a file before exiting the thread
     self.wrapout.append(_XML_HEADER)
     self.wrapout.append('<wrapper type="%s">\n' % script_type)
     self.wrapout.append('<result>success</result>\n')
     self.wrapout.append('<changes>\n')
     if script_type == "edit":
         for ftype, id, href in container._w.deleted:
             if ftype == 'manifest':
                 bookhref = href
                 mime = container._w.getmime(bookhref)
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append(
                 '<deleted href="%s" id="%s" media-type="%s" />\n' %
                 (quoteurl(bookhref), id, mime))
     if script_type in ['input', 'edit']:
         for id in container._w.added:
             if id in container._w.id_to_bookpath:
                 bookhref = container._w.id_to_bookpath[id]
                 mime = container._w.id_to_mime[id]
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append(
                 '<added href="%s" id="%s" media-type="%s" />\n' %
                 (quoteurl(bookhref), id, mime))
     if script_type == 'edit':
         for id in container._w.modified:
             if id in container._w.id_to_bookpath:
                 bookhref = container._w.id_to_bookpath[id]
                 mime = container._w.id_to_mime[id]
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append(
                 '<modified href="%s" id="%s" media-type="%s" />\n' %
                 (quoteurl(bookhref), id, mime))
     if script_type == 'validation':
         for vres in container.results:
             self.wrapout.append(
                 '<validationresult type="%s" bookpath="%s" linenumber="%s" charoffset="%s" message="%s" />\n'
                 % (vres.restype, vres.bookpath, vres.linenumber,
                    vres.charoffset, vres.message))
     self.wrapout.append('</changes>\n')
     self.exitcode = 0
     return
Ejemplo n.º 12
0
 def launch(self):
     script_module = self.script_module
     script_type = self.script_type
     container = self.container
     sys.stdout = SavedStream(sys.stdout, 'stdout', self)
     sys.stderr = SavedStream(sys.stderr, 'stderr', self)
     try:
         target_script = __import__(script_module)
         self.exitcode = target_script.run(container)
         sys.stdout = sys.stdout.stream
         sys.stderr = sys.stderr.stream
     except Exception as e:
         sys.stderr.write(traceback.format_exc())
         sys.stderr.write("Error: %s\n" % e)
         sys.stdout = sys.stdout.stream
         sys.stderr = sys.stderr.stream
         self.exitcode = -1
         pass
     if self.exitcode != 0:
         self.wrapout.append(_XML_HEADER)
         self.wrapout.append('<wrapper type="%s">\n<result>failed</result>\n<changes/>\n' % script_type)
         return self.exitcode
     if script_type == "edit":
         # write out the final updated opf to the outdir
         container._w.write_opf()
     # save the wrapper results to a file before exiting the thread
     self.wrapout.append(_XML_HEADER)
     self.wrapout.append('<wrapper type="%s">\n' % script_type)
     self.wrapout.append('<result>success</result>\n')
     self.wrapout.append('<changes>\n')
     if script_type == "edit":
         for ftype, id, href in container._w.deleted:
             if ftype == 'manifest':
                 bookhref = 'OEBPS/' + href
                 mime = container._w.getmime(bookhref)
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append('<deleted href="%s" id="%s" media-type="%s" />\n' % (quoteurl(bookhref), id, mime))
     if script_type in ['input', 'edit']:
         for id in container._w.added:
             if id in container._w.id_to_href:
                 href = container._w.id_to_href[id]
                 bookhref = 'OEBPS/' + href
                 mime = container._w.id_to_mime[id]
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append('<added href="%s" id="%s" media-type="%s" />\n' % (quoteurl(bookhref), id, mime))
     if script_type == 'edit':
         for id in container._w.modified:
             if id in container._w.id_to_href:
                 href = container._w.id_to_href[id]
                 bookhref = 'OEBPS/' + href
                 mime = container._w.id_to_mime[id]
             else:
                 bookhref = id
                 id = ""
                 mime = container._w.getmime(bookhref)
             self.wrapout.append('<modified href="%s" id="%s" media-type="%s" />\n' % (quoteurl(bookhref), id, mime))
     if script_type == 'validation':
         for vres in container.results:
             self.wrapout.append('<validationresult type="%s" filename="%s" linenumber="%s" charoffset="%s" message="%s" />\n' % (vres.restype, vres.filename, vres.linenumber, vres.charoffset, vres.message))
     self.wrapout.append('</changes>\n')
     self.exitcode = 0
     return