use argparse for cmdline-args

This commit is contained in:
Thor77 2015-07-17 15:08:12 +02:00
parent e3d1d7677f
commit b446abfed4
1 changed files with 9 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import re
import glob import glob
import json import json
import logging import logging
import argparse
import datetime import datetime
from os import sep from os import sep
import configparser import configparser
@ -240,10 +241,10 @@ def parse_config(config_path):
return log_path, output_path, debug, debug_file return log_path, output_path, debug, debug_file
def main(): def main(config_path='config.ini', id_map_path='id_map.json'):
# check cmdline-args # check cmdline-args
config_path = gen_abspath(argv[1] if len(argv) >= 2 else 'config.ini') config_path = gen_abspath(config_path)
id_map_path = gen_abspath(argv[2] if len(argv) >= 3 else 'id_map.json') id_map_path = gen_abspath(id_map_path)
if not exists(config_path): if not exists(config_path):
raise exceptions.ConfigNotFound(config_path) raise exceptions.ConfigNotFound(config_path)
@ -259,4 +260,8 @@ def main():
render_template(parse_logs(log_path, ident_map=id_map, file_log=debug_file), output=output_path, debug=debug) render_template(parse_logs(log_path, ident_map=id_map, file_log=debug_file), output=output_path, debug=debug)
if __name__ == '__main__': if __name__ == '__main__':
main() parser = argparse.ArgumentParser(description='A simple Teamspeak stats-generator - based on server-logs')
parser.add_argument('--config', type=str, help='path to config', default='config.ini')
parser.add_argument('--idmap', type=str, help='path to id_map', default='id_map.json')
args = parser.parse_args()
main(args.config, args.idmap)