From be47a7ca5ddf5cbe45ebea285bf14d03bc23d14e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 14 Jun 2022 10:59:25 +0200 Subject: [PATCH] Dirty fix to parse arguments both from the command line and uWSGI environment --- madblog/cli.py | 6 +++--- madblog/uwsgi.py | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/madblog/cli.py b/madblog/cli.py index 0dbf347..b1b9486 100644 --- a/madblog/cli.py +++ b/madblog/cli.py @@ -3,7 +3,7 @@ import os import sys -def get_args(): +def get_args(args): parser = argparse.ArgumentParser(description='''Serve a Markdown folder as a web blog. The folder should have the following structure: @@ -29,12 +29,12 @@ The folder should have the following structure: parser.add_argument('--debug', dest='debug', required=False, action='store_true', default=False, help='Enable debug mode (default: False)') - return parser.parse_known_args(sys.argv[1:]) + return parser.parse_known_args(args) def run(): from .config import init_config - opts, _ = get_args() + opts, _ = get_args(sys.argv[1:]) config_file = os.path.join(opts.dir, 'config.yaml') init_config(config_file=config_file, content_dir=opts.dir) diff --git a/madblog/uwsgi.py b/madblog/uwsgi.py index 74e906f..fe29e2e 100644 --- a/madblog/uwsgi.py +++ b/madblog/uwsgi.py @@ -1,9 +1,14 @@ import os +import sys from .cli import get_args from .config import init_config -opts, _ = get_args() +arg_delim_idx = [ + i for i, arg in enumerate(sys.argv) if arg == 'madblog.uwsgi' +][0] + +opts, _ = get_args(sys.argv[arg_delim_idx+1:]) config_file = os.path.join(opts.dir, 'config.yaml') init_config(config_file=config_file, content_dir=opts.dir)