Dirty fix to parse arguments both from the command line and uWSGI environment

This commit is contained in:
Fabio Manganiello 2022-06-14 10:59:25 +02:00
parent c39524e09b
commit be47a7ca5d
2 changed files with 9 additions and 4 deletions

View File

@ -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)

View File

@ -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)