-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_spec.py
53 lines (38 loc) · 1.45 KB
/
update_spec.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
import json
import os
from mobie.migration.migrate_v2 import migrate_project
from mobie.validation.utils import validate_with_schema
def parse_menu_name(source_type, source_name):
if source_name.startswith('em'):
return 'em'
else:
return 'lm'
def update_sources(sources):
new_sources = {}
for name, source in sources.items():
source_type = list(source.keys())[0]
source = source[source_type]
storage = source.pop('imageDataLocations')
local = storage.pop('local')
storage['fileSystem'] = local
remote = storage.pop('remote', None)
if remote is not None:
storage['s3store'] = remote
source['imageDataLocations'] = storage
new_sources[name] = {source_type: source}
return new_sources
def rename_image_data_properties():
with open('./data/project.json') as f:
dsets = json.load(f)['datasets']
for dset in dsets:
source_file = os.path.join('./data', dset, 'dataset.json')
with open(source_file) as f:
ds_meta = json.load(f)
sources = update_sources(ds_meta['sources'])
ds_meta['sources'] = sources
validate_with_schema(ds_meta, 'dataset')
with open(source_file, 'w') as f:
json.dump(ds_meta, f, indent=2, sort_keys=True)
if __name__ == '__main__':
# migrate_project('./data', parse_menu_name)
rename_image_data_properties()