-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_observer.py
62 lines (49 loc) · 2.19 KB
/
repo_observer.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
import argparse
import os
import socket
import subprocess
import time
import helpers
FORMAT = 'utf-8'
def poll ():
parser = argparse.ArgumentParser()
parser.add_argument("--dispatcher-server",
help="dispatcher host:port, " \
"by default it uses localhost:8888",
default="localhost:8888",
action="store")
parser.add_argument("repo",metavar="REPO",type=str,
help="path to the repository this will observe")
args = parser.parse_args()
dispatcher_host, disptacher_port = args.dispatcher_server.split(":")
while True:
try:
#run shell script update_repo.sh with repo location
subprocess.check_output(["./update_repo.sh",args.repo])
except subprocess.CalledProcessError as e:
raise Exception("Could not update and check repo. " + "Reason : %s" % e.output)
#check if commit_id was generated
if os.path.isfile(".commit_id"):
try:
#get status of dispatch server
response = helpers.communicate(dispatcher_host.encode(FORMAT),
int(disptacher_port),
"status".encode(FORMAT))
except socket.error as e:
raise Exception("Could not communicate with dispatcher server: %s" %e)
print("Notify dispatcher")
if response.decode(FORMAT) == "OK":
commit = ""
#read the commit id and send it to dispatch server
with open(".commit_id","r") as f:
commit = f.readline()
response = helpers.communicate(dispatcher_host.encode(FORMAT), int(disptacher_port),
f"dispatch:{commit}".encode(FORMAT))
if response.decode(FORMAT) != "OK":
raise Exception("Could not dispatch the test: %s" %response)
print ("Dispatched!")
else:
raise Exception("Could not dispatch tests: %s" %response)
time.sleep(50)
if __name__ == "__main__":
poll()