-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasygit.py
106 lines (86 loc) · 3 KB
/
easygit.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import sys
import json
from easygui import enterbox,fileopenbox
EASY_GIT_CONFIG_TITLE="EasyGit Config Window"
def choose_system(field,field_type,mode,defaultval):
if defaultval is None:
defaultval=""
if field_type == 'media/text':
if mode == 'gui':
return enterbox(f"Enter {field}",EASY_GIT_CONFIG_TITLE,defaultval)
elif mode == 'cui':
return input(f"Enter {field}"+f"({defaultval}):" if len(defaultval)>0 else ":")
elif field_type == 'media/file':
if mode == 'gui':
return fileopenbox()
elif mode == 'cui':
work=f"Enter {field}"
if len(defaultval) > 0:
work+=f"({defaultval})"
return input(work+":")
def configuration_system(field,field_type,ask_mode,mode,defaultval):
if ask_mode == 'on':
return {f"{field}":choose_system(field,field_type,mode,defaultval)}
elif ask_mode == 'off':
return {f"{field}":defaultval}
easy_git_config_file=open('easygitconfig.json')
easy_git_config_data=json.load(easy_git_config_file)['EasyGitConfigData']
easy_git_config_file.close()
KEY_PATH=configuration_system(
'gpg_key_path',
easy_git_config_data['gpg_key_path']['dtype'],
easy_git_config_data['gpg_key_path']['ask'],
easy_git_config_data['gpg_key_path']['mode'],
easy_git_config_data['gpg_key_path']['value']
)['gpg_key_path']
USERNAME=configuration_system(
'user-name',
easy_git_config_data['user-name']['dtype'],
easy_git_config_data['user-name']['ask'],
easy_git_config_data['user-name']['mode'],
easy_git_config_data['user-name']['value']
)['user-name']
REPOSITORY=configuration_system(
'repository',
easy_git_config_data['repository']['dtype'],
easy_git_config_data['repository']['ask'],
easy_git_config_data['repository']['mode'],
easy_git_config_data['repository']['value']
)['repository']
gpg_key_file=open(KEY_PATH)
gpg_key_data=gpg_key_file.read()
gpg_key_file.close()
args=sys.argv
def show_list_command():
print("easygit.py --help")
print("easygit.py {push|fetch|pull}")
def show_print_help(command=None):
if command:
print(f"Invalid Command [easygit.py {command}]")
show_list_command()
else:
show_list_command()
class GitCommandError(Exception):
def __init__(self,msg):
self.msg=msg
def __str__(self):
return str(self.msg)
def fire_command(command):
ret_code=os.system(f"git {command} https://{USERNAME}:{gpg_key_data}@github.com/{USERNAME}/{REPOSITORY}.git")
if ret_code != 0:
raise GitCommandError(f"Git Command Failure Occurs while using {command}")
if len(args) < 2:
args.append(input("enter {push|fetch|pull}:"))
fire_command(args[1])
elif args[1] == "--help":
show_list_command()
elif args[1] == "push":
fire_command(args[1])
elif args[1] == "pull":
fire_command(args[1])
elif args[1] == "fetch":
fire_command(args[1])
else:
show_print_help(args[1])
input("Press enter to exit")