Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Re-factoring
  • Loading branch information
kthoden committed Mar 29, 2019
1 parent 21fcfa2 commit d5cc216
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions imxml2epub.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# Time-stamp: <2018-08-22 15:49:01 (kthoden)>
# Time-stamp: <2019-03-29 15:45:37 (kthoden)>

""" Convert a customized DocBook XML file into a set of files that
constitute the contents of an EPUB file.
Expand Down Expand Up @@ -496,6 +496,7 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber):
# Copy File of the Image
# If it's in a subfolder, name of folder and name of image will be merged
strImageFileString = xmlFigure.find(".//file").text
logging.debug(f"Working on image {strImageFileString}.")
strImageFileString = strImageFileString.rstrip("\n")
strImageFileDir = os.path.dirname(strImageFileString)
# Remove / from path
Expand All @@ -508,7 +509,7 @@ def addToTocncx(tocncx, Label, intTechnicalChapterNumber):
elif strImageFileName_Suffix.lower() in [".png", ".pdf"]:
extension_and_mime = "png"
else:
print("Found an unrecognized image suffix: %s" % strImageFileName_Suffix)
logging.error(f"Found an unrecognized image suffix: {strImageFileName_Suffix}")
sys.exit()

strImageFilepath = libeoaconvert.sanitizeImage(os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName, GM_PATH, TL_PATH)
Expand Down Expand Up @@ -1405,7 +1406,7 @@ class FootnoteError(Exception):
etree.strip_attributes(xmlEbookTree, "id-text", "noindent", "type", "label", "spacebefore", "rend") # also contained "id"
etree.strip_elements(xmlEbookTree, "citekey", with_tail=False)

# Write every Part and Chapter into one file
logging.info("Write every Part and Chapter into one file")
xmlChapters = xmlEbookTree.findall("//div1")
listParts = []
intTechnicalChapterNumber = 1
Expand Down Expand Up @@ -1450,7 +1451,7 @@ class FootnoteError(Exception):
# Content_OPF hinzufügen
intTechnicalChapterNumber += 1

# Convert Facsimile-Parts
logging.info("Convert Facsimile-Parts")
xmlParts = xmlEbookTree.findall("//div0")
for xmlPart in xmlParts:
print("-------------")
Expand Down Expand Up @@ -1486,14 +1487,14 @@ class FootnoteError(Exception):
# Content_OPF hinzufügen
intTechnicalChapterNumber += 1

# Saving toc.ncx
logging.info("Saving toc.ncx")
tmpFileName = os.getcwd() + "/CONVERT/epub/OEBPS/toc.ncx"
tmpFile = open (tmpFileName, "w")
tmpResult = etree.tostring(tocncx, pretty_print=True, encoding="unicode")
tmpFile.write(tmpResult)
tmpFile.close()

# Saving content.opf
logging.info("Saving content.opf")
tmpFileName = os.getcwd() + "/CONVERT/epub/OEBPS/content.opf"
tmpFile = open (tmpFileName, "w")
tmpResult = etree.tostring(contentopf, pretty_print=True, encoding="unicode")
Expand All @@ -1504,8 +1505,9 @@ class FootnoteError(Exception):
# Finishing various Stuff #
############################################################################

# Write Temporary XML-Tree
logging.info("Write Temporary XML-Tree")
ergebnisdatei = open("tmp_files/Devel_ebook.xml", "w")
ergebnis = etree.tostring(xmlEbookTree, pretty_print=True, encoding="unicode")
ergebnisdatei.write(ergebnis)
ergebnisdatei.close()
logging.info("Finished!")

0 comments on commit d5cc216

Please sign in to comment.