-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_project_on_github.py
52 lines (38 loc) · 1.24 KB
/
update_project_on_github.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
import subprocess
def stage_all_and_commit(msg: str = "add new images"):
subprocess.run(["git", "add", "-A"])
subprocess.run(["git", "commit", "-m", msg])
def pull(rebase: bool = False) -> bool:
command = ["git", "pull"]
if rebase:
command.append("--rebase")
pull_process = subprocess.run(command, capture_output=True, text=True)
if pull_process.stderr:
print(pull_process.stderr)
return not pull_process.returncode
def push(remote: str = "origin", branch: str = "main"):
push_process = subprocess.run(
["git", "push", remote, branch], capture_output=True, text=True
)
if push_process.stderr:
print(push_process.stderr)
return not push_process.returncode
def sync_with_remote():
is_pulled = pull(rebase=True)
if not is_pulled:
return False
is_pushed = push()
return is_pushed
def get_args():
parser = argparse.ArgumentParser(
description="Sync MoBIE project files with GitHub. No arguments needed."
)
parser.parse_args()
def main():
stage_all_and_commit()
_ = sync_with_remote()
if __name__ == "__main__":
get_args()
# potential merge conflicts need to be solved manually on the command line
main()