Skip to content
This repository was archived by the owner on Apr 26, 2018. It is now read-only.

Commit 12a0595

Browse files
authored
Update main.py
1 parent 86760c6 commit 12a0595

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

main.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
BUILD_STATUS_SUCCESS = 0
1111
BUILD_STATUS_FAILURE = 1
1212
BUILD_STATUS_UNKNOWN = 2
13+
BUILD_ACTIVITY_SLEEPING = 0
14+
BUILD_ACTIVITY_BUILDING = 1
1315
PIN_RED = 5
1416
PIN_AMBER = 6
1517
PIN_GREEN = 16
@@ -28,8 +30,7 @@ def getBuildStatus():
2830
else:
2931
return parseResult(r.text)
3032

31-
def parseResult(text):
32-
root = etree.fromstring(text)
33+
def parseStatus(root):
3334
buildStatus = BUILD_STATUS_SUCCESS
3435
for child in root:
3536
if child.attrib['name'] not in ['Call Centre CI Build', 'Call Centre Installer Build'] :
@@ -40,28 +41,51 @@ def parseResult(text):
4041
break
4142
return buildStatus
4243

43-
def switchLights(buildStatus):
44+
def parseActivity(root):
45+
activity = BUILD_ACTIVITY_SLEEPING
46+
47+
for child in root:
48+
if child.attrib['name'] not in ['Call Centre CI Build', 'Call Centre Installer Build'] :
49+
continue
50+
activity = child.attrib['activity']
51+
if activity == 'Building':
52+
activity = BUILD_ACTIVITY_BUILDING
53+
break
54+
return activity
55+
56+
def parseResult(text):
57+
root = etree.fromstring(text)
58+
buildStatus = parseStatus(root)
59+
activity = parseActivity(root)
60+
return (buildStatus, activity)
61+
62+
def switchStatusLights(buildStatus):
4463
if buildStatus == BUILD_STATUS_SUCCESS:
4564
GPIO.output(PIN_RED, GPIO.LOW)
46-
GPIO.output(PIN_AMBER, GPIO.LOW)
4765
GPIO.output(PIN_GREEN, GPIO.HIGH)
4866
elif buildStatus == BUILD_STATUS_UNKNOWN:
49-
GPIO.output(PIN_RED, GPIO.LOW)
50-
GPIO.output(PIN_AMBER, GPIO.HIGH)
51-
GPIO.output(PIN_GREEN, GPIO.LOW)
67+
GPIO.output(PIN_RED, GPIO.HIGH)
68+
GPIO.output(PIN_GREEN, GPIO.HIGH)
5269
elif buildStatus == BUILD_STATUS_FAILURE:
5370
GPIO.output(PIN_RED, GPIO.HIGH)
54-
GPIO.output(PIN_AMBER, GPIO.LOW)
5571
GPIO.output(PIN_GREEN, GPIO.LOW)
5672

73+
def switchActivityLights(buildStatus):
74+
if buildStatus == BUILD_ACTIVITY_SLEEPING:
75+
GPIO.output(PIN_AMBER, GPIO.LOW)
76+
elif buildStatus == BUILD_ACTIVITY_BUILDING:
77+
GPIO.output(PIN_AMBER, GPIO.HIGH)
78+
5779
try:
5880
while True:
5981
try:
60-
buildStatus = getBuildStatus()
82+
(buildStatus, activity) = getBuildStatus()
6183
except:
6284
buildStatus = BUILD_STATUS_UNKNOWN
85+
activity = BUILD_ACTIVITY_SLEEPING
6386

64-
switchLights(buildStatus)
87+
switchStatusLights(buildStatus)
88+
switchActivityLights(activity)
6589

6690
time.sleep(1)
6791

0 commit comments

Comments
 (0)