8
8
from flattentool .json_input import JSONParser
9
9
from flattentool .lib import parse_sheet_configuration
10
10
from flattentool .output import FORMATS as OUTPUT_FORMATS
11
- from flattentool .output import FORMATS_SUFFIX
11
+ from flattentool .output import FORMATS_SUFFIX , LINE_TERMINATORS
12
12
from flattentool .schema import SchemaParser
13
13
from flattentool .xml_output import toxml
14
14
@@ -24,7 +24,8 @@ def create_template(
24
24
disable_local_refs = False ,
25
25
truncation_length = 3 ,
26
26
no_deprecated_fields = False ,
27
- ** _
27
+ line_terminator = "CRLF" ,
28
+ ** _ ,
28
29
):
29
30
"""
30
31
Creates template file(s) from given inputs
@@ -33,6 +34,9 @@ def create_template(
33
34
34
35
"""
35
36
37
+ if line_terminator not in LINE_TERMINATORS .keys ():
38
+ raise Exception (f"{ line_terminator } is not a valid line terminator" )
39
+
36
40
parser = SchemaParser (
37
41
schema_filename = schema ,
38
42
rollup = rollup ,
@@ -46,7 +50,10 @@ def create_template(
46
50
47
51
def spreadsheet_output (spreadsheet_output_class , name ):
48
52
spreadsheet_output = spreadsheet_output_class (
49
- parser = parser , main_sheet_name = main_sheet_name , output_name = name
53
+ parser = parser ,
54
+ main_sheet_name = main_sheet_name ,
55
+ output_name = name ,
56
+ line_terminator = LINE_TERMINATORS [line_terminator ],
50
57
)
51
58
spreadsheet_output .write_sheets ()
52
59
@@ -87,7 +94,8 @@ def flatten(
87
94
disable_local_refs = False ,
88
95
remove_empty_schema_columns = False ,
89
96
truncation_length = 3 ,
90
- ** _
97
+ line_terminator = "CRLF" ,
98
+ ** _ ,
91
99
):
92
100
"""
93
101
Flatten a nested structure (JSON) to a flat structure (spreadsheet - csv or xlsx).
@@ -99,6 +107,9 @@ def flatten(
99
107
):
100
108
raise Exception ("You must use filter_field and filter_value together" )
101
109
110
+ if line_terminator not in LINE_TERMINATORS .keys ():
111
+ raise Exception (f"{ line_terminator } is not a valid line terminator" )
112
+
102
113
if schema :
103
114
schema_parser = SchemaParser (
104
115
schema_filename = schema ,
@@ -136,6 +147,7 @@ def spreadsheet_output(spreadsheet_output_class, name):
136
147
main_sheet_name = main_sheet_name ,
137
148
output_name = name ,
138
149
sheet_prefix = sheet_prefix ,
150
+ line_terminator = LINE_TERMINATORS [line_terminator ],
139
151
)
140
152
spreadsheet_output .write_sheets ()
141
153
@@ -206,7 +218,7 @@ def unflatten(
206
218
disable_local_refs = False ,
207
219
xml_comment = None ,
208
220
truncation_length = 3 ,
209
- ** _
221
+ ** _ ,
210
222
):
211
223
"""
212
224
Unflatten a flat structure (spreadsheet - csv or xlsx) into a nested structure (JSON).
0 commit comments