Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
32eb1b77
Commit
32eb1b77
authored
2 years ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
replace newlines with semicolon in csv export
parent
c99d4937
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tst/json_to_csv.py
+12
-7
12 additions, 7 deletions
Tst/json_to_csv.py
with
12 additions
and
7 deletions
Tst/json_to_csv.py
+
12
−
7
View file @
32eb1b77
...
@@ -14,21 +14,23 @@ def run(jfile, outfile):
...
@@ -14,21 +14,23 @@ def run(jfile, outfile):
data
=
json
.
loads
(
jfile
)
data
=
json
.
loads
(
jfile
)
header
=
'
Item|Description|Verification|TestResult
'
header
=
'
Item|Description|Verification|TestResult
'
name
=
'
{}|{}|Test spec. version: {}| IASW-{}
'
.
format
(
data
[
'
_name
'
],
data
[
'
_description
'
],
data
[
'
_spec_version
'
],
data
[
'
_iasw_version
'
])
name
=
'
{}|{}|Test spec. version: {}| IASW-{}
'
.
format
(
data
[
'
_name
'
],
replace_newline
(
data
[
'
_description
'
]),
data
[
'
_spec_version
'
],
data
[
'
_iasw_version
'
])
# Date from last time the json file was changed + current date
# Date from last time the json file was changed + current date
date
=
'
Date||{}|
'
.
format
(
datetime
.
datetime
.
now
().
strftime
(
'
%Y-%m-%d
'
))
date
=
'
Date||{}|
'
.
format
(
datetime
.
datetime
.
now
().
strftime
(
'
%Y-%m-%d
'
))
testcomment
=
'
Comment|{}||
'
.
format
(
data
[
'
_comment
'
])
testcomment
=
'
Comment|{}||
'
.
format
(
replace_newline
(
data
[
'
_comment
'
])
)
precond
=
'
Precond.|{}||
'
.
format
(
data
[
'
_precon_descr
'
])
precond
=
'
Precond.|{}||
'
.
format
(
replace_newline
(
data
[
'
_precon_descr
'
])
)
postcond
=
'
Postcond.|{}||
'
.
format
(
data
[
'
_postcon_descr
'
])
postcond
=
'
Postcond.|{}||
'
.
format
(
replace_newline
(
data
[
'
_postcon_descr
'
])
)
steps
=
[]
steps
=
[]
for
step
in
data
[
'
sequences
'
][
0
][
'
steps
'
]:
for
step
in
data
[
'
sequences
'
][
0
][
'
steps
'
]:
line
=
'
Step {}|{}|{}|
'
.
format
(
step
[
'
_step_number
'
],
step
[
'
_description
'
],
step
[
'
_verification_description
'
])
line
=
'
Step {}|{}|{}|
'
.
format
(
step
[
'
_step_number
'
],
replace_newline
(
step
[
'
_description
'
]),
replace_newline
(
step
[
'
_verification_description
'
]))
steps
.
append
(
line
)
steps
.
append
(
line
)
if
step
[
'
_step_comment
'
]
!=
''
:
if
step
[
'
_step_comment
'
]
!=
''
:
comment
=
'
Comment|{}||
'
.
format
(
step
[
'
_step_comment
'
])
comment
=
'
Comment|{}||
'
.
format
(
replace_newline
(
step
[
'
_step_comment
'
])
)
steps
.
append
(
comment
)
steps
.
append
(
comment
)
if
outfile
[
-
1
]
==
'
/
'
:
# If only path is given but no filename
if
outfile
[
-
1
]
==
'
/
'
:
# If only path is given but no filename
...
@@ -43,6 +45,10 @@ def run(jfile, outfile):
...
@@ -43,6 +45,10 @@ def run(jfile, outfile):
fd
.
write
(
buf
)
fd
.
write
(
buf
)
def
replace_newline
(
txt
):
return
txt
.
replace
(
'
\n
'
,
'
;
'
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
json_file_path
=
sys
.
argv
[
1
]
json_file_path
=
sys
.
argv
[
1
]
...
@@ -50,6 +56,5 @@ if __name__ == '__main__':
...
@@ -50,6 +56,5 @@ if __name__ == '__main__':
outputfile
=
sys
.
argv
[
2
]
outputfile
=
sys
.
argv
[
2
]
else
:
# If no filename is given take the working directory path, filename is used from the json file
else
:
# If no filename is given take the working directory path, filename is used from the json file
outputfile
=
os
.
getcwd
()
+
'
/
'
outputfile
=
os
.
getcwd
()
+
'
/
'
# outputfile = '/'.join(json_file_path[:-len(json_file_path.split('/')[-1])-1]) + '/' # This would take the json File path
run
(
json_file_path
,
outputfile
)
run
(
json_file_path
,
outputfile
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment