From 381b32513e8343a5bf96c33cd655f7f5fcb52166 Mon Sep 17 00:00:00 2001 From: EsGeh Date: Fri, 15 Nov 2019 14:45:40 +0100 Subject: [PATCH] adjust Dockerfile, deps, readme, scripts, fonts. Latex workflow works. --- .dockerignore | 2 + .gitignore | 1 + Dockerfile | 89 +++++++++++++++++++++++++++++++++++++-- README.md | 49 ++++++++++++++++++--- docker-compose.yaml | 1 + scripts/config/env.conf | 5 +++ scripts/exit.py | 22 +++++----- scripts/init.py | 62 +++++++++++++++++---------- src/data/aux/formula.tex | 10 ++--- src/data/aux/largebib.tex | 2 +- src/eoatex2imxml.py | 46 +++++++++++++------- src/eoatex2pdf.py | 10 ++++- src/imxml2django.py | 14 ++++-- src/imxml2epub.py | 16 ++++--- 14 files changed, 251 insertions(+), 78 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ca39e94 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +/scripts/ +/env diff --git a/.gitignore b/.gitignore index 405398f..a1b4284 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /input/ /output/ +/dependencies/ examples # Byte-compiled / optimized / DLL files diff --git a/Dockerfile b/Dockerfile index e9145c2..1e42597 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,105 @@ -FROM python:3 +FROM python:3.8-buster ENV PYTHONUNBUFFERED 1 ENV SHELL /bin/bash +ENV HOME_DIR /eoa/skripts + + +RUN sed -i "s#deb http://deb.debian.org/debian buster main#deb http://deb.debian.org/debian buster main contrib non-free#g" /etc/apt/sources.list +# sed -i "s#deb http://http.us.debian.org/debian jessie main contrib non-free#deb http://http.us.debian.org/debian jessie main contrib non-free#g" /etc/apt/sources.list + +# add package source 'contrib': +# RUN echo "deb http://deb.debian.org/debian buster main contrib non-free" >> /etc/apt/sources.list +# RUN echo "deb-src http://deb.debian.org/debian buster main contrib non-free" >> /etc/apt/sources.list + # ------------------------------------------ # install necessary packages via apt-get: # ------------------------------------------ -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ +RUN apt-get update && apt-get install -y --no-install-recommends \ graphicsmagick \ pandoc \ pandoc-citeproc \ curl \ + biber + +# install latex: +RUN apt-get update && apt-get install -y --no-install-recommends \ texlive-xetex +# install fonts: +RUN apt-get update && apt-get install -y --no-install-recommends \ + texlive-fonts-extra \ + ttf-mscorefonts-installer \ + msttcorefonts \ + fonts-lmodern \ + fonts-noto-cjk \ + texlive-lang-chinese \ + texlive-science \ + texlive-bibtex-extra \ + tex-gyre + +# install fonts: +RUN cp -r \ + /usr/share/texlive/texmf-dist/fonts/opentype/public/xits \ + /usr/local/share/fonts/ + +RUN fc-cache -f + +RUN apt-get update && apt-get install -y --no-install-recommends \ + less + +# install fonts: +RUN apt-get update && apt-get install -y --no-install-recommends \ + tralics + +# needed for 'pdfcrop': +RUN apt-get update && apt-get install -y --no-install-recommends \ + texlive-extra-utils + +RUN apt-get update && apt-get install -y --no-install-recommends \ + tex4ht + +RUN apt-get update && apt-get install -y --no-install-recommends \ + tidy + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ghostscript + +# install latex: +RUN apt-get update && apt-get install -y --no-install-recommends \ + default-jre + # this is supposed to save memory: RUN rm -rf /var/lib/apt/lists/* +# ------------------------------------------ +# directories for manual installations: +# ------------------------------------------ + +ENV INSTALL_DIR "/eoa/install" +RUN mkdir -p "$INSTALL_DIR/" +ENV BIN_DIR "/eoa/bin" +RUN mkdir -p "$BIN_DIR/" +ENV PATH $BIN_DIR:$PATH + # ------------------------------------------ # install python dependencies: # ------------------------------------------ + +WORKDIR ${INSTALL_DIR} COPY requirements.txt "$INSTALL_DIR/" -RUN pip install -r requirements.txt +RUN pip install -r "requirements.txt" + +# ------------------------------------------ +# manual installations: +# ------------------------------------------ + +# install saxon +# Debians version of saxon is too old. We need to download it "manually" :-P +WORKDIR ${INSTALL_DIR} +RUN wget 'https://sourceforge.net/projects/saxon/files/Saxon-HE/9.6/SaxonHE9-6-0-10J.zip' +RUN unzip -d "$BIN_DIR" "SaxonHE9-6-0-10J.zip" +WORKDIR ${BIN_DIR} +RUN echo 'java -jar $BIN_DIR/saxon9he.jar "$@"' > $BIN_DIR/saxon +RUN chmod ugo+x $BIN_DIR/saxon diff --git a/README.md b/README.md index 694e380..274fddd 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,51 @@ Docker images are not deleted though. # Workflows Compiling your documents involves following a workflow which can consist of several steps. -For all further explanations we assume you are in the docker container. -## The LaTeX workflow (TODO) +## The LaTeX workflow (eoatex -> pdf, django, epub) -TODO +1. load environment variables (just for convenience): -## The DocX workflow (TODO) + $ source .env -TODO +This step will make available the environment variables from `.env`, such as `$INPUT_DIR`. -## Examplary workflow (TODO) +1. copy your publication into the `$INPUT_DIR` -TODO + $ mkdir temp + $ cd temp + $ git clone 'https://github.molgen.mpg.de/EditionOpenAccess/eoa-publication-model.git' + $ cd eoa-publication-model + $ git checkout b40c1606d033fae8e1db9d989881caa1a47e2984 + $ cd ../.. + $ mkdir --parents $INPUT_DIR/example + $ cp -r "temp/eoa-publication-model/examples/eoatex" "$INPUT_DIR/example/eoatex" + +1. enter the docker container + + $ ./scripts/run.py # run if not yet running + $ ./scripts/exec_in_container.py # enter container + +1. eoatex -> pdf + + $ ./eoatex2pdf.py -f $INPUT_DIR/example/eoatex/EOASample.tex + +(adjust filename if necessary) + +1. eoatex -> imxml (convert to "intermediate xml") + + $ ./eoatex2pdf.py -f $INPUT_DIR/example/eoatex/EOASample.tex + +(adjust filename if necessary) + +1. imxml -> django + + $ ./imxml2django.py --publication-dir $INPUT_DIR/example/eoatex + +1. imxml -> epub + + $ ./imxml2epub.py --publication-dir $INPUT_DIR/example/eoatex + +## The DocX workflow (docx -> TEI -> pdf, django, epub) (TODO) + +TODO (status: scripts broken) diff --git a/docker-compose.yaml b/docker-compose.yaml index 8b6ce47..fb79882 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,6 +15,7 @@ services: environment: - INPUT_DIR=${INPUT_DIR_IN_CONTAINER} - OUTPUT_DIR=${OUTPUT_DIR_IN_CONTAINER} + - DEPENDENCIES_DIR=${DEPENDENCIES_DIR_IN_CONTAINER} - INSTALL_DIR=${SRC_DIR_IN_CONTAINER} ports: [] user: ${USER}:${GROUP} diff --git a/scripts/config/env.conf b/scripts/config/env.conf index 1e34dc6..a31514c 100644 --- a/scripts/config/env.conf +++ b/scripts/config/env.conf @@ -14,11 +14,16 @@ CONTAINER_NAME=eoa_skripts SRC_DIR=src SRC_DIR_IN_CONTAINER=/eoa/skripts + INPUT_DIR=input INPUT_DIR_IN_CONTAINER=/eoa/input + OUTPUT_DIR=output OUTPUT_DIR_IN_CONTAINER=/eoa/output +DEPENDENCIES_DIR=dependencies +DEPENDENCIES_DIR_IN_CONTAINER=/eoa/dependencies + ################################################### # user and group: # USER=$(id -u) diff --git a/scripts/exit.py b/scripts/exit.py index ac3d50c..26e25ec 100755 --- a/scripts/exit.py +++ b/scripts/exit.py @@ -6,22 +6,13 @@ import shutil import os -def rm_dirs( config ): - path = Path( BASE_DIR, config['INPUT_DIR'] ) +def rm_dirs( config, rm_deps): + path = Path( BASE_DIR, config['DEPENDENCIES_DIR'] ) print( "removing dir '{}'".format( path ) ) shutil.rmtree( path, ignore_errors=True ) - # os.system('rm -rf "{}"'.format( path )) - - path = Path( BASE_DIR, config['OUTPUT_DIR'] ) - print( "removing dir '{}'".format( path ) ) - shutil.rmtree( - path, - ignore_errors=True - ) - # os.system('rm -rf "{}"'.format( path )) def rm_docker_env_file( config ): path = Path( @@ -39,6 +30,10 @@ def rm_docker_env_file( config ): parser = ArgumentParser( description="clean up the repository" ) + parser.add_argument( + "--rm-deps", + action = "store_true" + ) parser.add_argument( "--env-file", action = "store_true" @@ -53,6 +48,9 @@ def rm_docker_env_file( config ): stop( config ) - rm_dirs( config ) + rm_dirs( + config, + rm_deps = args.rm_deps or args.all + ) if args.env_file or args.all: rm_docker_env_file( config ) diff --git a/scripts/init.py b/scripts/init.py index f2167e6..32cbbbc 100755 --- a/scripts/init.py +++ b/scripts/init.py @@ -2,6 +2,7 @@ from utils.settings import BASE_DIR, load_config, create_docker_env_file from utils.functions import exec_in_container, run +from stop import stop from pathlib import Path import shlex @@ -12,11 +13,8 @@ from time import sleep BASE_DIR = Path( __file__ ).parent.parent -DEP_DIR = BASE_DIR / "dependencies" -SQLDB_WAIT_TIME=20 - def create_dir(dir): print( "creating dir '{}'".format( dir ) ) Path(dir).mkdir( @@ -36,6 +34,9 @@ def copy_dir(src, dst): ) def create_dirs( config ): + create_dir( + BASE_DIR / config['DEPENDENCIES_DIR'] + ) create_dir( BASE_DIR / config['INPUT_DIR'] ) @@ -47,23 +48,26 @@ def install_git_dep( repo_name, repo_uri, repo_hash, - init_script = None + force = False, + init_script = None, ): - if (DEP_DIR / repo_name).exists(): - shutil.rmtree( DEP_DIR / repo_name ) + DEP_DIR = BASE_DIR / config['DEPENDENCIES_DIR'] + if not((DEP_DIR / repo_name).exists()) or force: + if (DEP_DIR / repo_name).exists(): + shutil.rmtree( DEP_DIR / repo_name ) - subprocess.check_call( - ["git", "clone", repo_uri, DEP_DIR / repo_name] - ) - subprocess.check_call( - ["git", "checkout", repo_hash], - cwd = DEP_DIR / repo_name - ) - if init_script is not None: subprocess.check_call( - shlex.split( init_script ), + ["git", "clone", repo_uri, DEP_DIR / repo_name] + ) + subprocess.check_call( + ["git", "checkout", repo_hash], cwd = DEP_DIR / repo_name ) + if init_script is not None: + subprocess.check_call( + shlex.split( init_script ), + cwd = DEP_DIR / repo_name + ) if __name__ == '__main__': @@ -72,6 +76,10 @@ def install_git_dep( parser = ArgumentParser( description="initialize the repository: download git deps, create directories, etc" ) + parser.add_argument( + "--force-deps", + action = "store_true" + ) parser.add_argument( "--build", action = "store_true" @@ -84,16 +92,21 @@ def install_git_dep( # load env_file: config = load_config() + create_dirs( config ) + ## install git dependencies: - ''' install_git_dep( - repo_name = "eoa-publication-model", - repo_uri = "https://github.molgen.mpg.de/EditionOpenAccess/eoa-publication-model.git", - repo_hash = "d76a81feef1ebb708a90376d3f5a7eccb51807b0" + repo_name = "TEI", + repo_uri = "https://github.com/TEIC/TEI.git", + repo_hash = "7fbbc7c5c2ba533dc70f561b27101dbfa7f519a0", + force = args.force_deps, + ) + install_git_dep( + repo_name = "Stylesheets", + repo_uri = "https://github.com/TEIC/stylesheets.git", + repo_hash = "2a01be46ee82fce5eba6074359b3d18db2222e0c", + force = args.force_deps, ) - ''' - - create_dirs( config ) # rebuild docker image: if args.build: @@ -101,3 +114,8 @@ def install_git_dep( env = config, build = True, ) + stop( + env = config, + ) + + print( "done." ) diff --git a/src/data/aux/formula.tex b/src/data/aux/formula.tex index 4a370c4..0b93486 100755 --- a/src/data/aux/formula.tex +++ b/src/data/aux/formula.tex @@ -14,8 +14,8 @@ % Definition der Schriftarten für die einzelnen Schriftsysteme. % Das Paket zhspacing fügt weitere Unterstützung für Chinesisch hinzu -\newfontfamily\zhfont{BiauKai} -\newfontfamily\zhpunctfont{BiauKai} +\newfontfamily\zhfont{Noto Serif CJK SC} +\newfontfamily\zhpunctfont{Noto Serif CJK SC} \usepackage{zhspacing} \zhspacing @@ -27,8 +27,8 @@ \XeTeXcharclass`’=6 \XeTeXcharclass`…=6 -\newfontfamily\textchinese{BiauKai} -\newfontfamily\chinesefont{BiauKai} +\newfontfamily\textchinese{Noto Serif CJK SC} +\newfontfamily\chinesefont{Noto Serif CJK SC} \newfontfamily\germanfont{Times New Roman} \newfontfamily\englishfont{Times New Roman} \newfontfamily\greekfont{Times New Roman} @@ -55,4 +55,4 @@ $DERINHALT -\end{document} \ No newline at end of file +\end{document} diff --git a/src/data/aux/largebib.tex b/src/data/aux/largebib.tex index 6a573f3..7e79bdf 100644 --- a/src/data/aux/largebib.tex +++ b/src/data/aux/largebib.tex @@ -18,7 +18,7 @@ } \setotherlanguage[variant=polytonic]{greek} -\newfontfamily\chinesefont{BiauKai} +\newfontfamily\chinesefont{Noto Serif CJK SC} \newcommand{\EOAbibtweaks}{ % Remove pp from references diff --git a/src/eoatex2imxml.py b/src/eoatex2imxml.py index dbad4c4..3b7baa9 100755 --- a/src/eoatex2imxml.py +++ b/src/eoatex2imxml.py @@ -46,6 +46,15 @@ SCRIPT_PATH = Path( __file__ ) SCRIPT_NAME = SCRIPT_PATH.stem +DEFAULT_INPUT_DIR = \ + Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input') + +DEFAULT_OUTPUT_DIR = \ + Path(os.environ['OUTPUT_DIR'] if 'OUTPUT_DIR' in os.environ else './output') + +DEFAULT_DEPENDENCIES_DIR = \ + Path(os.environ['DEPENDENCIES_DIR'] if 'DEPENDENCIES_DIR' in os.environ else './dependencies') + ##################### # Parsing arguments # ##################### @@ -60,8 +69,7 @@ ) parser.add_argument( "-l", "--log-dir", - default = Path("output/logs"), - # default = Path("logs", SCRIPT_NAME).with_suffix(".log"), + default = DEFAULT_OUTPUT_DIR / "logs", help="logfile" ) parser.add_argument( @@ -71,12 +79,12 @@ ) parser.add_argument( "--tei-guidelines", - default = "tei/TEI", + default = DEFAULT_DEPENDENCIES_DIR / "TEI", help="path to the https://github.com/TEIC/TEI" ) parser.add_argument( "--tei-stylesheets", - default = "tei/Stylesheets", + default = DEFAULT_DEPENDENCIES_DIR / "Stylesheets", help="path to the https://github.com/TEIC/Stylesheets" ) parser.add_argument( @@ -86,12 +94,12 @@ ) parser.add_argument( "--latex-dir", - default = "./output/latex", + default = DEFAULT_OUTPUT_DIR / "latex", help="directory where to find the output generated by eoatex2pdf.py" ) parser.add_argument( "-o", "--output-dir", - default = "./output/imxml", + default = DEFAULT_OUTPUT_DIR / "imxml", help="where to dump all output files" ) parser.add_argument( @@ -255,7 +263,7 @@ def TeX2PNG(LaTeXCode, Type, Chapter, Number): Argumente = shlex.split(Kommando) # Redirecting stderr to save XeLaTeX-Output Datei = open(TEMP_DIR / 'xelatex-run.log', 'w') - Ergebnis = subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + Ergebnis = subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) if Ergebnis == 0: logging.info("Successfully converted formula " + Type + str(Chapter) + "_" + str(Number)) if Ergebnis == 1: @@ -267,7 +275,7 @@ def TeX2PNG(LaTeXCode, Type, Chapter, Number): ) # Kommando = PDFCROP_EXEC + " " + formula_tmp_dir + Type + "_" + str(Chapter) + "_" + str(Number) + ".pdf " + formula_tmp_dir + Type + "_" + str(Chapter) + "_" + str(Number) + "a.pdf" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) Kommando = "{cmd} convert -density 144 {arg1} {arg2}".format( cmd=GM_PATH, arg1 = (formula_tmp_dir / (Type + "_" + str(Chapter) + "_" + str(Number) + "a.pdf")).absolute(), @@ -275,7 +283,7 @@ def TeX2PNG(LaTeXCode, Type, Chapter, Number): ) # Kommando = GM_PATH + " convert -density 144 " + formula_tmp_dir + Type + "_" + str(Chapter) + "_" + str(Number) + "a.pdf " + os.getenv("PWD") + "/items/" + Type + "_" + str(Chapter) + "_" + str(Number) + ".png" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) # logging.info("TeX2PNG done") return LaTeXCode @@ -789,7 +797,7 @@ def process_inline_equations( xmlChapters ): Kommando = "xelatex --halt-on-error " + str(tmpFile.absolute()) Argumente = shlex.split(Kommando) Datei = open(TEMP_DIR / 'xelatex-run.log', 'w') - Ergebnis = subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + Ergebnis = subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) logging.info("Splitting all Inline Equations") pdf_burst("EOAinline.pdf", formula_tmp_dir) logging.info("Converting %s split pages into PNG-Images" % len(dictEOAineqs.keys())) @@ -804,7 +812,7 @@ def process_inline_equations( xmlChapters ): ) # Kommando = PDFCROP_EXEC + " " + formula_tmp_dir + "EOAformulas_" + str(intRunningOrder) + ".pdf " + formula_tmp_dir + dictEOAineqs[intRunningOrder] + ".pdf" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) Kommando = "{cmd} convert -density 144 {arg1} {arg2}".format( cmd = GM_PATH, @@ -813,7 +821,7 @@ def process_inline_equations( xmlChapters ): ) #Kommando = GM_PATH + " convert -density 144 " + formula_tmp_dir + dictEOAineqs[intRunningOrder] + ".pdf " + os.getenv("PWD") + "/items/" + dictEOAineqs[intRunningOrder] + ".png" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) counter_dictEOAineqs += 1 else: @@ -875,7 +883,7 @@ def process_eoachem( xmlChapters ): Kommando = "xelatex --halt-on-error " + str(tmpFile.absolute()) Argumente = shlex.split(Kommando) Datei = open(TEMP_DIR / 'xelatex-run.log', 'w') - Ergebnis = subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + Ergebnis = subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) logging.info("Splitting all Inline Chemical formulas") pdf_burst("EOAchem.pdf", formula_tmp_dir) logging.info("Converting %s split pages into PNG-Images" % len(dictEOAchems.keys())) @@ -890,7 +898,7 @@ def process_eoachem( xmlChapters ): ) # Kommando = PDFCROP_EXEC + " " + formula_tmp_dir + "EOAformulas_" + str(intRunningOrder) + ".pdf " + formula_tmp_dir + dictEOAchems[intRunningOrder] + ".pdf" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) Kommando = "{cmd} convert -density 144 {arg1} {arg2}".format( cmd=GM_PATH, @@ -899,7 +907,7 @@ def process_eoachem( xmlChapters ): ) # Kommando = GM_PATH + " convert -density 144 " + formula_tmp_dir + dictEOAchems[intRunningOrder] + ".pdf " + os.getenv("PWD") + "/items/" + dictEOAchems[intRunningOrder] + ".png" Argumente = shlex.split(Kommando) - subprocess.call(Argumente,cwd=formula_tmp_dir,stdout=Datei) + subprocess.check_call(Argumente,cwd=formula_tmp_dir,stdout=Datei) counter_dictEOAchems += 1 else: @@ -1066,7 +1074,13 @@ def write_json_bibl( citeproc_command = "pandoc-citeproc --bib2json %s" % bib_database + ".bib" logging.debug(f"Running citeproc with the following command: {citeproc_command}") citeproc_arguments = shlex.split(citeproc_command) - citeproc_process = subprocess.Popen(citeproc_arguments, stdout=subprocess.PIPE) + env = os.environ.copy() + env['LANG'] = 'en_US.UTF-8' + citeproc_process = subprocess.Popen( + citeproc_arguments, + env = env, + stdout=subprocess.PIPE + ) citeproc_json = citeproc_process.stdout.read() citations_json = json.loads(citeproc_json) # for x in citations_json: diff --git a/src/eoatex2pdf.py b/src/eoatex2pdf.py index 8b2c894..90b8277 100755 --- a/src/eoatex2pdf.py +++ b/src/eoatex2pdf.py @@ -16,6 +16,12 @@ SCRIPT_PATH = Path( __file__ ) SCRIPT_NAME = SCRIPT_PATH.stem +INPUT_DIR = \ + Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input') + +OUTPUT_DIR = \ + Path(os.environ['OUTPUT_DIR'] if 'OUTPUT_DIR' in os.environ else './output') + def main( input_file, output_dir, @@ -97,7 +103,7 @@ def main( ) parser.add_argument( "-o", "--output-dir", - default = "./output/latex", + default = OUTPUT_DIR / "latex", help = "output directory" ) parser.add_argument( @@ -107,7 +113,7 @@ def main( ) parser.add_argument( "-l", "--log-file", - default = Path("output/logs", SCRIPT_NAME).with_suffix(".log"), + default = (OUTPUT_DIR / "logs" / SCRIPT_NAME).with_suffix(".log"), help="logfile" ) parser.add_argument( diff --git a/src/imxml2django.py b/src/imxml2django.py index 84e3323..fc13071 100755 --- a/src/imxml2django.py +++ b/src/imxml2django.py @@ -33,6 +33,12 @@ SCRIPT_PATH = Path( __file__ ) SCRIPT_NAME = SCRIPT_PATH.name +DEFAULT_INPUT_DIR = \ + Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input') + +DEFAULT_OUTPUT_DIR = \ + Path(os.environ['OUTPUT_DIR'] if 'OUTPUT_DIR' in os.environ else './output') + ##################### # Parsing arguments # ##################### @@ -49,7 +55,7 @@ ) parser.add_argument( "-l", "--log-file", - default = Path("output/logs", SCRIPT_NAME).with_suffix(".log"), + default = (DEFAULT_OUTPUT_DIR / 'logs' / SCRIPT_NAME).with_suffix(".log"), help="logfile" ) parser.add_argument( @@ -64,17 +70,17 @@ ) parser.add_argument( "--publication-dir", - default = ".", + default = DEFAULT_INPUT_DIR, help="directory containing publication.cfg and the Cover.jpg" ) parser.add_argument( "-i", "--input-dir", - default = "./output/imxml", + default = DEFAULT_OUTPUT_DIR / "imxml", help="directory containing the intermediate xml generated by eoatex2imxml.py" ) parser.add_argument( "-o", "--output-dir", - default = "./output/django", + default = DEFAULT_OUTPUT_DIR / "django", help="where to dump all output files" ) diff --git a/src/imxml2epub.py b/src/imxml2epub.py index ba3fa58..5a45d0f 100755 --- a/src/imxml2epub.py +++ b/src/imxml2epub.py @@ -31,6 +31,12 @@ SCRIPT_PATH = Path( __file__ ) SCRIPT_NAME = SCRIPT_PATH.stem +DEFAULT_INPUT_DIR = \ + Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input') + +DEFAULT_OUTPUT_DIR = \ + Path(os.environ['OUTPUT_DIR'] if 'OUTPUT_DIR' in os.environ else './output') + ##################### # Parsing arguments # ##################### @@ -47,28 +53,28 @@ ) parser.add_argument( "-l", "--log-file", - default = Path( "output/logs", SCRIPT_NAME).with_suffix( ".log" ), + default = (DEFAULT_OUTPUT_DIR / "logs" / SCRIPT_NAME) . with_suffix( ".log" ), help="logfile" ) parser.add_argument( "--log-level", - default = "DEBUG", + default = "INFO", help="log level: choose between DEBUG, INFO, WARNING, ERROR, CRITICAL" ) parser.add_argument( "--publication-dir", - default = ".", + default = DEFAULT_INPUT_DIR, help="directory containing publication.cfg and the Cover.jpg" ) parser.add_argument( "-i", "--input-dir", - default = "./output/imxml", + default = DEFAULT_OUTPUT_DIR / "imxml", help="directory containing the intermediate xml generated by eoatex2imxml.py" ) parser.add_argument( "-o", "--output-dir", - default = "./output/epub", + default = DEFAULT_OUTPUT_DIR / "epub", help="where to dump all output files" )