From 5d87c66da702f2f8eeacdf78a273ef4581c71439 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 12 Dec 2019 12:08:04 +0100 Subject: [PATCH] Add config file --- pushee.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pushee.py b/pushee.py index 872c813..6bfc062 100644 --- a/pushee.py +++ b/pushee.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 +import json +import os +from pathlib import Path import sys @@ -18,7 +21,7 @@ COMMANDS = { def print_usage(): - print(f"{sys.argv[0]} ") + print(f"{sys.argv[0]} ") print() print("Commands:") print("\tmrs\t\t\tFetch files and create merge requests for them") @@ -26,19 +29,30 @@ def print_usage(): print("\tcomments\t\tFetch all comments on MRs") print("\tmerge\t\t\tMerge all MRs") print("\ttest\t\t\tDebugging function") - print("Format of date: %Y_%m%d_%H%M%S") + # print("Format of date: %Y_%m%d_%H%M%S") + + +def load_config(): + config_file_path = Path("~/.pushee.json").expanduser() + if not os.path.exists(config_file_path): + print("Couldn't find config file", file=sys.stderr) + exit(1) + + with open(config_file_path) as config_file: + return json.load(config_file) def main(): - if len(sys.argv) != 6 or sys.argv[5] not in COMMANDS: + config = load_config() + + if len(sys.argv) != 2 or sys.argv[1] not in COMMANDS: print_usage() exit(2) - _, path, hw, correction, deadline, command = sys.argv - correction = correction == "y" - - submissions = Parser(path, deadline, correction).parse(hw) - COMMANDS[command](submissions)() + submissions = Parser( + config["mbox_path"], config["deadline"], config["correction"] + ).parse(config["homework"]) + COMMANDS[sys.argv[1]](submissions)() if __name__ == "__main__":