-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhipchatPostCode.py
More file actions
143 lines (108 loc) · 3.87 KB
/
Copy pathhipchatPostCode.py
File metadata and controls
143 lines (108 loc) · 3.87 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from simple_worker_pip import *
import sys
import random
import string
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('config.ini')
token = config.get("IronWorker", "token" )
host = config.get("IronWorker", "host" )
port = config.get("IronWorker", "port" )
version = config.get("IronWorker", "version")
protocol = config.get("IronWorker", "protocol")
project_id = config.get("IronWorker", "defaultProjectId")
sw = SimpleWorker(host, port, version, token, protocol)
name = "hipchat-" + str(time.time())
ret = sw.postCode(project_id, name, "hipchatTask.py", "hipchatTask.zip")
print str(ret)
ret = sw.postTask(project_id, name)
print "postTask returned: " + str(ret)
task_id = ret['tasks'][0]['id']
sys.exit()
projects = sw.getProjects()
print "getProjects returns: " + str(projects)
for project in projects:
# Before deleting a project, delete all codes, tasks, schedules
project_id = project['id']
schedules = sw.getSchedules(project_id)
for schedule in schedules:
if schedule['status'] != 'cancelled':
print "deleting schedule: " + schedule['id']
sw.deleteSchedule(project_id, schedule['id'])
#tasks = sw.getTasks(project_id)
#print "tasks = " + str(tasks)
#for task in tasks:
# if task['status'] != 'cancelled':
# print "deleting task: " + task['id']
# sw.deleteTask(project_id, task['id'])
codes = sw.getCodes(project_id)
# delete the first one, do another getCodes, make sure it's not there
try:
code_id = codes[0]['id']
except:
continue
#sw.deleteCode(project_id, code_id)
codes = sw.getCodes(project_id)
for code in codes:
if (code_id == code['id']):
print "Woop! I thought I deleted this code! " + code_id
print "deleting code: " + code['id']
#sw.deleteCode(project_id, code['id'])
#sw.deleteProject(project['id'])
projectName = "pip-gen-project-" + str(int(time.time()))
newProjectID = sw.postProject(projectName)
print "newProjectID = " + str(newProjectID)
project_id = newProjectID
print "project_id = " + project_id
sw.setProject(project_id) # make this the default...
details = sw.getProjectDetails(project_id)
print "details: " + str(details)
# Make a new code (drop):
#name = "helloFromPython" + str(time.time())
#name = "helloFromPython-" + str(time.time())
s = ''.join(random.choice(string.ascii_uppercase) for x in range(10))
name = "helloFromPython" + s
print "creating code (drop) with name: " + name
ret = sw.postCode(project_id, name, "hello.py", "hello.zip")
time.sleep(1)
print "postCode returned: " + str(ret)
#sys.exit()
# For a given project_id, get list of Codes:
codes = sw.getCodes(project_id)
print "codes: " + str(codes)
for code in codes:
if code['name'] == name:
print "newly created coder: " + str(code)
code_id = code['id']
code_id = codes[-1]['id']
print "code_id = " + code_id
#sys.exit()
# get details for specific code (drop)
details = sw.getCodeDetails(code_id)
print "code details: " + str(details)
ret = sw.postTask(project_id, name)
print "postTask returned: " + str(ret)
task_id = ret['tasks'][0]['id']
try:
logstr = sw.getLog(project_id, task_id)
except urllib2.HTTPError, e:
if e.code == 404:
print "Got expected 404 when attempting to get log right away..."
else:
print "Unexpected HTTP error: " + str(e)
sys.exit()
print "About to sleep 30 to let task run..."
time.sleep(30)
logstr = sw.getLog(project_id, task_id)
print "sw.getLog returns: " + str(logstr)
sys.exit()
schedules = sw.getSchedules(project_id)
print "getSchedules returns: " + str(schedules)
for schedule in schedules:
if schedule['status'] != 'cancelled':
print schedule['id']
sw.deleteSchedule(project_id, schedule['id'])
schedule_id = sw.postSchedule(project_id, name, 10)
print "postSchedule returned: " + str(schedule_id)
schedules = sw.getSchedules(project_id)
print "getSchedules returns: " + str(schedules)