-
Notifications
You must be signed in to change notification settings - Fork 1
/
switchboard2kinto.py
65 lines (47 loc) · 1.66 KB
/
switchboard2kinto.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
import uuid
import hashlib
import sys
import json
from kinto_http import cli_utils
DEFAULT_SERVER = "https://kinto-ota.dev.mozaws.net/v1/"
def _print(msg):
sys.stdout.write(msg)
sys.stdout.flush()
def push(client):
with open('config.json') as f:
SCHEMA_V1 = json.load(f)['collections']
with open('experiments.json') as f:
experiments = json.loads(f.read())
count = 0
client.create_collection('experiments',
data=SCHEMA_V1['experiments']['config'],
permissions={"read": ["system.Everyone"]},
safe=False)
kinto_experiments = {}
for record in list(client.get_records()):
kinto_experiments[record['name']] = record
with client.batch() as b:
for key, experiment in experiments.items():
_print('.')
experiment['name'] = key
if key in kinto_experiments:
# update
experiment['id'] = kinto_experiments[key]['id']
else:
# creation
hashed_key = hashlib.md5(key.encode('utf8')).hexdigest()
experiment['id'] = str(uuid.UUID(hashed_key))
b.update_record(experiment)
count += 1
_print('\nChanged %d records\n' % count)
def main():
parser = cli_utils.add_parser_options(
description='Upgrade the attachment structure',
default_server=DEFAULT_SERVER,
default_bucket='fennec',
default_collection='experiments')
args = parser.parse_args()
client = cli_utils.create_client_from_args(args)
push(client)
if __name__ == '__main__':
main()