From 36d0bb8a76203f7082cc41a503fb9f5dab5996e1 Mon Sep 17 00:00:00 2001 From: Klaus Thoden Date: Thu, 31 May 2018 13:10:03 +0200 Subject: [PATCH] Instead of bailing out, create directory and copy files --- eoatex2imxml.py | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/eoatex2imxml.py b/eoatex2imxml.py index 1aae864..eb6a80e 100755 --- a/eoatex2imxml.py +++ b/eoatex2imxml.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8; mode: python -*- -# Time-stamp: <2018-04-23 10:06:41 (kthoden)> +# Time-stamp: <2018-05-31 12:25:32 (kthoden)> # license? __version__= "1.0" @@ -58,6 +58,11 @@ # run biber_2.1 -O biber2-1n.bbl $INPUT to obtain this file BIBERFILE = "biber2-1.bbl" +######################## +# Constant directories # +######################## +CONVERT_DIR = os.getcwd() + os.path.sep + "CONVERT" + ################################## # Reading the configuration file # ################################## @@ -356,7 +361,7 @@ def cleanup(): # Checking for existance of tools and libraries # ################################################# if not os.path.exists(TRALICS_PATH_LIB): - print ("Cannot find the Tralics configuration at %s. Exiting." % TRALICS_PATH_LIB) + print("Cannot find the Tralics configuration at %s. Exiting." % TRALICS_PATH_LIB) sys.exit() ################################## @@ -371,15 +376,26 @@ def cleanup(): os.mkdir(os.getcwd() + "/debug") # Check for folder and necessary files -if not os.path.exists(os.getcwd() + "/CONVERT"): - print ("Das notwendige Verzeichnis CONVERT wurde noch nicht erstellt.") - sys.exit() -if not os.path.exists(os.getcwd() + "/CONVERT/cover.jpg"): - print ("Die Datei cover.jpg im Verzeichnis CONVERT fehlt.") - sys.exit() -if not os.path.exists(os.getcwd() + "/CONVERT/publication.cfg"): - print ("Die Datei publication.cfg im Verzeichnis CONVERT fehlt.") - sys.exit() +if not os.path.exists(CONVERT_DIR): + print("The directory CONVERT has not been created yet. Creating it for you") + time.sleep(1) + os.makedirs(CONVERT_DIR) +if not os.path.exists(CONVERT_DIR + os.path.sep + "publication.cfg"): + print("The publication.cfg file is missing in CONVERT directory.") + if os.path.exists(os.getcwd() + os.path.sep + "publication.cfg"): + shutil.copy("publication.cfg", CONVERT_DIR) + print("Copied from current directory.") + else: + print("Found no publication.cfg. Exiting") + sys.exit() +if not os.path.exists(CONVERT_DIR + os.path.sep + "cover.jpg"): + print("The file Cover.jpg in CONVERT directory is missing.") + if os.path.exists(os.getcwd() + os.path.sep + "Cover.jpg"): + shutil.copy("Cover.jpg", CONVERT_DIR + os.path.sep + "cover.jpg") + print("Copied from current directory.") + else: + print("No coverfile found. You can create a temporary one with the mkimage.py script") + sys.exit() # if os.path.exists(os.getcwd() + "/pre_xml.tex") == False: # print ("pre_xml fehlt") # sys.exit() @@ -1295,8 +1311,8 @@ def cleanup(): form_cit = BeautifulSoup(formatted_citations, "html.parser") for xmlChapter in xmlChapters: - print ("-----------------------------------------------------") - print ("Processing References for Chapter " + str(intChapterNumber)) + print("-----------------------------------------------------") + print("Processing References for Chapter " + str(intChapterNumber)) xmlCitations = xmlChapter.xpath(".//EOAciteauthoryear | .//EOAciteyear | .//EOAcitemanual") if bib_type == "anthology":