forked from usegalaxy-eu/usegalaxy-eu-tools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsync_yaml.py
59 lines (46 loc) · 1.68 KB
/
sync_yaml.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
import yaml
import sys
import argparse
import copy
import os
# Small script that syncs a yaml and yaml.lock file
lock_file = open(
"/home/padge/Elixir/galaxy-tool-development/usegalaxy-be-tools/belgium-custom.yaml.lock", "r")
lock_yaml = yaml.safe_load(lock_file)
len(lock_yaml['tools'])
l = [x['name'] for x in lock_yaml['tools']]
set([x for x in l if l.count(x) > 1])
tools_file = open(
"/home/padge/Elixir/galaxy-tool-development/usegalaxy-be-tools/belgium-custom.yaml", "r")
tools_yaml = yaml.safe_load(tools_file)
tools_yaml['tools'][0].keys()
tools_yaml.keys()
synced_tools_yaml = copy.deepcopy(tools_yaml)
unique_tools = {x['name']:x for x in tools_yaml['tools']}
updated_unique_tools = copy.deepcopy(unique_tools)
unique_lock_tools = {x['name']:x for x in lock_yaml['tools']}
i=0
j=0
for k in unique_lock_tools.keys():
if not k in unique_tools.keys():
tmp = unique_lock_tools[k]
print({key: tmp[key] for key in tmp if key != 'revisions'})
updated_unique_tools[k] = {key: tmp[key]
for key in tmp if key != 'revisions'}
# print(unique_lock_tools[k])
i+=1
else:
j+=1
print(i)
print(j)
print(len(unique_tools))
print(len(unique_lock_tools))
print(len(updated_unique_tools.values()))
synced_tools_yaml['tools'] = list(updated_unique_tools.values())
print(len(synced_tools_yaml['tools']))
{key: synced_tools_yaml[key]
for key in synced_tools_yaml if key != 'tools'}
out_file = "/home/padge/Elixir/galaxy-tool-development/usegalaxy-be-tools/tmp-belgium-custom.yaml"
with open(out_file, 'w') as outfile:
yaml.dump(synced_tools_yaml, outfile,
default_flow_style=False, explicit_start=True)