Exemplo n.º 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()
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.last_data_dir, "Yaml Files (*.yaml)")
     if yaml_file[0]:
         cfg.open_file(yaml_file[0])
         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()