Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add process_tei.py script, adjust some scripts where needed
  • Loading branch information
EsGeh authored and EsGeh committed Jan 7, 2020
1 parent 99107d1 commit 56a39f7
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 134 deletions.
25 changes: 4 additions & 21 deletions README.md
Expand Up @@ -93,9 +93,9 @@ In order to apply the workflow to any other publication copy it into the `runtim
$ ./scripts/run.py # run if not yet running
$ ./scripts/exec_in_container.py # enter container

1. eoatex -> pdf
1. process eoatex:

$ process_eoa_latex.py -f input/example/124_eoatex/EOASample.tex
$ process_eoa_latex.py input/example/124_eoatex

(adjust filename if necessary)

Expand All @@ -111,26 +111,9 @@ In order to apply the workflow to any other publication copy it into the `input/
$ ./scripts/run.py # run if not yet running
$ ./scripts/exec_in_container.py # enter container

1. eoaTEI -> eoaTEI with bibliography
1. process tei

$ tei_add_bibl.py input/example/125_tei_part

1. eoaTEI -> eoaTEX

$ tei2eoatex.py input/example/125_tei_part

1. eoaTEX -> pdf

$ eoatex2pdf.py -o output/125_tei_part/pdf output/125_tei_part/eoatex

1. eoaTEI -> imxml (to intermediate xml)

$ gather_pickledata.py -o output/125_tei_part/pickle output/with_bibl/125_tei_part/{tei_part_with_bibl.xml,texfiles/example.bib}
tei2imxml.py -f tei_part.xml output/with_bibl/125_tei_part

1. eoaTEI -> html

$ tei2html.py output/with_bibl/125_tei_part
$ process_tei.py input/example/125_tei_part

## The DocX workflow (DocX -> TEI -> ...) (TODO: describe how)

Expand Down
93 changes: 0 additions & 93 deletions src/gather_pickledata.py

This file was deleted.

7 changes: 0 additions & 7 deletions src/process_eoa_latex.py
Expand Up @@ -49,13 +49,6 @@ def main(
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
'''
parser.add_argument(
"-f", "--filename",
required = True,
help="Name of main EOATeX file (without suffix!)."
)
'''
parser.add_argument(
"-c", "--config",
default = BASE_DIR / "config" / "eoaconvert.cfg",
Expand Down
92 changes: 92 additions & 0 deletions src/process_tei.py
@@ -0,0 +1,92 @@
#!/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}\""
)

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 )
)
27 changes: 14 additions & 13 deletions src/tei2html.py
Expand Up @@ -70,12 +70,14 @@ def copy_dir(
default = "INFO",
help="log level: choose between DEBUG, INFO, WARNING, ERROR, CRITICAL"
)
'''
parser.add_argument(
"--root-dir",
default = DEFAULT_OUTPUT_DIR / "html_from_tei",
type = Path,
help=""
)
'''
parser.add_argument(
"-p", "--param",
action = 'append',
Expand All @@ -91,7 +93,7 @@ def copy_dir(
)
parser.add_argument(
"-f", "--filename",
default = Path("*_with_bibl.xml"),
default = Path("with_bibl.xml"),
type = Path,
help = "xml file inside PUBLICATION_DIR, or absolute path. Patterns like '*.xml' are also acceptable"
)
Expand Down Expand Up @@ -150,11 +152,20 @@ def copy_dir(
output_dir = \
args.output_dir if args.output_dir is not None else (DEFAULT_OUTPUT_DIR / publ_dir.resolve().stem) / "html"

CONFIG_FILE = args.config
if not tei_filename.is_file():
raise( Exception(
f"not a valid input file: {tei_filename}"
) )

if output_dir.exists():
if args.overwrite:
rmtree( output_dir )
else:
raise( Exception( f"output directory already existing: '{output_dir}'!" ) )

CONFIG_FILE = args.config
log_dir = output_dir / "log"
log_file = (log_dir / SCRIPT_NAME) . with_suffix( ".log" )

CONFIG = load_config(
CONFIG_FILE,
args.log_level,
Expand All @@ -163,16 +174,6 @@ def copy_dir(

logging.info( f"tei_file: {tei_filename}, publ_dir: {publ_dir}" )

if not tei_filename.is_file():
raise( Exception(
f"not a valid input file: {tei_filename}"
) )

if output_dir.exists():
if args.overwrite:
rmtree( output_dir )
else:
raise( Exception( f"output directory already existing: '{output_dir}'!" ) )
if not output_dir.exists():
mkdir( output_dir )
## copy webdesign:
Expand Down
21 changes: 21 additions & 0 deletions src/tei_add_bibl.py
Expand Up @@ -220,3 +220,24 @@ def create_bibl(
)
else:
raise( Exception("unknown publication type!"))

# create uniquely named links to
# original tei file and the one with added bibliography
orig_link = output_dir / "no_bibl.xml"
if orig_link.exists():
logging.error(
f"error while creating unique link: file already exists '{orig_link}'"
)
exit(1)
orig_link . symlink_to(
tei_file . name
)
with_bibl_link = output_dir / "with_bibl.xml"
if with_bibl_link.exists():
logging.error(
f"error while creating unique link: file already exists '{with_bibl_link}'"
)
exit(1)
with_bibl_link . symlink_to(
tei_with_bibl_file . name
)

0 comments on commit 56a39f7

Please sign in to comment.