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/tei2html.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
103 lines (84 sloc)
2.51 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 | |
# -*- coding: utf-8; mode: python -*- | |
"A converter from TEI to HTML." | |
__version__ = "1.0" | |
__date__ = "20190408" | |
__author__ = "sgfroerer@mpiwg-berlin.mpg.de" | |
from utils.load_config import load_config, check_executable, exec_command, ToFile | |
import utils.libeoaconvert as libeoaconvert | |
import logging | |
import argparse | |
from pathlib import Path | |
# things to be done | |
# assign ids top to bottom for the following elements: | |
# div1 div2 div3 note item table EOAfigure EOAequation formula theorem | |
BASE_DIR = Path( __file__ ).resolve().parent | |
SCRIPT_NAME = Path( __file__).stem | |
def check_executables(): | |
check_executable( "saxon" ) | |
def main( | |
input_file, | |
root_dir | |
): | |
"""Main function""" | |
exec_command( | |
"saxon -t -s:{input_file} -xsl:{xslt_file} domain={root_dir}".format( | |
xslt_file = (BASE_DIR / SCRIPT_NAME) . with_suffix( ".xsl" ), | |
input_file = input_file, | |
root_dir = root_dir | |
), | |
) | |
# def main ends here | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
parser.add_argument( | |
"-c", "--config", | |
default = BASE_DIR / "config" / "eoaconvert.cfg", | |
help="Name of config file" | |
) | |
parser.add_argument( | |
"-l", "--log-file", | |
default = Path("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( | |
"--root-dir", | |
default = Path.cwd(), | |
help="internal html links on the page will use this location as a prefix" | |
) | |
parser.add_argument( | |
"-f", "--filename", | |
required = True, | |
help="Name of main EOA-TEI file" | |
) | |
''' | |
TODO: support output directory | |
parser.add_argument( | |
"-o", "--output-dir", | |
default = ".", | |
help="where to dump all output files" | |
) | |
''' | |
args = parser.parse_args() | |
CONFIG_FILE = args.config | |
print("The configfile is '%s'." % CONFIG_FILE) | |
print("The logfile is '%s'." % args.log_file) | |
CONFIG = load_config( | |
CONFIG_FILE, | |
args.log_level, | |
args.log_file, | |
) | |
check_executables() | |
# run main: | |
main( | |
input_file = args.filename, | |
root_dir = args.root_dir | |
) | |
# finis |