diff --git a/Tst/progress_view/progress_view.py b/Tst/progress_view/progress_view.py index f17d75672abce08830bb2e46d9dd5fcd41fa9eaa..fb77b8f5c8ca18f3e5b05be64e187199d57e2b43 100644 --- a/Tst/progress_view/progress_view.py +++ b/Tst/progress_view/progress_view.py @@ -7,9 +7,13 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, Gio, GLib import sys import confignator -sys.path.append(confignator.get_option('paths', 'ccs')) + +cfg = confignator.get_config() +sys.path.append(cfg.get('paths', 'ccs')) + import ccs_function_lib as cfl cfl.add_tst_import_paths() + from testlib import analyse_command_log from testlib import analyse_verification_log from testlib import testing_logger @@ -22,7 +26,7 @@ import toolbox import generator # create a logger -log_file_path = confignator.get_option(section='progress-viewer-logging', option='log-file-path') +log_file_path = cfg.get(section='progress-viewer-logging', option='log-file-path') logger = logging.getLogger(__name__) logger.setLevel(level=logging.DEBUG) @@ -226,8 +230,8 @@ class TestProgressView(Gtk.ApplicationWindow): Gtk.StyleContext.add_class(context, 'tst-css') self.on_apply_css() self.resize( - int(confignator.get_option(section='progress-viewer-window-size', option='basic-width-step-mode')), - int(confignator.get_option(section='progress-viewer-window-size', option='basic-height'))) + int(cfg.get(section='progress-viewer-window-size', option='basic-width-step-mode')), + int(cfg.get(section='progress-viewer-window-size', option='basic-height'))) self.sort_button.set_active(True) self.show_all() logger.debug('__init__ succeeded') @@ -256,7 +260,7 @@ class TestProgressView(Gtk.ApplicationWindow): parent=self, action=Gtk.FileChooserAction.OPEN) dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK) - dialog.set_current_folder(confignator.get_option(section='progress-viewer-history', option='last-folder')) + dialog.set_current_folder(cfg.get(section='progress-viewer-history', option='last-folder')) self.add_filters(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: @@ -389,8 +393,8 @@ class TestProgressView(Gtk.ApplicationWindow): paths = {} try: current_file_name = os.path.basename(filename) - path_test_specs = confignator.get_option(section='tst-paths', option='tst_products') - path_test_runs = confignator.get_option(section='tst-logging', option='test_run') + path_test_specs = cfg.get(section='tst-paths', option='tst_products') + path_test_runs = cfg.get(section='tst-logging', option='test_run') json_file_path = os.path.join(path_test_specs, current_file_name) paths['json_file_path'] = json_file_path @@ -548,14 +552,14 @@ class TestProgressView(Gtk.ApplicationWindow): def on_remake_treeview(self, *args): if self.sort_button.get_active(): self.progress_tree_store = Gtk.TreeStore(str, str, str, str, str, str, str, str, str, str, str, str, str) - self.scroll_win.set_min_content_width(int(confignator.get_option(section='progress-viewer-window-size', option='minimum-width-run-mode'))) - if self.get_size()[0] == int(confignator.get_option(section='progress-viewer-window-size', option='basic-width-step-mode')): - self.resize(int(confignator.get_option(section='progress-viewer-window-size', option='basic-width-run-mode')), self.get_size()[1]) + self.scroll_win.set_min_content_width(int(cfg.get(section='progress-viewer-window-size', option='minimum-width-run-mode'))) + if self.get_size()[0] == int(cfg.get(section='progress-viewer-window-size', option='basic-width-step-mode')): + self.resize(int(cfg.get(section='progress-viewer-window-size', option='basic-width-run-mode')), self.get_size()[1]) else: self.progress_tree_store = Gtk.TreeStore(str, str, str, str, str, str, str, str, str, str, str) - self.scroll_win.set_min_content_width(int(confignator.get_option(section='progress-viewer-window-size', option='minimum-width-step-mode'))) - if self.get_size()[0] == int(confignator.get_option(section='progress-viewer-window-size', option='basic-width-run-mode')): - self.resize(int(confignator.get_option(section='progress-viewer-window-size', option='basic-width-step-mode')), self.get_size()[1]) + self.scroll_win.set_min_content_width(int(cfg.get(section='progress-viewer-window-size', option='minimum-width-step-mode'))) + if self.get_size()[0] == int(cfg.get(section='progress-viewer-window-size', option='basic-width-run-mode')): + self.resize(int(cfg.get(section='progress-viewer-window-size', option='basic-width-step-mode')), self.get_size()[1]) self.sorted_model = Gtk.TreeModelSort(model=self.progress_tree_store) self.sorted_model.set_sort_column_id(1, Gtk.SortType.ASCENDING) self.view.set_model(self.sorted_model) @@ -1299,7 +1303,7 @@ class Save_to_File_Dialog(Gtk.FileChooserDialog): self.win = parent self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK) - self.set_current_folder(confignator.get_option(section='tst-logging', option='output-file-path')) + self.set_current_folder(cfg.get(section='tst-logging', option='output-file-path')) #self.set_current_name('{}-IASW-{}TS-{}TR-{}'.format()) area = self.get_content_area() @@ -1314,7 +1318,7 @@ class Save_to_File_Dialog(Gtk.FileChooserDialog): # Only shown if Log File path was not given (Found from loaded log File in main window) log_file_path_label = Gtk.Label(label='Use Basic Log File Path: ') - log_file_path_label.set_tooltip_text('Basic File Path: {}'.format(confignator.get_option('tst-logging', 'test_run'))) + log_file_path_label.set_tooltip_text('Basic File Path: {}'.format(cfg.get('tst-logging', 'test_run'))) self.log_file_path_check = Gtk.CheckButton() self.log_file_path_check.set_active(True) @@ -1322,7 +1326,7 @@ class Save_to_File_Dialog(Gtk.FileChooserDialog): json_file_path_label = Gtk.Label(label='Use Basic Json File Path: ') json_file_path_label.set_tooltip_text( 'Basic File Path: {}, Also True if No Json File should be used (Specification Date in Output File will be empty)'.format( - confignator.get_option('tst-paths', 'tst_products'))) + cfg.get('tst-paths', 'tst_products'))) self.json_file_path_check = Gtk.CheckButton() self.json_file_path_check.set_active(True) @@ -1379,12 +1383,12 @@ class Save_to_File_Dialog(Gtk.FileChooserDialog): self.savedetailes.pack_end(self.test_name, False, True, 10) self.savedetailes.pack_end(name_label, False, True, 10) - area.pack_start(self.savedetailes, False, True, 0) self.show_all() return + class File_Path_Dialog(Gtk.FileChooserDialog): def __init__(self, parent=None, file=None, is_json=None): super(File_Path_Dialog, self).__init__(title='Please choose {}'.format(file), @@ -1395,9 +1399,9 @@ class File_Path_Dialog(Gtk.FileChooserDialog): self.win = parent if not is_json: - self.set_current_folder(confignator.get_option(section='tst-logging', option='test_run')) + self.set_current_folder(cfg.get(section='tst-logging', option='test_run')) else: - self.set_current_folder(confignator.get_option(section='tst-paths', option='tst_products')) + self.set_current_folder(cfg.get(section='tst-paths', option='tst_products')) if not is_json: area = self.get_content_area() @@ -1407,8 +1411,9 @@ class File_Path_Dialog(Gtk.FileChooserDialog): area.pack_start(label, False, True, 0) self.show_all() + def run(): - bus_name = confignator.get_option('dbus_names', 'progress-view') + bus_name = cfg.get('dbus_names', 'progress-view') dbus.validate_bus_name(bus_name) appli = Application(application_id=bus_name, flags=Gio.ApplicationFlags.FLAGS_NONE) diff --git a/Tst/tst/tst.py b/Tst/tst/tst.py index b253a2d4318e83f84c325d63e5da8c18844a5c6c..d2ef80d2722b720cd7ee2f69471ee57ab0ac4987 100755 --- a/Tst/tst/tst.py +++ b/Tst/tst/tst.py @@ -8,14 +8,16 @@ gi.require_version('Gtk', '3.0') gi.require_version('GtkSource', '3.0') from gi.repository import Gtk, Gdk, Gio, GtkSource, GLib, GdkPixbuf import confignator +cfg = confignator.get_config() + import sys -sys.path.append(confignator.get_option('paths', 'ccs')) +sys.path.append(cfg.get('paths', 'ccs')) import ccs_function_lib as cfl cfl.add_tst_import_paths() import view import data_model import file_management -import tst_logger +# import tst_logger import generator import codeblockreuse import connect_apps @@ -40,11 +42,11 @@ css_file = os.path.join(os.path.dirname(__file__), 'style/style.css') style_path = os.path.join(os.path.dirname(__file__), 'style') logger = logging.getLogger('tst_app_main') -log_lvl = confignator.get_option(section='tst-logging', option='level') +log_lvl = cfg.get(section='tst-logging', option='level') logger.setLevel(level=log_lvl) console_hdlr = toolbox.create_console_handler(hdlr_lvl=log_lvl) logger.addHandler(hdlr=console_hdlr) -log_file = confignator.get_option(section='tst-logging', option='log-file-path') +log_file = cfg.get(section='tst-logging', option='log-file-path') file_hdlr = toolbox.create_file_handler(file=log_file) logger.addHandler(hdlr=file_hdlr) @@ -221,7 +223,7 @@ class TstAppWindow(Gtk.ApplicationWindow): action.connect('activate', self.on_close) self.add_action(action) - show_json_view = confignator.get_bool_option('tst-preferences', 'show-json-view') + show_json_view = cfg.getboolean('tst-preferences', 'show-json-view') action = Gio.SimpleAction.new_stateful('model_viewer_toggle_hide', None, GLib.Variant.new_boolean(show_json_view)) action.connect('change-state', self.model_viewer_toggle_hide) @@ -273,7 +275,7 @@ class TstAppWindow(Gtk.ApplicationWindow): self.btn_start_ccs_editor = Gtk.ToolButton() self.btn_start_ccs_editor.set_label('Start CCS') pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( - confignator.get_option('paths', 'ccs') + '/pixmap/ccs_logo_2.svg', 28, 28) + cfg.get('paths', 'ccs') + '/pixmap/ccs_logo_2.svg', 28, 28) icon = Gtk.Image.new_from_pixbuf(pixbuf) self.btn_start_ccs_editor.set_icon_widget(icon) self.btn_start_ccs_editor.set_tooltip_text('Start CCS-Editor') @@ -312,7 +314,7 @@ class TstAppWindow(Gtk.ApplicationWindow): # logo self.unilogo = Gtk.ToolButton() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( - confignator.get_option('paths', 'ccs') + '/pixmap/Icon_Space_blau_en.png', 32, 32) + cfg.get('paths', 'ccs') + '/pixmap/Icon_Space_blau_en.png', 32, 32) icon = Gtk.Image.new_from_pixbuf(pixbuf) self.unilogo.set_icon_widget(icon) self.unilogo.connect('clicked', self.on_about) @@ -397,19 +399,19 @@ class TstAppWindow(Gtk.ApplicationWindow): # self.dev_open_example_json_file() # set the size (width and height) of the main window using the values of the configuration file - height_from_config = confignator.get_option('tst-preferences', 'main-window-height') - width_from_config = confignator.get_option('tst-preferences', 'main-window-width') + height_from_config = cfg.get('tst-preferences', 'main-window-height') + width_from_config = cfg.get('tst-preferences', 'main-window-width') if height_from_config is not None and width_from_config is not None: self.resize(int(width_from_config), int(height_from_config)) else: self.maximize() # set the position of the Paned widget using the configuration file - paned_position = confignator.get_option('tst-preferences', 'paned-position') + paned_position = cfg.get('tst-preferences', 'paned-position') if paned_position is None: paned_position = self.get_size().width * 3 / 5 self.work_desk.set_position(int(paned_position)) # # set the position of the paned of the widget self.codeblockreuse - # paned_position_cbr = confignator.get_option('tst-preferences', 'paned-position-codeblockreuse') + # paned_position_cbr = cfg.get('tst-preferences', 'paned-position-codeblockreuse') # self.codeblockreuse.set_paned_position(int(paned_position_cbr)) self.show_all() @@ -568,14 +570,14 @@ class TstAppWindow(Gtk.ApplicationWindow): Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) # using the last folder from history - last_folder = confignator.get_option('tst-history', 'last-folder') + last_folder = cfg.get('tst-history', 'last-folder') if os.path.isdir(last_folder): dialog.set_current_folder(last_folder) self.add_filters(dialog) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() - confignator.save_option('tst-history', 'last-folder', os.path.dirname(file_selected)) + cfg.save_option_to_file('tst-history', 'last-folder', os.path.dirname(file_selected)) try: json_type = True data_from_file = file_management.open_file(file_name=file_selected) @@ -636,19 +638,19 @@ class TstAppWindow(Gtk.ApplicationWindow): self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK)) - dialog.set_current_folder(confignator.get_option(section='tst-history', option='last-folder')) + dialog.set_current_folder(cfg.get(section='tst-history', option='last-folder')) dialog.set_current_name('{}-TS-{}.json'.format(current_name, current_model.spec_version)) self.add_filters(dialog) dialog.set_do_overwrite_confirmation(True) response = dialog.run() if response == Gtk.ResponseType.OK: file_selected = dialog.get_filename() - confignator.save_option('tst-history', 'last-folder', os.path.dirname(file_selected)) + cfg.save_option_to_file('tst-history', 'last-folder', os.path.dirname(file_selected)) file_management.save_file(file_path=file_selected, test_spec=current_model, file_extension='json', logger=self.logger) current_test.filename = file_selected file_name = file_selected.split('/')[-1] - #current_model.name = file_selected.split('/')[-1].split('.')[0].split('-TS-')[0] # Get only the name + # current_model.name = file_selected.split('/')[-1].split('.')[0].split('-TS-')[0] # Get only the name current_test.update_widget_data() self.notebook.set_tab_label(current_test, self.notebook_page_label(file_name)) # Update tab label self.show_all() @@ -683,13 +685,13 @@ class TstAppWindow(Gtk.ApplicationWindow): Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) # using the last folder from history - last_folder = confignator.get_option('tst-history', 'last-folder') + last_folder = cfg.get('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() if response == Gtk.ResponseType.OK: - confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) + cfg.save_option_to_file('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) @@ -763,7 +765,7 @@ class TstAppWindow(Gtk.ApplicationWindow): 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.format_secondary_text('{} at {} is unsaved'.format(filename, folder)) + # dialog.format_secondary_text('{} at {} is unsaved'.format(filename, folder)) response = dialog.run() if response == Gtk.ResponseType.YES: @@ -785,10 +787,10 @@ class TstAppWindow(Gtk.ApplicationWindow): def on_delete_event(self, *args): self.logger.info('save preferences') # saving the height and width of the main window - confignator.save_option('tst-preferences', 'main-window-height', str(self.get_size().height)) - confignator.save_option('tst-preferences', 'main-window-width', str(self.get_size().width)) + cfg.save_option_to_file('tst-preferences', 'main-window-height', str(self.get_size().height)) + cfg.save_option_to_file('tst-preferences', 'main-window-width', str(self.get_size().width)) # save the position of the paned widget - confignator.save_option('tst-preferences', 'paned-position', str(self.work_desk.get_position())) + cfg.save_option_to_file('tst-preferences', 'paned-position', str(self.work_desk.get_position())) # save the preferences of the CodeReuseFeature self.codeblockreuse.save_panes_positions() self.logger.info('Check for Unsaved Buffer') @@ -825,11 +827,11 @@ class TstAppWindow(Gtk.ApplicationWindow): model = self.current_model() if not model: logger.info('Test Files can not be generated without Steps') - print('Please add at least one test step') + logger.error('Please add at least one test step') return elif not model.name: logger.info('Test Files can not be generated if Test has no name!') - print('Please give the test a name') + logger.error('Please give the test a name') return self.product_paths = generator.make_all(model=model) # triggering the dialog after generation @@ -851,18 +853,17 @@ class TstAppWindow(Gtk.ApplicationWindow): # current_json_filename = self.current_test_instance().filename current_model = self.current_model() else: - logger.info('Small Script can not be generated without jsonfile') - print('Small Script can not be generated without json file') + logger.error('Small Script can not be generated without json file') return outfile_basic = '{}-TS-{}.py'.format(current_model.name, current_model.spec_version) dialog.set_current_name(outfile_basic) - dialog.set_current_folder(confignator.get_option('tst-history', 'last-folder')) + dialog.set_current_folder(cfg.get('tst-history', 'last-folder')) response = dialog.run() if response == Gtk.ResponseType.OK: json_to_barescript.run(current_model.encode_to_json(), dialog.get_filename()) - confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) + cfg.save_option_to_file('tst-history', 'last-folder', dialog.get_current_folder()) dialog.destroy() return @@ -884,17 +885,16 @@ class TstAppWindow(Gtk.ApplicationWindow): current_model = self.current_model() else: logger.info('CSV File can not be generated without json file') - print('CSV File can not be generated without json file') return outfile_basic = '{}-IASW-{}-TS-{}.csv_PIPE'.format(current_model.name, current_model.iasw_version, current_model.spec_version) dialog.set_current_name(outfile_basic) - dialog.set_current_folder(confignator.get_option('tst-history', 'last-folder')) + dialog.set_current_folder(cfg.get('tst-history', 'last-folder')) response = dialog.run() if response == Gtk.ResponseType.OK: json_to_csv.run(current_model.encode_to_json(), dialog.get_filename()) - confignator.save_option('tst-history', 'last-folder', dialog.get_current_folder()) + cfg.save_option_to_file('tst-history', 'last-folder', dialog.get_current_folder()) dialog.destroy() return @@ -989,13 +989,12 @@ class TstAppWindow(Gtk.ApplicationWindow): paths = {} current_instance = self.current_test_instance() if not current_instance: - self.logger.info('Progress Viewer started without running Test') - print('Progress Viewer started without running Test') + self.logger.warning('Progress Viewer started without running Test') return '' try: current_file_name = os.path.basename(current_instance.filename) - path_test_specs = confignator.get_option(section='tst-paths', option='tst_products') - path_test_runs = confignator.get_option(section='tst-logging', option='test_run') + path_test_specs = cfg.get(section='tst-paths', option='tst_products') + path_test_runs = cfg.get(section='tst-logging', option='test_run') json_file_path = os.path.join(path_test_specs, current_file_name) paths['json_file_path'] = json_file_path @@ -1007,7 +1006,7 @@ class TstAppWindow(Gtk.ApplicationWindow): vrc_log_file_path = os.path.join(path_test_runs, name + testing_logger.vrc_log_auxiliary) paths['vrc_log_file_path'] = vrc_log_file_path except Exception as e: - self.logger.info('Json or Log Files could not be found') + self.logger.warning('Json or Log Files could not be found') return '' return paths @@ -1198,7 +1197,7 @@ class ViewModelAsJson(Gtk.Box): def run(): - bus_name = confignator.get_option('dbus_names', 'tst') + bus_name = cfg.get('dbus_names', 'tst') dbus.validate_bus_name(bus_name) applica = TstApp(bus_name, Gio.ApplicationFlags.FLAGS_NONE, logger=logger)