-
Notifications
You must be signed in to change notification settings - Fork 25
/
db_pickle2json.py
55 lines (45 loc) · 1.6 KB
/
db_pickle2json.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
from rompar import *
import rompar
# For reference
def save_grid_pickle(self, fn=None):
if not fn:
fn = self.basename + '_s%d.grid' % self.saven
symlinka(fn, self.basename + '.grid')
gridout = open(fn, 'wb')
pickle.dump((self.grid_intersections, self.Data, self.grid_points_x, self.grid_points_y, self.config), gridout)
print 'Saved %s' % fn
'''
def load_grid(self, grid_file=None, apickle=None, gui=True):
self.gui = gui
if not apickle:
with open(grid_file, 'rb') as gridfile:
apickle = pickle.load(gridfile)
self.grid_intersections, data, self.grid_points_x, self.grid_points_y, self.config = apickle
...
'''
def main():
import argparse
parser = argparse.ArgumentParser(description='Convert old DB format to new')
parser.add_argument('pickle', help='Input pickle file')
parser.add_argument('json', help='Output json file')
args = parser.parse_args()
self = rompar.Rompar()
with open(args.pickle, 'rb') as gridfile:
apickle = pickle.load(gridfile)
grid_intersections, data, grid_points_x, grid_points_y, config = apickle
configj = dict(config.__dict__)
configj['view'] = configj['view'].__dict__
j = {
'grid_intersections': grid_intersections,
'data': data,
'grid_points_x': grid_points_x,
'grid_points_y': grid_points_y,
'fn': config,
#'group_cols': group_cols,
#'group_rows': group_rows,
'config': configj,
}
rompar.load_grid(self, grid_json=j, gui=False)
rompar.save_grid(self, fn=args.json)
if __name__ == "__main__":
main()