Add config file
This commit is contained in:
parent
0cbb641426
commit
5d87c66da7
1 changed files with 22 additions and 8 deletions
30
pushee.py
30
pushee.py
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +21,7 @@ COMMANDS = {
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print(f"{sys.argv[0]} <path_to_mbox> <homework> <correction> <deadline> <command>")
|
print(f"{sys.argv[0]} <command>")
|
||||||
print()
|
print()
|
||||||
print("Commands:")
|
print("Commands:")
|
||||||
print("\tmrs\t\t\tFetch files and create merge requests for them")
|
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("\tcomments\t\tFetch all comments on MRs")
|
||||||
print("\tmerge\t\t\tMerge all MRs")
|
print("\tmerge\t\t\tMerge all MRs")
|
||||||
print("\ttest\t\t\tDebugging function")
|
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():
|
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()
|
print_usage()
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
_, path, hw, correction, deadline, command = sys.argv
|
submissions = Parser(
|
||||||
correction = correction == "y"
|
config["mbox_path"], config["deadline"], config["correction"]
|
||||||
|
).parse(config["homework"])
|
||||||
submissions = Parser(path, deadline, correction).parse(hw)
|
COMMANDS[sys.argv[1]](submissions)()
|
||||||
COMMANDS[command](submissions)()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in a new issue