Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplified cmd line if for scripts. logs are written to output dirs.
  • Loading branch information
EsGeh authored and EsGeh committed Dec 21, 2019
1 parent 380d7af commit 99107d1
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 294 deletions.
20 changes: 11 additions & 9 deletions README.md
Expand Up @@ -101,7 +101,7 @@ In order to apply the workflow to any other publication copy it into the `runtim

This script calls several other scripts to compile the input into several different output formats. Every script can be run seperately if needed. Just check the contents of the script for details.

## The DocX workflow (docx -> TEI -> pdf, django, epub) (TODO: complete documentation, test and fix workflow)
## The TEI workflow (TEI -> pdf, django, epub)

The following description uses the example publication in `input/example` (from the `eoa-publication-model` repository).
In order to apply the workflow to any other publication copy it into the `input/` directory and adjust paths in the description accordingly.
Expand All @@ -113,23 +113,25 @@ In order to apply the workflow to any other publication copy it into the `input/

1. eoaTEI -> eoaTEI with bibliography

$ tei_add_bibl.py -o output/125/with_bibl input/example/125_tei_part
$ tei_add_bibl.py input/example/125_tei_part

1. eoaTEI -> eoaTEX

$ tei2eoatex.py -f input/example/125_tei_part/tei_part.xml -o output/125/eoatex
$ tei2eoatex.py input/example/125_tei_part

1. eoaTEX -> pdf

$ eoatex2pdf.py -f output/125/eoatex/main.tex -o output/125/pdf

