From e8d1ed4ba1a9fac0b1972565329629ce0b4c0fbb Mon Sep 17 00:00:00 2001 From: Jake <j.vondoemming@stud.uni-goettingen.de> Date: Thu, 1 Sep 2022 15:33:03 +0200 Subject: [PATCH] use commandline arguments --- Makefile | 2 +- fgs/__main__.py | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 71ecb48..f396ec0 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ publish: build .PHONY: build build: mathjax - cd fgs && python3 __main__.py + cd fgs && python3 __main__.py "../content" "../output" "../theme" "../config.json" "../lang.json" .PHONY: mathjax mathjax: diff --git a/fgs/__main__.py b/fgs/__main__.py index fc870f0..0a14ceb 100644 --- a/fgs/__main__.py +++ b/fgs/__main__.py @@ -12,21 +12,23 @@ import reader import generator import writer -CONTENT_DIR = '../content' -OUTPUT_DIR = '../output' -THEME_DIR = '../theme' +#content_dir = '../content' +#output_dir = '../output' +#theme_dir = '../theme' +#config_file = '../config.json' +#lang_file = '../lang.json' -def main(): +def main(content_dir, output_dir, theme_dir, config_file, lang_file): print("Hello World") config = {} - with open('../config.json') as f: + with open(config_file) as f: config = common.combine(config, json.loads(f.read())) - with open('../lang.json') as f: + with open(lang_file) as f: if 'lang' not in config: config['lang'] = {} config['lang'] = common.combine(config['lang'], json.loads(f.read())) - with open(CONTENT_DIR + '/config.json') as f: + with open(content_dir + '/config.json') as f: config = common.combine(config, json.loads(f.read())) print(config) @@ -49,15 +51,15 @@ def main(): extensions = mimeconfig['extensions'] readers.append(reader.PandocReader(config, factories, mimetype, None, base=mimeconfig['base'], extensions=extensions)) - read_dir(os.path.join(CONTENT_DIR, "."), readers) - read_dir(THEME_DIR + '/static', readers, [config['theme']['static_dir']]) + read_dir(os.path.join(content_dir, "."), readers) + read_dir(theme_dir + '/static', readers, [config['theme']['static_dir']]) context = {} gen = generator.Generator(config, context, factories) gen.generate_context() - wrt = writer.Writer(config, context, OUTPUT_DIR, THEME_DIR) + wrt = writer.Writer(config, context, output_dir, theme_dir) gen.generate_output(wrt) @@ -91,5 +93,9 @@ def read_dir(directory, readers, subpath = []): if __name__ == '__main__': - main() + argv = sys.argv + if len(argv) != 6: + print("Usage:",argv[0],"<content_dir> <output_dir> <theme_dir> <config_file> <lang_file>") + os._exit(1) + main(argv[1], argv[2], argv[3], argv[4], argv[5]) -- GitLab