-
Notifications
You must be signed in to change notification settings - Fork 20
/
job_trigger.py
49 lines (35 loc) · 1.18 KB
/
job_trigger.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
from __future__ import print_function
import glob, sys, os
pathToBuild = glob.glob('../build/lib*')
if len(pathToBuild) > 0:
versionString = "%d.%d" % (sys.version_info[0], sys.version_info[1])
for i in pathToBuild:
if versionString in i:
sys.path.insert(0, os.path.realpath(i))
pathToBuild = glob.glob('/tmp/p4python*')
if len(pathToBuild) > 0:
sys.path.insert(0, pathToBuild[0])
import P4
def run_trigger(specdef, formname, formfile):
p4 = P4.P4()
try:
p4.define_spec('job', specdef)
with open(formfile) as f:
content = f.read()
parsed = p4.parse_job(content)
parsed._status = "suspended"
content = p4.format_job(parsed)
with open(formfile, "w") as f:
f.write(content)
except Exception as e:
print("Received exception : {}".format(e))
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Usage : job_trigger.py specdef formname formfile")
sys.exit(1)
specdef = sys.argv[1]
formname = sys.argv[2]
formfile = sys.argv[3]
run_trigger(specdef, formname, formfile)