(adjust filename if necessary)
$ 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/pickle input/example/125_tei_part/*.xml input/example/125_tei_part/texfiles/example.bib
$ tei2imxml.py -f output/125/with_bibl/tei_part.xml -d output/125/pickle/data.pickle -o output/125/imxml
$ 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 -o output/125/html output/125/with_bibl
$ tei2html.py output/with_bibl/125_tei_part

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

Convert from DocX to eoaTEI, then continue with the tei workflow (adjust paths accordingly) as described above.
87 changes: 39 additions & 48 deletions src/eoatex2imxml.py
Expand Up @@ -67,40 +67,26 @@
default = BASE_DIR / "config" / "eoaconvert.cfg",
help="Name of config file"
)
parser.add_argument(
"-l", "--log-dir",
default = DEFAULT_OUTPUT_DIR / "logs",
help="logfile"
)
parser.add_argument(
"--log-level",
default = "INFO",
help="log level: choose between DEBUG, INFO, WARNING, ERROR, CRITICAL"
)
parser.add_argument(
"--tei-guidelines",
default = DEFAULT_DEPENDENCIES_DIR / "TEI",
help="path to the https://github.com/TEIC/TEI"
)
parser.add_argument(
"--tei-stylesheets",
default = DEFAULT_DEPENDENCIES_DIR / "Stylesheets",
help="path to the https://github.com/TEIC/Stylesheets"
)
parser.add_argument(
"-f", "--filename",
required = True,
help="Name of main EOATeX file (without suffix!)."
default = Path("*.tex"),
type = Path,
help = "xml file inside INPUT_DIR, or absolute path. Patterns like '*.xml' are also acceptable"
)
parser.add_argument(
"--latex-dir",
default = DEFAULT_OUTPUT_DIR / "latex",
help="directory where to find the output generated by eoatex2pdf.py"
type = Path,
help="directory where to find the output generated by eoatex2pdf.py. default: {DEFAULT_OUTPUT_DIR}/INPUT_DIR/pdf"
)
parser.add_argument(
"-o", "--output-dir",
default = DEFAULT_OUTPUT_DIR / "imxml",
help="where to dump all output files"
type = Path,
help = f"output directory. default: {DEFAULT_OUTPUT_DIR}/INPUT_DIR/imxml"
)
parser.add_argument(
"-t", "--trash",
Expand All @@ -116,6 +102,11 @@
action="store_true",
help="Embed webdesign of EOA1.0 into XML"
)
parser.add_argument(
"INPUT_DIR",
help = "directory containing the publication (including resources like pictures, etc.)",
type = Path,
)

args = parser.parse_args()

Expand All @@ -129,17 +120,6 @@
# run biber_2.1 -O biber2-1n.bbl $INPUT to obtain this file
BIBERFILE = "biber2-1.bbl"

##################################
# Reading the configuration file #
##################################

CONFIG = load_config(
CONFIG_FILE,
args.log_level,
(Path(args.log_dir) / SCRIPT_NAME) . with_suffix( ".log" ),
# args.log_file,
)

########################
# Paths to executables #
########################
Expand All @@ -150,25 +130,19 @@
# TL_PATH = CONFIG['Executables']['texlive']
# TEXBIN_PATH = CONFIG['Executables']['texbin']

############################
# Paths to auxiliary files #
############################
TRALICS_PATH_LIB = BASE_DIR / CONFIG['Auxiliaries']['TRALICS_PATH_LIB']
TEMPLATE_PATH = BASE_DIR / CONFIG['Auxiliaries']['template_path']
SUPPORT_PATH = BASE_DIR / CONFIG['Auxiliaries']['support_path']

############################
# Paths:
############################
INPUT_DIR = Path( args.filename ).resolve().parent
INPUT_PATH = Path( args.filename )
if INPUT_PATH.suffix == '':
INPUT_PATH = INPUT_PATH.with_suffix( ".tex" )
elif INPUT_PATH.suffix != ".tex":
raise( Exception( "input file matching '*.tex' expected" ) )
OUTPUT_DIR = Path( args.output_dir )
LATEX_DIR = Path ( args.latex_dir )
LOG_DIR = Path( args.log_dir )
INPUT_DIR = args.INPUT_DIR
INPUT_PATH = args.filename
INPUT_PATH = \
args.filename if args.filename . is_absolute() else list(INPUT_DIR . glob( str(args.filename) ))[0]
OUTPUT_DIR = \
args.output_dir if args.output_dir is not None else (DEFAULT_OUTPUT_DIR / INPUT_DIR.resolve().stem) / "imxml"
LATEX_DIR = \
args.latex_dir if args.latex_dir is not None else (DEFAULT_OUTPUT_DIR / INPUT_DIR.resolve().stem) / "pdf"
LOG_DIR = OUTPUT_DIR / "log"
LOG_FILE = (LOG_DIR / SCRIPT_NAME) . with_suffix( ".log" )

TEMP_DIR = OUTPUT_DIR / "tmp_files"
DEBUG_DIR = OUTPUT_DIR / "debug"
Expand All @@ -178,6 +152,23 @@

BIB2HTML_FILENAME = "temp"

##################################
# Reading the configuration file #
##################################

CONFIG = load_config(
CONFIG_FILE,
args.log_level,
LOG_FILE,
)

############################
# Paths to auxiliary files #
############################
TRALICS_PATH_LIB = BASE_DIR / CONFIG['Auxiliaries']['TRALICS_PATH_LIB']
TEMPLATE_PATH = BASE_DIR / CONFIG['Auxiliaries']['template_path']
SUPPORT_PATH = BASE_DIR / CONFIG['Auxiliaries']['support_path']


#################################################
# Checking for existance of tools and libraries #
Expand Down
38 changes: 24 additions & 14 deletions src/eoatex2pdf.py
Expand Up @@ -16,10 +16,10 @@
SCRIPT_PATH = Path( __file__ )
SCRIPT_NAME = SCRIPT_PATH.stem

INPUT_DIR = \
DEFAULT_INPUT_DIR = \
Path(os.environ['INPUT_DIR'] if 'INPUT_DIR' in os.environ else './input')

OUTPUT_DIR = \
DEFAULT_OUTPUT_DIR = \
Path(os.environ['OUTPUT_DIR'] if 'OUTPUT_DIR' in os.environ else './output')

def main(
Expand Down Expand Up @@ -110,24 +110,20 @@ def copy_bib_file():
)
parser.add_argument(
"-f", "--filename",
required = True,
help="Name of main EOATeX file without .tex extension."
default = Path("*.tex"),
type = Path,
help = "xml file inside INPUT_DIR, or absolute path. Patterns like '*.xml' are also acceptable"
)
parser.add_argument(
"-o", "--output-dir",
default = OUTPUT_DIR / "latex",
help = "output directory"
type = Path,
help = f"output directory. default: {DEFAULT_OUTPUT_DIR}/INPUT_DIR/pdf"
)
parser.add_argument(
"-c", "--config",
default = BASE_DIR / "config" / "eoaconvert.cfg",
help="Name of config file"
)
parser.add_argument(
"-l", "--log-file",
default = (OUTPUT_DIR / "logs" / SCRIPT_NAME).with_suffix(".log"),
help="logfile"
)
parser.add_argument(
"--log-level",
default = "INFO",
Expand All @@ -139,16 +135,30 @@ def copy_bib_file():
default = False,
help="Run only two passes of XeLaTeX and no biber."
)
parser.add_argument(
"INPUT_DIR",
help = "directory containing the publication (including resources like pictures, etc.)",
type = Path,
)

args = parser.parse_args()
input_dir = args.INPUT_DIR
input_file = \
args.filename if args.filename . is_absolute() else list(input_dir . glob( str(args.filename) ))[0]
# output_dir = args.output_dir
output_dir = \
args.output_dir if args.output_dir is not None else (DEFAULT_OUTPUT_DIR / input_dir.resolve().stem) / "pdf"
log_dir = output_dir / "log"
log_file = (log_dir / SCRIPT_NAME) . with_suffix( ".log" )

load_config(
args.config,
args.log_level,
args.log_file
log_file
)

main(
input_file = args.filename,
output_dir = args.output_dir,
input_file = input_file,
output_dir = output_dir,
nobiber = args.no_biber
)
2 changes: 1 addition & 1 deletion src/gather_pickledata.py
Expand Up @@ -62,7 +62,7 @@ def main(
)
parser.add_argument(
"-o", "--output-dir",
default = DEFAULT_OUTPUT_DIR / "from_tei/pickle",
required = True,
metavar = "OUTPUT_DIR",
help="output directory"
)
Expand Down
74 changes: 31 additions & 43 deletions src/imxml2django.py
Expand Up @@ -51,12 +51,8 @@
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"
metavar="CONFIGURATION",
type = Path,
)
parser.add_argument(
"--log-level",
Expand All @@ -68,38 +64,24 @@
help="Check the publication.cfg for completeness.",
action="store_true"
)
parser.add_argument(
"--publication-dir",
required = True,
# default = DEFAULT_INPUT_DIR,
help="directory containing publication.cfg and the Cover.jpg"
)
parser.add_argument(
"-i", "--input-dir",
default = DEFAULT_OUTPUT_DIR / "imxml",
help="directory containing the intermediate xml generated by eoatex2imxml.py"
help = f"directory containing some intermediate xml created by previous steps. default: {DEFAULT_OUTPUT_DIR}/PUBLICATION_NAME/imxml",
type = Path,
)
parser.add_argument(
"-o", "--output-dir",
default = DEFAULT_OUTPUT_DIR / "django",
help="where to dump all output files"
help = f"output directory. default: {DEFAULT_OUTPUT_DIR}/PUBLICATION_NAME/django",
type = Path,
)
parser.add_argument(
"PUBLICATION_DIR",
help = "directory containing the publication (including resources like pictures, etc.)",
type = Path,
)

args = parser.parse_args()

config_file = args.CONFIG_FILE

print("The configfile is %s." % config_file)

##################################
# Reading the configuration file #
##################################
CONFIG = load_config(
config_file,
args.log_level,
args.log_file,
)

########################
# Paths to executables #
########################
Expand All @@ -109,13 +91,29 @@
############################
# Paths:
############################
INPUT_DIR = Path( args.input_dir )
OUTPUT_DIR = Path( args.output_dir )
PUBLICATION_DIR = Path( args.publication_dir )
PUBLICATION_DIR = args.PUBLICATION_DIR
INPUT_DIR = \
args.input_dir if args.input_dir is not None else DEFAULT_OUTPUT_DIR / PUBLICATION_DIR.resolve().stem / "imxml"
OUTPUT_DIR = \
args.output_dir if args.output_dir is not None else (DEFAULT_OUTPUT_DIR / PUBLICATION_DIR.resolve().stem) / "django"
LOG_DIR = OUTPUT_DIR / "log"
LOG_FILE = (LOG_DIR / SCRIPT_NAME) . with_suffix( ".log" )
TEMP_DIR = OUTPUT_DIR / "tmp_files"
# CONVERT_DIR = OUTPUT_DIR / "CONVERT"
DEBUG_DIR = OUTPUT_DIR / "debug"

config_file = args.CONFIG_FILE

print("The configfile is %s." % config_file)

##################################
# Reading the configuration file #
##################################
CONFIG = load_config(
config_file,
args.log_level,
LOG_FILE,
)

############################
# Paths to auxiliary files #
############################
Expand All @@ -128,16 +126,10 @@

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

# Check for folder and necessary files
# if not os.path.exists(CONVERT_DIR):
# logging.info(f"The directory {CONVERT_DIR} has not been created yet. Creating it for you")
# time.sleep(1)
# os.makedirs(CONVERT_DIR)
logging.info(f"The publication.cfg file is missing in django directory.")
if os.path.exists(INPUT_DIR / "publication.cfg"):
shutil.copy(INPUT_DIR / "publication.cfg", OUTPUT_DIR)
Expand Down Expand Up @@ -185,10 +177,6 @@
# Convert tralics-XML to Django Data Structure #
############################################################################
""")
# Create django File Structure
# if not os.path.exists(CONVERT_DIR / "django"):
# os.mkdir(CONVERT_DIR / "django")
# os.mkdir(CONVERT_DIR / "django" / "images")
if not os.path.exists(OUTPUT_DIR / "images"):
os.mkdir(OUTPUT_DIR / "images")
if not os.path.exists(OUTPUT_DIR / "images" / "embedded"):
Expand Down

0 comments on commit 99107d1

Please sign in to comment.