diff --git a/Tst/json_to_barescript.py b/Tst/json_to_barescript.py index 7ca49e2a6bc9bb08a575589fc40c4a6cb25d7179..9ef58a79b86c2e86b44a4978fc0c6fc55a2e1a61 100755 --- a/Tst/json_to_barescript.py +++ b/Tst/json_to_barescript.py @@ -15,7 +15,12 @@ import sys def run(jfile, outfile): - data = json.load(open(jfile, 'r')) + + if os.path.isfile(jfile): + data = json.load(open(jfile, 'r')) + else: + data = json.loads(jfile) + date = datetime.datetime.now().strftime('%Y-%m-%d') script = '' @@ -24,7 +29,7 @@ def run(jfile, outfile): script += '# ' + data['_name'] + '\n' script += '# ' + data['_description'] + '\n' script += '# Specification Version: ' + data['_spec_version'] + '\n' - script += '# Software Version: ' + data['sw_version'] + '\n' + script += '# Software Version: ' + data['_iasw_version'] + '\n' script += '# Author: UVIE\n# Date: {}\n'.format(date) script += '#--------------------------------------------\n\n\n' diff --git a/Tst/json_to_csv.py b/Tst/json_to_csv.py index 3243f6858b11e31ed819063e6231c3204fbe7fbf..57723b8f5d3d9f7779b3f01973f54b3318b23758 100755 --- a/Tst/json_to_csv.py +++ b/Tst/json_to_csv.py @@ -5,14 +5,18 @@ import json import os import sys + def run(jfile, outfile): - data = json.load(open(jfile, 'r')) + if os.path.isfile(jfile): + data = json.load(open(jfile, 'r')) + else: + data = json.loads(jfile) header = 'Item|Description|Verification|TestResult' - name = '{}|{}|Test spec. version: {}| IASW-{}'.format(data['_name'], data['_description'], data['_spec_version'], data['_sw_version']) + name = '{}|{}|Test spec. version: {}| IASW-{}'.format(data['_name'], data['_description'], data['_spec_version'], data['_iasw_version']) # Date from last time the json file was changed + current date - date = 'Date||{}|{}'.format(datetime.datetime.strftime(datetime.datetime.fromtimestamp(os.stat(jfile).st_mtime), '%Y-%m-%d'), datetime.datetime.now().strftime('%Y-%m-%d')) + date = 'Date||{}|'.format(datetime.datetime.now().strftime('%Y-%m-%d')) precond = 'Precond.|{}||'.format(data['_precon_descr']) postcond = 'Postcond.|{}||'.format(data['_postcon_descr']) steps = [] diff --git a/Tst/spec_to_json.py b/Tst/spec_to_json.py index 5b8aaf3776b979d0eccd30bc2582fddbb4ef4e4d..da02255774b39b631e936a8d0603905e85b51693 100755 --- a/Tst/spec_to_json.py +++ b/Tst/spec_to_json.py @@ -12,14 +12,14 @@ def run(specfile, gen_cmd, save_json): jspec = tmp.copy() specs = open(specfile, 'r').read().split('\n') - name, descr, spec_version_entry, sw_version_entry = specs[1].split('|') - spec_version = spec_version_entry.split('version: ')[-1] - sw_version = sw_version_entry.split('IASW-')[-1] + name, descr, spec_version_entry, _ = specs[1].split('|') + spec_version = spec_version_entry.split(': ')[-1] + sw_version = spec_version_entry.split('-')[1] jspec['_name'] = name - jspec['_description'] = descr + jspec['_description'] = descr.replace('\\_', '_') jspec['_spec_version'] = spec_version - jspec['_sw_version'] = sw_version + jspec['_iasw_version'] = sw_version jspec['_primary_counter_locked'] = False steps = jspec['sequences'][0]['steps'] @@ -28,6 +28,9 @@ def run(specfile, gen_cmd, save_json): for step in specs[4:]: + # remove tex escape sequences + step = step.replace('\\_', '_') + if step.count('|') != 3: continue @@ -37,14 +40,22 @@ def run(specfile, gen_cmd, save_json): continue if n.lower() == 'comment': - step = steps[-1] - step['_step_comment'] = descr + if len(steps) == 0: + jspec['_comment'] = descr + else: + step = steps[-1] + step['_step_comment'] = descr continue step_num = n.replace('Step ', '') step_temp['_step_number'] = step_num - step_temp['_primary_counter'] = int(step_num.split('.')[0]) - step_temp['_secondary_counter'] = int(step_num.split('.')[1]) + try: + c1, c2 = map(int, step_num.split('.')) + except ValueError: + c1 = int(step_num) + c2 = 0 + step_temp['_primary_counter'] = c1 + step_temp['_secondary_counter'] = c2 step_temp['_description'] = descr step_temp['_verification_description'] = ver @@ -76,7 +87,7 @@ def run(specfile, gen_cmd, save_json): if save_json: json.dump(jspec, open(specfile + '.json', 'w'), indent=4) else: - json_data = json.dumps(jspec) + # json_data = json.dumps(jspec) return jspec diff --git a/Tst/tst/app_menu.xml b/Tst/tst/app_menu.xml index 08ea8b222590c77b77d7c593f89aeea5bc5c679c..db4430cda43cef0e45de5b163370e3fb6d4efb5a 100644 --- a/Tst/tst/app_menu.xml +++ b/Tst/tst/app_menu.xml @@ -22,7 +22,7 @@ <attribute name="action">win.save_as</attribute> </item> <item> - <attribute name="label" translatable="yes">CSV to Json</attribute> + <attribute name="label" translatable="yes">Import CSV</attribute> <attribute name="action">win.csv_to_json</attribute> </item> <item> @@ -79,11 +79,11 @@ <attribute name="action">win.generate_scripts</attribute> </item> <item> - <attribute name="label" translatable="yes">Generate Small Script</attribute> + <attribute name="label" translatable="yes">Export to compact script</attribute> <attribute name="action">win.generate_barescript</attribute> </item> <item> - <attribute name="label" translatable="yes">Generate CSV File</attribute> + <attribute name="label" translatable="yes">Export to CSV</attribute> <attribute name="action">win.generate_csv</attribute> </item> </section> diff --git a/Tst/tst/tst.py b/Tst/tst/tst.py index 42be742bc957b2f5b26ccff8f07a910b3c2779fc..86bcb9a0efff020a7f795f826101cb1259cbeddb 100755 --- a/Tst/tst/tst.py +++ b/Tst/tst/tst.py @@ -280,6 +280,7 @@ class TstAppWindow(Gtk.ApplicationWindow): # add the notebook for the test specifications self.notebook = Gtk.Notebook() + self.notebook.connect('switch-page', self.update_model_viewer) self.work_desk.pack1(self.notebook) self.feature_area = Gtk.Notebook() @@ -452,10 +453,16 @@ class TstAppWindow(Gtk.ApplicationWindow): raise Exception return current_model - def update_model_viewer(self): + def update_model_viewer(self, *args): """ Gets the data of the model and makes a JSON string out of it. Intended to display the model data as plain JSON """ + if len(args) == 3: + nb, _, n = args + tab = nb.get_nth_page(n) + self.json_view.update(tab.model) + return + current_model = self.current_model() self.json_view.update(current_model) @@ -600,7 +607,7 @@ class TstAppWindow(Gtk.ApplicationWindow): return False def add_filters(self, dialog, filter_json=True): - if json: + if filter_json: filter_text = Gtk.FileFilter() filter_text.set_name('JSON format') filter_text.add_mime_type('application/json') @@ -627,15 +634,15 @@ class TstAppWindow(Gtk.ApplicationWindow): last_folder = confignator.get_option('tst-history', 'last-folder') if os.path.isdir(last_folder): dialog.set_current_folder(last_folder) + # self.add_filters(dialog, filter_json=False) response = dialog.run() - self.add_filter_csv(dialog, filter_json=False) if response == Gtk.ResponseType.OK: confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) file_selected = dialog.get_filename() filename = file_selected.replace('.' + file_selected.split('.')[-1], '.json') data_from_file = spec_to_json.run(specfile=file_selected, gen_cmd=True, save_json=False) self.on_open_create_tab(data_from_file, filename, json_type=False) - self.on_open_create_tab(data_from_file, filename, json_type=False) + # self.on_open_create_tab(data_from_file, filename, json_type=False) dialog.destroy() self.save_as_file_dialog() @@ -703,7 +710,7 @@ class TstAppWindow(Gtk.ApplicationWindow): filename = 'New Test' dialog = Gtk.MessageDialog() dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO, Gtk.ResponseType.NO) - dialog.set_markup('Unsaved File {}, Save?'.format(filename)) + dialog.set_markup('Unsaved file {}, save?'.format(filename)) #dialog.format_secondary_text('{} at {} is unsaved'.format(filename, folder)) response = dialog.run() @@ -778,7 +785,7 @@ class TstAppWindow(Gtk.ApplicationWindow): def on_generate_barescript(self, *args): """ - Generates a small python test file without all the additional staff from on_generate_scripts + Generates a small python test file without all the additional stuff from on_generate_scripts """ dialog = Gtk.FileChooserDialog( title="Save Script AS", parent=self, action=Gtk.FileChooserAction.SAVE) @@ -789,7 +796,7 @@ class TstAppWindow(Gtk.ApplicationWindow): Gtk.ResponseType.OK, ) if self.current_test_instance(): - current_json_filename = self.current_test_instance().filename + # current_json_filename = self.current_test_instance().filename current_model = self.current_model() else: logger.info('Small Script can not be generated without jsonfile') @@ -802,7 +809,7 @@ class TstAppWindow(Gtk.ApplicationWindow): response = dialog.run() if response == Gtk.ResponseType.OK: - json_to_barescript.run(current_json_filename, dialog.get_filename()) + json_to_barescript.run(current_model.encode_to_json(), dialog.get_filename()) confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) dialog.destroy() @@ -821,7 +828,7 @@ class TstAppWindow(Gtk.ApplicationWindow): Gtk.ResponseType.OK, ) if self.current_test_instance(): - current_json_filename = self.current_test_instance().filename + # current_json_filename = self.current_test_instance().filename current_model = self.current_model() else: logger.info('CSV File can not be generated without json file') @@ -834,7 +841,7 @@ class TstAppWindow(Gtk.ApplicationWindow): response = dialog.run() if response == Gtk.ResponseType.OK: - json_to_csv.run(current_json_filename, dialog.get_filename()) + json_to_csv.run(current_model.encode_to_json(), dialog.get_filename()) confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) dialog.destroy() @@ -1001,34 +1008,25 @@ class ViewModelAsJson(Gtk.Box): super().__init__(*args, **kwargs) self.set_orientation(Gtk.Orientation.VERTICAL) - # toolbar - self.btn_show_options = Gtk.ToolButton() - self.btn_show_options.set_icon_name('applications-system-symbolic') - self.btn_show_options.connect('clicked', self.options_toggle_hide) - self.toolbar = Gtk.Toolbar() - self.toolbar.insert(self.btn_show_options, 0) - self.pack_start(self.toolbar, False, True, 0) - # options area self.box_h = Gtk.Box.new(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) - self.chooser_label = Gtk.Label.new() - self.chooser_label.set_text('Select code style scheme:') - self.button_accept = Gtk.Button.new() - self.button_accept.set_label('Apply new scheme') - self.button_accept.connect('clicked', self.on_button_accept_clicked) self.style_manager = GtkSource.StyleSchemeManager.get_default() self.style_manager.append_search_path(style_path) self.chooser_button = GtkSource.StyleSchemeChooserButton() self.chooser_button.set_style_scheme(self.style_manager.get_scheme('darcula')) + self.chooser_button.connect('notify', self._update_style) + img = Gtk.Image.new_from_icon_name('applications-system-symbolic', Gtk.IconSize.BUTTON) + self.chooser_button.set_image(img) + self.chooser_button.set_label('') self.current_scheme = self.chooser_button.get_style_scheme() - self.box_h.pack_end(self.button_accept, True, True, 0) - self.box_h.pack_end(self.chooser_button, True, True, 0) - self.box_h.pack_end(self.chooser_label, True, True, 0) + self.chooser_button.set_tooltip_text('style: ' + self.current_scheme.get_name()) + self.box_h.pack_end(self.chooser_button, False, False, 0) self.pack_start(self.box_h, False, True, 0) # the view of the json self.scrolled_window = Gtk.ScrolledWindow() self.model_viewer = GtkSource.View() + self.model_viewer.set_editable(False) self.model_viewer_buffer = self.model_viewer.get_buffer() self.lm = GtkSource.LanguageManager() self.model_viewer_buffer.set_language(self.lm.get_language('json')) @@ -1036,6 +1034,13 @@ class ViewModelAsJson(Gtk.Box): self.scrolled_window.add(self.model_viewer) self.pack_start(self.scrolled_window, True, True, 0) + def _update_style(self, widget, spec): + if spec.name == 'style-scheme': + self.current_scheme = self.chooser_button.get_style_scheme() + self.model_viewer_buffer.set_style_scheme(self.current_scheme) + self.chooser_button.set_label('') + self.chooser_button.set_tooltip_text('style: ' + self.current_scheme.get_name()) + def options_toggle_hide(self, button): visible = self.box_h.is_visible() if visible: @@ -1043,10 +1048,6 @@ class ViewModelAsJson(Gtk.Box): else: self.box_h.show() - def on_button_accept_clicked(self, *args): - self.current_scheme = self.chooser_button.get_style_scheme() - self.model_viewer_buffer.set_style_scheme(self.current_scheme) - def update(self, model): """ Gets the data of the model and makes a JSON string out of it. Intended to display the model data as plain JSON diff --git a/Tst/tst/view.py b/Tst/tst/view.py index ae636b3920c79b9e31c662012384415679f8bac1..58905d2b841121b440468185aa3073fd2f0d82cc 100644 --- a/Tst/tst/view.py +++ b/Tst/tst/view.py @@ -928,7 +928,7 @@ class StepWidget(Gtk.EventBox): def set_data_in_widget(self): self.set_is_active_in_widget() self.set_description_in_widget() - self.set_commands_in_widget()# + self.set_commands_in_widget() self.set_step_comment_in_widget() self.set_verification_in_widget() self.set_verification_description_in_widget()