-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone-github.py
72 lines (53 loc) · 1.71 KB
/
clone-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
import os
import subprocess
import sys
def wait_for_enter():
input("Press Enter to continue...")
def run_command(command):
print(f"Running command: {command}")
try:
subprocess.run(command, check=True, shell=True)
except subprocess.CalledProcessError as e:
print(f"Error running command: {e}")
print(f"Command output: {e.output}")
class CloneGithub:
def run(self, context):
host = context.get("host")
repo_path = context.get("repo_path")
run_command("git init")
run_command(f"git clone git@{host}:{repo_path}")
wait_for_enter()
class ConfigGithubUser:
def run(self, context):
email = context.get("email")
name = context.get("name")
run_command(f"git config user.email {email}")
run_command(f"git config user.name {name}")
def get_context(context_str):
try:
return json.loads(context_str)
except json.JSONDecodeError as e:
print(f"Invalid JSON: {e}")
sys.exit(1)
def main(context_str):
context = get_context(context_str)
procedure = [CloneGithub, ConfigGithubUser]
for step in procedure:
step().run(context)
print("Done!")
if __name__ == "__main__":
if len(sys.argv) != 3:
print(
'Usage: clone-github.py <path> \'{"host": "github.com", "repo_path": "marcus.a/example.git", "email": "[email protected]", "name": "Marcus Aurelius"}\''
)
sys.exit(1)
cwd = os.getcwd()
path = sys.argv[1]
print(f"{cwd}/{path}")
try:
os.makedirs(f"{cwd}/{path}")
os.chdir(f"{cwd}/{path}")
main(sys.argv[2])
except OSError as e:
print(f"Error making or changing directory: {e}")