9
9
from collections import OrderedDict
10
10
11
11
12
- def create_template (schema , output_name = 'releases ' , output_format = 'all' , main_sheet_name = 'main' , flatten = False , rollup = False , root_id = 'ocid' , use_titles = False , ** _ ):
12
+ def create_template (schema , output_name = 'template ' , output_format = 'all' , main_sheet_name = 'main' , flatten = False , rollup = False , root_id = 'ocid' , use_titles = False , ** _ ):
13
13
"""
14
14
Creates template file(s) from given inputs
15
15
This function is built to deal with commandline input and arguments
16
16
but to also be called from elswhere in future
17
17
18
18
"""
19
19
20
- parser = SchemaParser (schema_filename = schema , main_sheet_name = main_sheet_name , rollup = rollup , root_id = root_id , use_titles = use_titles )
20
+ parser = SchemaParser (schema_filename = schema , rollup = rollup , root_id = root_id , use_titles = use_titles )
21
21
parser .parse ()
22
22
23
23
def spreadsheet_output (spreadsheet_output_class , name ):
@@ -38,7 +38,7 @@ def spreadsheet_output(spreadsheet_output_class, name):
38
38
raise Exception ('The requested format is not available' )
39
39
40
40
41
- def flatten (input_name , schema = None , output_name = 'releases ' , output_format = 'all' , main_sheet_name = 'main' , root_list_path = 'releases ' , rollup = False , root_id = 'ocid' , use_titles = False , ** _ ):
41
+ def flatten (input_name , schema = None , output_name = 'flattened ' , output_format = 'all' , main_sheet_name = 'main' , root_list_path = 'main ' , rollup = False , root_id = 'ocid' , use_titles = False , ** _ ):
42
42
"""
43
43
Flatten a nested structure (JSON) to a flat structure (spreadsheet - csv or xlsx).
44
44
@@ -49,16 +49,14 @@ def flatten(input_name, schema=None, output_name='releases', output_format='all'
49
49
schema_filename = schema ,
50
50
rollup = rollup ,
51
51
root_id = root_id ,
52
- use_titles = use_titles ,
53
- main_sheet_name = main_sheet_name )
52
+ use_titles = use_titles )
54
53
schema_parser .parse ()
55
54
else :
56
55
schema_parser = None
57
56
parser = JSONParser (
58
57
json_filename = input_name ,
59
58
root_list_path = root_list_path ,
60
59
schema_parser = schema_parser ,
61
- main_sheet_name = main_sheet_name ,
62
60
root_id = root_id ,
63
61
use_titles = use_titles )
64
62
parser .parse ()
@@ -102,8 +100,8 @@ def decimal_default(o):
102
100
raise TypeError (repr (o ) + " is not JSON serializable" )
103
101
104
102
105
- def unflatten (input_name , base_json = None , input_format = None , output_name = 'releases .json' ,
106
- main_sheet_name = 'releases ' , encoding = 'utf8' , timezone_name = 'UTC' ,
103
+ def unflatten (input_name , base_json = None , input_format = None , output_name = 'unflattened .json' ,
104
+ root_list_path = 'main ' , encoding = 'utf8' , timezone_name = 'UTC' ,
107
105
root_id = 'ocid' , schema = '' , convert_titles = False , cell_source_map = None ,
108
106
heading_source_map = None , ** _ ):
109
107
"""
@@ -119,11 +117,11 @@ def unflatten(input_name, base_json=None, input_format=None, output_name='releas
119
117
spreadsheet_input = spreadsheet_input_class (
120
118
input_name = input_name ,
121
119
timezone_name = timezone_name ,
122
- main_sheet_name = main_sheet_name ,
120
+ root_list_path = root_list_path ,
123
121
root_id = root_id ,
124
122
convert_titles = convert_titles )
125
123
if schema :
126
- parser = SchemaParser (schema_filename = schema , main_sheet_name = main_sheet_name , rollup = True , root_id = root_id )
124
+ parser = SchemaParser (schema_filename = schema , rollup = True , root_id = root_id )
127
125
parser .parse ()
128
126
spreadsheet_input .parser = parser
129
127
spreadsheet_input .encoding = encoding
@@ -135,7 +133,7 @@ def unflatten(input_name, base_json=None, input_format=None, output_name='releas
135
133
base = OrderedDict ()
136
134
if WITH_CELLS :
137
135
result , cell_source_map_data , heading_source_map_data = spreadsheet_input .fancy_unflatten ()
138
- base [main_sheet_name ] = list (result )
136
+ base [root_list_path ] = list (result )
139
137
with codecs .open (output_name , 'w' , encoding = 'utf-8' ) as fp :
140
138
json .dump (base , fp , indent = 4 , default = decimal_default , ensure_ascii = False )
141
139
if cell_source_map :
@@ -146,7 +144,7 @@ def unflatten(input_name, base_json=None, input_format=None, output_name='releas
146
144
json .dump (heading_source_map_data , fp , indent = 4 , default = decimal_default , ensure_ascii = False )
147
145
else :
148
146
result = spreadsheet_input .unflatten ()
149
- base [main_sheet_name ] = list (result )
147
+ base [root_list_path ] = list (result )
150
148
with codecs .open (output_name , 'w' , encoding = 'utf-8' ) as fp :
151
149
json .dump (base , fp , indent = 4 , default = decimal_default , ensure_ascii = False )
152
150
0 commit comments