-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
37 lines (31 loc) · 869 Bytes
/
utils.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
def pathify(src, root="", separator="/"):
for (k, v) in src.iteritems():
topic = separator.join((root, k))
if type(v)==dict:
for i in pathify(v, topic, separator):
yield i
else:
yield (topic, v)
def changes(old, new):
old_k=set(old.keys())
new_k=set(new.keys())
_ret = {}
for k in (new_k-old_k):
_ret[k] = new[k]
for k in (old_k-new_k):
_ret[k] = None
for k in old_k.intersection(new_k):
if type(old[k])!=type(new[k]):
_ret[k] = new[k]
if type(new[k])==dict:
inner = changes(old[k], new[k])
if inner:
_ret[k] = inner
elif old[k] != new[k]:
_ret[k] = new[k]
return _ret
def merge(iterator):
tgt = {}
for i in iterator:
tgt.update(i)
return tgt