-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygoboard.py
executable file
·82 lines (60 loc) · 2.1 KB
/
pygoboard.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
import getopt
import random
import socket
import sys
import threading
import traceback
import time
import urllib2
from parser import Parser
from say.say import Say
from static import REAL_GO, TEST_FILES
from twitter.twitter import Twitter
from weibo.weibo import WeiBo
def threadWeiBo(build_status):
WeiBo.postWeiboUpdate(build_status)
def sayThis(build_status):
Say.sayThis(build_status)
def threadSay(build_status):
sayThis(build_status)
def threadTwitter(build_status):
Twitter.postTwitterUpdate(build_status)
def createTaskThreads(build_status):
say = threading.Thread(target=threadSay, args=(build_status,))
say.start()
weibo = threading.Thread(target=threadWeiBo, args=(build_status,))
weibo.start()
twitter = threading.Thread(target=threadTwitter, args=(build_status,))
twitter.start()
def readTestData():
file_path = "test-data/%s" % random.choice(TEST_FILES)
return open(file_path).read()
def readRealData():
return urllib2.urlopen(REAL_GO).read()
def readData():
opts, args = getopt.getopt(sys.argv[1:], '')
if args.__contains__("test"):
return readTestData()
return readRealData()
if __name__ == '__main__':
try:
socket.setdefaulttimeout(5)
oldBuildVersions = {}
build_status = "off"
while True:
data = readData()
ciModel = Parser.generate_ci_model_from_xml_string(data)
go_status = ciModel.get_stage_status()
currentBuildVersions = ciModel.get_build_version()
print "*** running ***"
if not currentBuildVersions.__eq__(oldBuildVersions):
print "*** it seems that there is a new build ***"
build_status = ciModel.getBuildStatus(go_status)
print "*** it seems that current build status is %s" % build_status
createTaskThreads(build_status)
oldBuildVersions = currentBuildVersions
else:
print "*** it seems that nothing happen ***"
time.sleep(20)
except Exception, (error):
traceback.print_exc(file=sys.stdout)