#!/usr/bin/env python3 import json import os from pathlib import Path import sys from commands import MergeRequests, UpdateAssignees, Comments, Merge, Test from kontr_emails import Parser COMMANDS = { "mrs": MergeRequests, "update-assignees": UpdateAssignees, "comments": Comments, "merge": Merge, "test": Test, } def print_usage(): print(f"{sys.argv[0]} ") print() print("Commands:") print("\tmrs\t\t\tFetch files and create merge requests for them") print("\tupdate-assignees\tUpdate assignees on MRs") 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") 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(): config = load_config() if len(sys.argv) != 2 or sys.argv[1] not in COMMANDS: print_usage() exit(2) submissions = Parser( config["mbox_path"], config["deadline"], config["correction"] ).parse(config["homework"]) COMMANDS[sys.argv[1]](submissions)() if __name__ == "__main__": main()