-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·52 lines (45 loc) · 1.16 KB
/
update.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
#!/usr/bin/env python2
from subprocess import call
import sys
import getopt
from random import choice
import string
from os import chdir
repo = "git://github.com/alex-laties/HeroesOfNethack.git"
def main():
opts = 0
args = 0
target = '/var/www'
branch = 'master'
try:
opts, args = getopt.getopt(sys.argv[1:], "t: b:", ["target=", "branch="])
except getopt.error, msg:
print msg
sys.exit(2)
for o, a in opts:
if o in ("-t", "--target"):
target = a
elif o in ("-b, --branch"):
branch = a
if target == '':
print "no target"
sys.exit(2)
#make psuedo-random directory
temp = '/tmp/'
chars = string.letters + string.digits
for i in range(8):
temp = temp + choice(chars)
print "making temp directory " + temp
call(["mkdir", temp])
print "cloning..."
call(["git", "clone", repo, temp])
print "selecting branch"
chdir(temp)
call(["git", "checkout", branch])
print "copying..."
call(["cp", "-r" , temp + "/client/index.html", temp+"/client/css", temp+"/client/js", target])
call(["cp", "-r", temp + "/common", target])
print "removing temp..."
call(["rm", "-rf", temp])
if __name__ == "__main__":
main()