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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
1afe2125
Commit
1afe2125
authored
2 years ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
confirm before overwriting existing csv and py files
parent
091feee0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tst/tst/tst.py
+32
-9
32 additions, 9 deletions
Tst/tst/tst.py
with
32 additions
and
9 deletions
Tst/tst/tst.py
+
32
−
9
View file @
1afe2125
...
@@ -724,12 +724,25 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -724,12 +724,25 @@ class TstAppWindow(Gtk.ApplicationWindow):
return
return
def
existing_file_dialog
(
self
,
filepath
):
dialog
=
Gtk
.
MessageDialog
()
dialog
.
add_buttons
(
Gtk
.
STOCK_YES
,
Gtk
.
ResponseType
.
YES
,
Gtk
.
STOCK_NO
,
Gtk
.
ResponseType
.
NO
)
dialog
.
set_markup
(
'
Overwrite existing file?
'
)
dialog
.
format_secondary_text
(
'
{} already exists. Overwrite?
'
.
format
(
filepath
))
response
=
dialog
.
run
()
if
response
==
Gtk
.
ResponseType
.
YES
:
dialog
.
destroy
()
return
True
else
:
dialog
.
destroy
()
return
False
def
existing_json_warn_dialog
(
self
,
filepath
):
def
existing_json_warn_dialog
(
self
,
filepath
):
filename
=
filepath
.
split
(
'
/
'
)[
-
1
]
filename
=
filepath
.
split
(
'
/
'
)[
-
1
]
folder
=
filepath
[:
-
len
(
filename
)
-
1
]
folder
=
filepath
[:
-
len
(
filename
)
-
1
]
dialog
=
Gtk
.
MessageDialog
()
dialog
=
Gtk
.
MessageDialog
()
dialog
.
add_buttons
(
Gtk
.
STOCK_OK
,
Gtk
.
ResponseType
.
OK
)
dialog
.
add_buttons
(
Gtk
.
STOCK_OK
,
Gtk
.
ResponseType
.
OK
)
dialog
.
set_markup
(
'
CSV converted J
son F
ile already
E
xists
'
.
format
(
filename
))
dialog
.
set_markup
(
'
CSV converted J
SON f
ile already
e
xists
'
.
format
(
filename
))
dialog
.
format_secondary_text
(
'
{} at {} already exists, temporarily saved in TST
\n
Be careful during saving
'
.
format
(
filename
,
folder
))
dialog
.
format_secondary_text
(
'
{} at {} already exists, temporarily saved in TST
\n
Be careful during saving
'
.
format
(
filename
,
folder
))
dialog
.
run
()
dialog
.
run
()
dialog
.
destroy
()
dialog
.
destroy
()
...
@@ -839,10 +852,10 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -839,10 +852,10 @@ class TstAppWindow(Gtk.ApplicationWindow):
def
on_generate_barescript
(
self
,
*
args
):
def
on_generate_barescript
(
self
,
*
args
):
"""
"""
Generates a
small
python test file without all the additional stuff from on_generate_scripts
Generates a
compact
python test file without all the additional stuff from on_generate_scripts
"""
"""
dialog
=
Gtk
.
FileChooserDialog
(
dialog
=
Gtk
.
FileChooserDialog
(
title
=
"
Save
S
cript
AS
"
,
parent
=
self
,
action
=
Gtk
.
FileChooserAction
.
SAVE
)
title
=
"
Save
s
cript
as
"
,
parent
=
self
,
action
=
Gtk
.
FileChooserAction
.
SAVE
)
dialog
.
add_buttons
(
dialog
.
add_buttons
(
Gtk
.
STOCK_CANCEL
,
Gtk
.
STOCK_CANCEL
,
Gtk
.
ResponseType
.
CANCEL
,
Gtk
.
ResponseType
.
CANCEL
,
...
@@ -853,7 +866,7 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -853,7 +866,7 @@ class TstAppWindow(Gtk.ApplicationWindow):
# current_json_filename = self.current_test_instance().filename
# current_json_filename = self.current_test_instance().filename
current_model
=
self
.
current_model
()
current_model
=
self
.
current_model
()
else
:
else
:
logger
.
error
(
'
Small Script can not be generated without
json
file
'
)
logger
.
error
(
'
Small Script can not be generated without
JSON
file
'
)
return
return
outfile_basic
=
'
{}-TS-{}.py
'
.
format
(
current_model
.
name
,
current_model
.
spec_version
)
outfile_basic
=
'
{}-TS-{}.py
'
.
format
(
current_model
.
name
,
current_model
.
spec_version
)
...
@@ -861,9 +874,14 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -861,9 +874,14 @@ class TstAppWindow(Gtk.ApplicationWindow):
dialog
.
set_current_folder
(
cfg
.
get
(
'
tst-history
'
,
'
last-folder
'
))
dialog
.
set_current_folder
(
cfg
.
get
(
'
tst-history
'
,
'
last-folder
'
))
response
=
dialog
.
run
()
response
=
dialog
.
run
()
if
response
==
Gtk
.
ResponseType
.
OK
:
while
response
==
Gtk
.
ResponseType
.
OK
:
if
os
.
path
.
exists
(
dialog
.
get_filename
()):
if
not
self
.
existing_file_dialog
(
dialog
.
get_filename
()):
response
=
dialog
.
run
()
continue
json_to_barescript
.
run
(
current_model
.
encode_to_json
(),
dialog
.
get_filename
())
json_to_barescript
.
run
(
current_model
.
encode_to_json
(),
dialog
.
get_filename
())
cfg
.
save_option_to_file
(
'
tst-history
'
,
'
last-folder
'
,
dialog
.
get_current_folder
())
cfg
.
save_option_to_file
(
'
tst-history
'
,
'
last-folder
'
,
dialog
.
get_current_folder
())
break
dialog
.
destroy
()
dialog
.
destroy
()
return
return
...
@@ -873,7 +891,7 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -873,7 +891,7 @@ class TstAppWindow(Gtk.ApplicationWindow):
Generates a CSV Test Specification file
Generates a CSV Test Specification file
"""
"""
dialog
=
Gtk
.
FileChooserDialog
(
dialog
=
Gtk
.
FileChooserDialog
(
title
=
"
Save CSV
AS
"
,
parent
=
self
,
action
=
Gtk
.
FileChooserAction
.
SAVE
)
title
=
"
Save CSV
as
"
,
parent
=
self
,
action
=
Gtk
.
FileChooserAction
.
SAVE
)
dialog
.
add_buttons
(
dialog
.
add_buttons
(
Gtk
.
STOCK_CANCEL
,
Gtk
.
STOCK_CANCEL
,
Gtk
.
ResponseType
.
CANCEL
,
Gtk
.
ResponseType
.
CANCEL
,
...
@@ -884,17 +902,22 @@ class TstAppWindow(Gtk.ApplicationWindow):
...
@@ -884,17 +902,22 @@ class TstAppWindow(Gtk.ApplicationWindow):
# current_json_filename = self.current_test_instance().filename
# current_json_filename = self.current_test_instance().filename
current_model
=
self
.
current_model
()
current_model
=
self
.
current_model
()
else
:
else
:
logger
.
info
(
'
CSV File can not be generated without
json
file
'
)
logger
.
info
(
'
CSV File can not be generated without
JSON
file
'
)
return
return
outfile_basic
=
'
{}-
IASW-{}-
TS-{}.csv_PIPE
'
.
format
(
current_model
.
name
,
current_model
.
iasw_version
,
current_model
.
spec_version
)
outfile_basic
=
'
{}-TS-{}.csv_PIPE
'
.
format
(
current_model
.
name
,
current_model
.
spec_version
)
dialog
.
set_current_name
(
outfile_basic
)
dialog
.
set_current_name
(
outfile_basic
)
dialog
.
set_current_folder
(
cfg
.
get
(
'
tst-history
'
,
'
last-folder
'
))
dialog
.
set_current_folder
(
cfg
.
get
(
'
tst-history
'
,
'
last-folder
'
))
response
=
dialog
.
run
()
response
=
dialog
.
run
()
if
response
==
Gtk
.
ResponseType
.
OK
:
while
response
==
Gtk
.
ResponseType
.
OK
:
if
os
.
path
.
exists
(
dialog
.
get_filename
()):
if
not
self
.
existing_file_dialog
(
dialog
.
get_filename
()):
response
=
dialog
.
run
()
continue
json_to_csv
.
run
(
current_model
.
encode_to_json
(),
dialog
.
get_filename
())
json_to_csv
.
run
(
current_model
.
encode_to_json
(),
dialog
.
get_filename
())
cfg
.
save_option_to_file
(
'
tst-history
'
,
'
last-folder
'
,
dialog
.
get_current_folder
())
cfg
.
save_option_to_file
(
'
tst-history
'
,
'
last-folder
'
,
dialog
.
get_current_folder
())
break
dialog
.
destroy
()
dialog
.
destroy
()
return
return
...
...
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