-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtojson.py
More file actions
30 lines (23 loc) · 788 Bytes
/
tojson.py
File metadata and controls
30 lines (23 loc) · 788 Bytes
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
import pickle, os, json
# get all dotfiles (which could potentially contain dumped data
dotfiles = [x for x in os.listdir('.') if x.startswith('.')]
objects = []
filenames = []
masterjson = {}
for filename in dotfiles:
try:
# try to de-pickle each dot file
with open(filename, 'rb') as file:
objects.append(pickle.load(file))
filenames.append(filename)
except:
pass
# replace it in every dotfile, and write it back out
for x in range(0, len(objects)):
object = objects[x]
filename = filenames[x]
for key in object:
if key not in masterjson:
masterjson[key] = {}
masterjson[key][filename[1:]] = object[key]
print json.dumps(masterjson, sort_keys=True, indent=4, separators=(',', ': '))