forked from kushaldas/autocloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_fixtures.py
66 lines (55 loc) · 2.17 KB
/
generate_fixtures.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
#!/usr/bin/env python
import os
import sys
import json
import logging
import requests
import fedmsg
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
url = 'https://apps.fedoraproject.org/datagrepper/raw'
params = {
'topic': 'org.fedoraproject.prod.buildsys.task.state.change',
'rows_per_page': 100,
}
FILEPATH = os.getcwd() + '/fixtures.json'
if not os.stat(FILEPATH).st_size == 0:
choice = int(raw_input("A fixture file with data already exists. "
"Do you want to continue? (0-Yes, 1-No)\n"))
if choice:
sys.exit(0)
with open('fixtures.json', 'w') as outfile:
counter = 1
builds = []
while True:
try:
params.update({'page': counter})
logger.debug('Sending request to datagrepper')
resp = requests.get(url, params=params)
if resp.status_code != 200:
continue
logger.debug('Fetched request from datagrepper')
results = json.loads(resp.content)
raw_messages = results.get('raw_messages')
msg_ids = []
for raw_message in raw_messages:
# This code is taken from http://git.io/vqaAQ
print '-'*50, raw_message['msg_id']
msg_info = raw_message['msg']['info']
if msg_info['method'] == 'image':
if isinstance(msg_info["children"], list):
for child in msg_info["children"]:
if child["method"] == "createImage":
if child["state"] == 2:
#fedmsg.publish(msg=raw_message['msg'], topic='buildsys.task.state.change')
json.dump(raw_message, outfile)
print raw_message['msg_id']
builds.append(child['id'])
counter += 1
except KeyboardInterrupt:
choice = int(raw_input("Enter your choice (0:continue, 1:quit)\n"))
if choice:
sys.exit(0)
else:
logger.info(builds)
print '\n'.join(msg_ids)