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 import_file(self): """import con file menu action""" if not self.save_old_file(): return con_file = QtWidgets.QFileDialog.getOpenFileName( self.mainwindow, "Choose Con Model File", cfg.config.data_dir, "Con Files (*.con)") if con_file[0]: cfg.import_file(con_file[0]) self.mainwindow.reload() self.mainwindow.update_recent_files() self._update_document_name() self.mainwindow.show_status_message("File '" + con_file[0] + "' is imported")