dfg_templates/DFGdocs.py

84 lines
2.8 KiB
Python
Executable File

#!/usr/bin/python3
import sys
import pathlib
import argparse
from IPython import embed
# The script should create a new DFG document from the templates
# It takes the template name and the name of the project.
# It copies over the needed files and replaces some information?
# dfg_header.tex, the main.tex, the makefile and the Logo
# renames the main file to the new name, updates the makefile
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
templates = ["project", "lebenslauf", "cv", "abschlussbericht"]
version = ["53.01 - 09/22", "53.200 - 03/23", "53.200 - 03/23", "3.06 - 01/23"]
language = ["en", "de", "en", "de"]
required_files = {"project": ["header.tex", "Makefile", "DFG_logo.png", "dfg_sachbeihilfe.tex"],
"lebenslauf": ["header.tex", "Makefile", "DFG_logo.png", "lebenslauf.tex"],
"cv": ["header.tex", "Makefile", "DFG_logo.png", "cv.tex"],
"abschlussbericht": ["header.tex", "Makefile", "DFG_logo.png", "abschlussbericht.tex"]
}
def print_templates():
print("Available templates: ")
print(f"\tname{(15*' ')}version{14*' '}language")
for t, v, l in zip(templates, version, language):
print(f"\t{t}{(20 - len(t)) * ' '}{v}{(20 - len(v)) * ' '}{l}")
def create_parser():
parser = MyParser(
description="Creates a new DFG document according to latex templates.",
prog='DFGdocs',
epilog='By Jan Grewe, 2023, Free software, absolutely no warranty!')
parser.add_argument("-l", "--list", action="store_true", help="List the available templates.")
parser.add_argument("-d", "--destination", type=str, default=".",
help="The destination folder as absolute or relative path.")
parser.add_argument("name", nargs='?', type=str, help="The project name")
parser.add_argument("template", nargs='?', type=str, help="Name of the DFG document template.")
return parser
def copy_template(args):
# assemble project name and destination
# check if destination folder exists
# if not, create
# if exists, check if empty
# if not empty refuse to work
# copy files
# change filename of main.tex
# change Makefile
pass
def main():
parser = create_parser()
args = parser.parse_args()
if args.list:
print_templates()
sys.exit(0)
if args.name is None:
print(f"Error using DFGdocs. NAME argument is not defined!")
parser.print_help()
sys.exit(2)
if args.template is None:
print(f"Error using DFGdocs. TEMPLATE argument is not defined!")
print_templates()
sys.exit(2)
copy_template(args)
if __name__ == "__main__":
main()