Exemplo n.º 1
0
 def open_set_file(self, file):
     """open set file"""
     cfg.open_file(file)
     self._restore_backup()
     self.mainwindow.reload()
     self.mainwindow.update_recent_files()
     self._update_document_name()
     self.mainwindow.show_status_message("File '" + file + "' is opened")
Exemplo n.º 2
0
 def open_file(self):
     """open file menu action"""
     if not self.save_old_file():
         return
     yaml_file = QtWidgets.QFileDialog.getOpenFileName(
         self.mainwindow, "Choose Yaml Model File",
         cfg.config.data_dir, "Yaml Files (*.yaml)")
     if yaml_file[0]:
         cfg.open_file(yaml_file[0])
         self._restore_backup()
         self.mainwindow.reload()
         self.mainwindow.update_recent_files()
         self._update_document_name()
         self.mainwindow.show_status_message("File '" + yaml_file[0] + "' is opened")
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
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