Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed some commented lines
  • Loading branch information
kthoden committed May 14, 2019
1 parent 226e98f commit c69a307
Showing 1 changed file with 5 additions and 39 deletions.
44 changes: 5 additions & 39 deletions imxml2epub.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# Time-stamp: <2019-05-14 17:01:53 (kthoden)>
# Time-stamp: <2019-05-14 17:06:15 (kthoden)>

""" Convert a customized DocBook XML file into a set of files that
constitute the contents of an EPUB file.
Expand Down Expand Up @@ -107,12 +107,6 @@

GM_PATH = "gm"
PDFCROP_EXEC = "pdfcrop"
# TL_PATH = CONFIG['Executables']['texlive']
# TEXBIN_PATH = CONFIG['Executables']['texbin']
# TRALICS_PATH_EXEC = CONFIG['Executables']['tralics_path_exec']
# TRALICS_PATH_LIB = CONFIG['Executables']['TRALICS_PATH_LIB']
# SUPPORT_PATH = CONFIG['Executables']['support_path']
# AUX_TeX_FILES_PATH = CONFIG['Executables']['aux_tex_files_path']

############################
# Paths:
Expand All @@ -121,7 +115,6 @@
OUTPUT_DIR = Path( args.output_dir )
PUBLICATION_DIR = Path( args.publication_dir )
TEMP_DIR = OUTPUT_DIR / "tmp_files"
# CONVERT_DIR = OUTPUT_DIR / "CONVERT"
DEBUG_DIR = OUTPUT_DIR / "debug"

############################
Expand All @@ -132,8 +125,6 @@

if not TEMP_DIR.exists():
os.makedirs( TEMP_DIR )
# if not DIR.exists():
# os.makedirs( CONVERT_DIR )
if not DEBUG_DIR.exists():
os.makedirs( DEBUG_DIR )

Expand All @@ -154,18 +145,8 @@
else:
logging.error("No coverfile found. You can create a temporary one with the mkimage.py script")
sys.exit( 1 )
# if os.path.exists(os.getcwd() + "/pre_xml.tex") == False:
# print ("pre_xml fehlt")
# sys.exit()


# lang_dict = {"fig" : {"en" : "Fig.", "de" : "Abb."}}

Datei = open( TEMP_DIR / 'intermediate.log', 'w')
'''
tmpDir = os.getcwd() + "/tmp_files/"
Datei = open('tmp_files/intermediate.log', 'w')
'''
# Datei = open( TEMP_DIR / 'intermediate.log', 'w')

xmlTree = etree.parse( str(INPUT_DIR / "tmp_files" / "IntermediateXMLFile.xml") )

Expand Down Expand Up @@ -393,21 +374,18 @@ def create_epub_container(filename, OUTPUT_DIR):
EPUB_FILES / "eoa-epub-termes.css",
OUTPUT_DIR / "OEBPS/eoa-epub.css"
)
# shutil.copy(EPUB_FILES + "eoa-epub-termes.css", os.getcwd() + "/CONVERT/epub/OEBPS/eoa-epub.css")
elif args.font == "libertine":
shutil.copy(
EPUB_FILES / "eoa-epub-libertine.css",
OUTPUT_DIR / "OEBPS/eoa-epub.css"
)
# shutil.copy(EPUB_FILES + "eoa-epub-libertine.css", os.getcwd() + "/CONVERT/epub/OEBPS/eoa-epub.css")
font_files = libertine_fonts
else:
logging.info("Font not recognized, falling back to default.")
shutil.copy(
EPUB_FILES / "eoa-epub-termes.css",
OUTPUT_DIR / "OEBPS/eoa-epub.css"
)
# shutil.copy(EPUB_FILES + "eoa-epub-termes.css", os.getcwd() + "/CONVERT/epub/OEBPS/eoa-epub.css")

otf_id_counter = 1
txt_id_counter = 1
Expand All @@ -417,7 +395,6 @@ def create_epub_container(filename, OUTPUT_DIR):
EPUB_FILES / fontfile,
OUTPUT_DIR / "OEBPS/fonts/"
)
# shutil.copy(EPUB_FILES + fontfile, os.getcwd() + "/CONVERT/epub/OEBPS/fonts/")

base_file_name, file_extension = os.path.splitext(fontfile)

Expand Down Expand Up @@ -542,17 +519,13 @@ def create_epub_container(filename, OUTPUT_DIR):
OUTPUT_DIR / "cover.jpg",
OUTPUT_DIR / "OEBPS/images/"
)
# shutil.copy(os.getcwd() + "/CONVERT/Cover.jpg", os.getcwd() + "/CONVERT/epub/OEBPS/images/")
xmlItem = etree.Element("item")
xmlItem.set("id", "cover")
xmlItem.set("href", "cover.xhtml")
xmlItem.set("media-type", "application/xhtml+xml")
xmlManifest.append(xmlItem)
shutil.copy(EPUB_FILES / "epubcover.xhtml", OUTPUT_DIR / "OEBPS/cover.xhtml")
# shutil.copy(EPUB_FILES + "epubcover.xhtml", os.getcwd() + "/CONVERT/epub/OEBPS/cover.xhtml")
logging.info("-------------------")
logging.info("Preparing intro.xhtml")
logging.info("-------------------")
logging.info(f"{logseparator}Preparing intro.xhtml")
if publication_series == "Sources":
tmpFilePath = EPUB_FILES / "epubintro-sources.xhtml"
else:
Expand Down Expand Up @@ -591,9 +564,7 @@ def create_epub_container(filename, OUTPUT_DIR):
# tmpFilePath = os.getcwd() + "/CONVERT/epub/OEBPS/intro.xhtml"
tmpFile = open(tmpFilePath, "w")
tmpFile.write(strIntroHTML)
logging.info("-------------------")
logging.info("Preparing toc.ncx")
logging.info("-------------------")
logging.info(f"{logseparator}Preparing toc.ncx")
xmlHead = tocncx.find("//{http://www.daisy.org/z3986/2005/ncx/}head")
xmlMeta = etree.Element("meta")
xmlMeta.set("name", "dtb:uid")
Expand Down Expand Up @@ -695,7 +666,6 @@ def create_epub_container(filename, OUTPUT_DIR):
PUBLICATION_DIR / strImageFileString,
OUTPUT_DIR / "OEBPS/images" / (strImageFileDir + strImageFileName)
)
# shutil.copy(os.getcwd() + "/" + strImageFileString, os.getcwd() + "/CONVERT/epub/OEBPS/images/" + strImageFileDir + strImageFileName)

extension_and_mime = get_mimetype(strImageFileName_Suffix)

Expand Down Expand Up @@ -1204,7 +1174,6 @@ class FootnoteError(Exception):
INPUT_DIR / "items" / xmlInlineEquation.get("src"),
OUTPUT_DIR / "OEBPS/images" / xmlInlineEquation.get("src")
)
# shutil.copy(os.getcwd() + "/items/" + xmlInlineEquation.get("src"), os.getcwd() + "/CONVERT/epub/OEBPS/images/" + xmlInlineEquation.get("src"))
xmlInlineEquation.set("src", "images/" + xmlInlineEquation.get("src"))
contentopf = addToContentopf(contentopf, xmlInlineEquation.get("src"), xmlInlineEquation.get("src"), "png")

Expand All @@ -1219,7 +1188,6 @@ class FootnoteError(Exception):
INPUT_DIR / "items" / xml_inline_chem.get("src"),
OUTPUT_DIR / "OEBPS/images" / xml_inline_chem.get("src")
)
# shutil.copy(os.getcwd() + "/items/" + xml_inline_chem.get("src"), os.getcwd() + "/CONVERT/epub/OEBPS/images/" + xml_inline_chem.get("src"))
xml_inline_chem.set("src", "images/" + xml_inline_chem.get("src"))
contentopf = addToContentopf(contentopf, xml_inline_chem.get("src"), xml_inline_chem.get("src"), "png")

Expand Down Expand Up @@ -1701,9 +1669,7 @@ class FootnoteError(Exception):
logging.info("Convert Facsimile-Parts")
xmlParts = xmlEbookTree.findall("//div0")
for xmlPart in xmlParts:
logging.info("-------------")
logging.info("Working on Facsimile-Part")
logging.info("-------------")
logging.info(f"{logseparator}Working on Facsimile-Part")
# check if it has a child element EOAfacsimilepart
if bool(xmlPart.findall(".//EOAfacsimilepart")):
htmlChapter = etree.parse(str(EPUB_FILES / "epubchapter.xml"), xmlChapterParser)
Expand Down

0 comments on commit c69a307

Please sign in to comment.