def __init__(self): # load config cfg.init(None) # main window self._app = QtWidgets.QApplication(sys.argv) #print("Model app: ", str(self._app)) self._app.setWindowIcon(icon.get_app_icon("me-geomap")) self.mainwindow = MainWindow(self) cfg.main_window = self.mainwindow # set default values self._update_document_name() # show self.mainwindow.show() self.autosave = Autosave(cfg.config.CONFIG_DIR, lambda: cfg.curr_file, self.mainwindow.editor.text) """Object handling automatic saving""" self._restore_backup() if len(cfg.document) > 0: self.mainwindow.reload() self.mainwindow.editor.textChanged.connect(self.autosave.start_autosave) self.reloader_timer = QtCore.QTimer() """timer for file time checking in ms""" self.reloader_timer.timeout.connect(self.check_file) self.reloader_timer.start(RELOAD_INTERVAL)
def main(): """Launches the export cli.""" parser = argparse.ArgumentParser( description='Export the YAML configuration file to CON format') parser.add_argument( '--destination-file', nargs='?', default=None, help='The destination file if is different from source file') parser.add_argument('--yaml_file', help='YAML input file', required=True) args = parser.parse_args() if args.destination_file: file = args.destination_file else: file = os.path.splitext( args.yaml_file)[0] + '.con' # replace extension if os.path.isfile(file): raise Exception("File already exists") cfg.init(None) if cfg.open_file(args.yaml_file): con_text = cfg.export_file() file_d = open(file, 'w') file_d.write(con_text) file_d.close()
def main(): """Launches the import cli.""" parser = argparse.ArgumentParser( description='Import the YAML configuration file from CON format') parser.add_argument('--transformation-name', nargs='*', help='Transformation rules contained in the Model Editor that are ' 'processed after import') parser.add_argument('--destination-file', nargs='?', default=None, help='The destination file if is different from source file') parser.add_argument('--con_file', help='CON input file', required=True) args = parser.parse_args() if args.destination_file: file = args.destination_file else: file = os.path.splitext(args.con_file)[0] + '.yaml' # replace extension if os.path.isfile(file): raise Exception("File already exists") cfg.init(None) cfg.set_current_format_file("1.8.3") cfg.import_file(args.con_file) if args.transformation_name is not None: for transf in args.transformation_name: cfg.transform_con(transf) file_d = open(file, 'w') file_d.write(cfg.document) file_d.close()
def test_meconfig_static(request): Config.SERIAL_FILE = "ModelEditorData_test" cfg.init(None) # cfg.config is assigned assert cfg.config.__class__ == Config def fin_test_config(): import gm_base.config gm_base.config.delete_config_file("ModelEditorData_test") request.addfinalizer(fin_test_config) cfg.format_files = [] cfg._read_format_files() # read format files assert '1.8.3' in cfg.format_files cfg.curr_format_file = None cfg.set_current_format_file('1.8.3') # good name assert cfg.curr_format_file == '1.8.3' cfg.set_current_format_file('bad_name') # bad name assert cfg.curr_format_file == '1.8.3' cfg.document = "#test" cfg.changed = True cfg.curr_file = "test" cfg.new_file() # new file test assert cfg.document == "" assert cfg.changed is False assert cfg.curr_file is None cfg.document = "#test" cfg.changed = True cfg.curr_file = "test.yaml" cfg.config.add_recent_file("test.yaml", "1.8.3") cfg.save_file() def fin_test_static(): import os if os.path.isfile("test.yaml"): os.remove("test.yaml") if os.path.isfile("test2.yaml"): os.remove("test2.yaml") request.addfinalizer(fin_test_static) # save file test assert cfg.changed is False assert cfg.curr_file == "test.yaml" assert cfg.config.recent_files[0] == "test.yaml" assert cfg.config.format_files[0] == "1.8.3" cfg.document = "#test2" cfg.changed = True cfg.save_as("test2.yaml") # save us test assert cfg.changed is False assert cfg.curr_file == "test2.yaml" assert cfg.config.recent_files[0] == "test2.yaml" assert cfg.config.format_files[0] == "1.8.3" assert cfg.config.recent_files[1] == "test.yaml" assert cfg.config.format_files[1] == "1.8.3" cfg.document = "#test2" cfg.changed = True cfg.set_current_format_file('1.8.3') cfg.open_file("test.yaml") # open file test assert cfg.changed is False assert cfg.curr_file == "test.yaml" assert cfg.document == "#test" assert cfg.config.recent_files[1] == "test2.yaml" assert cfg.config.format_files[1] == "1.8.3" assert cfg.config.recent_files[0] == "test.yaml" assert cfg.config.format_files[0] == "1.8.3" assert cfg.curr_format_file == '1.8.3' cfg.document = "" cfg.changed = True cfg.set_current_format_file('1.8.3') cfg.open_recent_file("test2.yaml") # open recent file test assert cfg.changed is False assert cfg.curr_file == "test2.yaml" assert cfg.document == "#test2" assert cfg.config.recent_files[0] == "test2.yaml" assert cfg.config.format_files[0] == "1.8.3" assert cfg.config.recent_files[1] == "test.yaml" assert cfg.config.format_files[1] == "1.8.3" assert cfg.curr_format_file == '1.8.3' cfg.update_yaml_file("#new test") # test update_yaml_file 1 assert cfg.changed == True assert cfg.document == "#new test" cfg.changed = False cfg.update_yaml_file("#new test") # test update_yaml_file 2 assert cfg.changed is False assert cfg.document == "#new test" # test document parsing cfg.document = "n: 1" cfg.update() assert cfg.root.children[0].value == 1
def test_config(request): Config.SERIAL_FILE = "ModelEditorData_test" cfg.init(None) cfg.config = Config() # cfg.config is assigned assert cfg.config.__class__ == Config def fin_test_config(): import gm_base.config gm_base.config.delete_config_file("ModelEditorData_test") request.addfinalizer(fin_test_config) import os cwd = os.getcwd() # current_working_dir for first opened config is cwd assert cwd == cfg.config.current_working_dir config = Config() # new config have current_working_dir == cwd assert cwd == config.current_working_dir cfg.config.add_recent_file("test_file1", "test_format_file1") # add first file assert cfg.config.recent_files[0] == "test_file1" assert cfg.config.format_files[0] == "test_format_file1" cfg.config.add_recent_file("test_file1", "test_format_file_new_1") # change only format assert cfg.config.format_files[0] == "test_format_file_new_1" assert len(cfg.config.format_files) == 1 cfg.config.add_recent_file("test_file2", "1.8.3") cfg.config.add_recent_file("test_file3", "test_format_file3") # add 3 files assert len(cfg.config.format_files) == 3 assert cfg.config.recent_files[0] == "test_file3" assert cfg.config.format_files[0] == "test_format_file3" assert cfg.config.recent_files[2] == "test_file1" assert cfg.config.format_files[2] == "test_format_file_new_1" cfg.config.add_recent_file("test_file2", "1.8.3") # move 2 to first line assert len(cfg.config.format_files) == 3 assert cfg.config.recent_files[0] == "test_file2" assert cfg.config.format_files[0] == "1.8.3" assert cfg.config.recent_files[1] == "test_file3" assert cfg.config.format_files[1] == "test_format_file3" assert cfg.config.recent_files[2] == "test_file1" assert cfg.config.format_files[2] == "test_format_file_new_1" # test get_format_file function assert cfg.config.get_format_file("test_file1") == "test_format_file_new_1" assert cfg.config.get_format_file("test_file2") == "1.8.3" config.update_current_working_dir("/home/test.yaml") # test update_current_working_dir assert config.current_working_dir == "/home" cfg.config.save() cfg.config.recent_files = [] cfg.config.format_files = [] cfg.config = Config().open() # save config assert len(cfg.config.format_files) == 3 assert cfg.config.recent_files[0] == "test_file2" assert cfg.config.format_files[0] == "1.8.3" assert cfg.config.recent_files[1] == "test_file3" assert cfg.config.format_files[1] == "test_format_file3" assert cfg.config.recent_files[2] == "test_file1" assert cfg.config.format_files[2] == "test_format_file_new_1"
def set_empty_config(): Config.SERIAL_FILE = "ModelEditorData_test" cfg.config = Config() cfg.init(None)