This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
autopuller.py
67 lines (60 loc) · 2.28 KB
/
autopuller.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
import web
import json, time, os
import threading
from apconfig import *
def worker(repo, submittime, committer):
tmp = os.popen('cd ' + repoList[repo][0] + ' && git pull').readlines()
output = open('./autopuller.log', 'a')
output.write(time.strftime("\n[%Y-%m-%d %H:%M:%S]\n",time.localtime(time.time())))
output.write("* Git returned: \n")
output.writelines(tmp)
output.write("* Repo: " + repo)
output.write("\n* Branch: " + repoList[repo][1])
output.write("\n* Dir: " + repoList[repo][0])
tmp = os.popen(repoList[repo][2]).readlines()
output.write("\n* Custom Command: \n")
output.write(repoList[repo][2] + "\n* Shell Returned: \n")
output.writelines(tmp)
output.write("- Submitted by " + committer + " at " + submittime + "\n")
output.close()
class index:
def GET(self):
return """
Service Running
Powered by Kinoware Github Autopuller.
"""
class showlogs:
def GET(self):
output = open('./autopuller.log', 'r')
tmp = output.read()
output.close()
return tmp
class service:
def POST(self):
nowthetime = time.strftime("[%Y-%m-%d %H:%M:%S]",time.localtime(time.time()))
para = web.input()
value = json.loads(para.payload)
repoName = value[u'repository'][u'name']
if value[u'ref'] == 'refs/heads/' + repoList[repoName][1]:
output = open('./autopuller.log', 'a')
output.write("\n" + nowthetime + "\n")
output.write("Repo: " + repoName)
output.write("\n* Added: \n")
output.writelines(value[u'head_commit'][u'added'])
output.write("\n* Modified: \n")
output.writelines(value[u'head_commit'][u'modified'])
output.write("\n* Removed: \n")
output.writelines(value[u'head_commit'][u'removed'])
output.write("\n- Committer " + value[u'head_commit'][u'committer'][u'email'] + "\n")
output.close()
th = threading.Thread(target=worker,args=(repoName, nowthetime, value[u'head_commit'][u'committer'][u'email']))
th.start()
return "Succeed"
return "Parameter Wrong"
urls = (
'/', 'index',
'/webhook', 'service',
'/logs','showlogs'
)
app = web.application(urls, globals())
if __name__ == "__main__": app.run()