-
Notifications
You must be signed in to change notification settings - Fork 0
/
venya_android_git_commit.py
78 lines (64 loc) · 1.88 KB
/
venya_android_git_commit.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
import re
import sys
import datetime
from contextlib import contextmanager
import os
import subprocess
from subprocess import Popen, PIPE
import getopt
@contextmanager
def cd(newdir):
olddir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(olddir)
def run(cmd,*params):
if type(cmd).__name__ != "str":
print "Wrong type of command \"{}\"".format(cmd)
sys.exit(2)
command = cmd
for param in params:
if type(param).__name__ != "str":
print "Wrong type of param \"{}\"".format(param)
sys.exit(2)
command += " " + param
#openParams = ""
cmdopen = Popen(command,shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE)
output, err = cmdopen.communicate()
if re.search("git push",command) != None:
return err
if err != "":
print "!!! ERROR !!!\nCommand \"Popen({}, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)\" FAILED\n[ERROR] \"{}\"".format(repr(command),err.rstrip())
sys.exit(2)
return output.rstrip()
## VARIABLE
basedir = os.path.join("/mnt","c","Users","arturo","OneDrive","VenYa","SOURCES","Android_app")
appdir = "venya-android-app"
git = "git"
gitmessage = ""
gitrepository = "https://r2ronoha:[email protected]/r2ronoha/venya_for_android.git"
## MAIN PROGRAM
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:],"m:")
except getopt.GetoptError:
print "Failed to get program options"
sys.exit(2)
for opt,arg in opts:
if opt == '-m':
gitmessage = arg
if gitmessage == "":
now = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
gitmessage = sys.argv[0] + " " + now
#output = run("cd",basedir)
with cd(basedir):
output = run("pwd")
print "{}\n".format(output)
output = run(git,"add",appdir)
print "{}\n".format(output)
output = run("git commit -m \"{}\"".format(gitmessage))
print "{}\n".format(output)
output = run(git,"push",gitrepository,"master")
print "{}\n".format(output)