-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitp.py
55 lines (37 loc) · 963 Bytes
/
gitp.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
#!/usr/bin/python
import sys
import subprocess
import json
import string
# Gitp!
version = "0.1"
url = "https://github.com/SaguiTech/gitp/"
args = sys.argv
if len(args) < 2:
print "Gitp version "+version+" - Making git more extensible! See more at "+url
sys.exit(0)
args[0] = 'git'
gitp = json.load(open('gitp.json'))
def explode(str):
return str.split(' ')
def execute(args):
try:
print subprocess.check_output(args)
except subprocess.CalledProcessError as e:
sys.exit(e.returncode)
def runTriggers(when):
print '[Gitp] Executing triggers '+when+' "'+args[1]+'"...'
for command in gitp[args[1]][when]:
arrCommand = explode(command)
print '[Gitp] Executing command "'+arrCommand[0]+'"...'
execute(arrCommand)
if args[1] in gitp:
actions = gitp[args[1]]
if 'before' in actions:
runTriggers('before')
print '[Gitp] Executing "'+args[1]+'"...'
execute(args)
if 'after' in actions:
runTriggers('after')
else:
execute(args)