示例#1
0
 def transform(self, file):
     """Run transformation according rules in set file"""
     cfg.update_yaml_file(self.mainwindow.editor.text())
     cfg.transform(file)
     # synchronize cfg document with editor text
     self.mainwindow.editor.setText(cfg.document, keep_history=True)
     self.mainwindow.reload()
示例#2
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()
示例#3
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()