Exemple #1
0
def do_transform(con_file, yaml_file, dest_file, transformation_name):
        cfg.init(None)        
        if con_file:
            cfg.import_file(con_file)
            source_file = con_file
        elif yaml_file:
            cfg.open_file(yaml_file)
            source_file = yaml_file

        # check destination file
        if dest_file:
            file = dest_file
        else:
            file = os.path.splitext(source_file)[0] + '.yaml'  # replace extension
        if os.path.isfile(file):
            raise Exception("File already exists")

        # apply transformations        
        if transformation_name is not None:
            for transf in transformation_name:                
                cfg.transform(transf)

        file_d = open(file, 'w')
        file_d.write(cfg.document)
        file_d.close()
Exemple #2
0
    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.import_file(args.con_file)
        if args.transformation_name is not None:
            for transf in args.transformation_name:
                cfg.transform(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.last_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")