Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
EOASkripts/src/process_tei.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
98 lines (85 sloc)
2.6 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from utils.load_config import load_config, exec_command | |
# imports | |
import argparse | |
from pathlib import Path | |
import glob | |
import os | |
import subprocess | |
import shutil | |
import logging | |
BASE_DIR = Path( __file__ ).resolve().parent | |
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') | |
def main( | |
publ_dir | |
): | |
PUBL_NAME = publ_dir.resolve().stem | |
exec_command( | |
f"tei_add_bibl.py -! \"{publ_dir}\"" | |
) | |
exec_command( | |
f"tei2eoatex.py -! \"{publ_dir}\"" | |
) | |
exec_command( | |
f"eoatex2pdf.py --output-dir \"{DEFAULT_OUTPUT_DIR}/{PUBL_NAME}/pdf\" \"{DEFAULT_OUTPUT_DIR}/{PUBL_NAME}/eoatex\"" | |
) | |
exec_command( | |
f"tei_pickle.py -! \"{DEFAULT_OUTPUT_DIR}/with_bibl/{PUBL_NAME}\"" | |
) | |
exec_command( | |
f"tei2imxml.py --filename no_bibl.xml \"{DEFAULT_OUTPUT_DIR}/with_bibl/{PUBL_NAME}\"" | |
) | |
exec_command( | |
f"tei2html.py -! --filename \"with_bibl.xml\" \"{DEFAULT_OUTPUT_DIR}/with_bibl/{PUBL_NAME}\"" | |
) | |
exec_command( | |
f"imxml2django.py \"{publ_dir}\"" | |
) | |
exec_command( | |
f"imxml2epub.py \"{publ_dir}\"" | |
) | |
if __name__ == "__main__": | |
##################### | |
# Parsing arguments # | |
##################### | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
parser.add_argument( | |
"-c", "--config", | |
default = BASE_DIR / "config" / "eoaconvert.cfg", | |
dest="CONFIG_FILE", | |
help="Name of configuration file", | |
metavar="CONFIGURATION" | |
) | |
parser.add_argument( | |
"-l", "--log-file", | |
default = (DEFAULT_OUTPUT_DIR / 'logs' / SCRIPT_NAME).with_suffix(".log"), | |
help="logfile" | |
) | |
parser.add_argument( | |
"--log-level", | |
default = "INFO", | |
help="log level: choose between DEBUG, INFO, WARNING, ERROR, CRITICAL" | |
) | |
parser.add_argument( | |
"PUBLICATION_DIR", | |
help = "directory containing the publication (including resources like pictures, etc.)", | |
type = Path, | |
) | |
args = parser.parse_args() | |
CONFIG = load_config( | |
args.CONFIG_FILE, | |
args.log_level, | |
args.log_file, | |
) | |
main( | |
publ_dir = Path( args.PUBLICATION_DIR ) | |
) |