def _translate_ui(self): tosca = csar.CSAR(os.path.join(self._source_directory, 'csar.zip'))\ .get_main_template_yaml() groups = CSARPackage._translate_ui_parameters(tosca, self.description) forms = [] for i, record in enumerate(groups): forms.append({'group{0}'.format(i): {'fields': record[0]}}) translated = { 'Version': 2.2, 'Application': CSARPackage._generate_application_ui( groups, self.full_name), 'Forms': forms } return yaml.dump(translated, Dumper=Dumper, default_style='"')
def _translate_class(self): csar_file = os.path.join(self._source_directory, 'csar.zip') shutil.copy(csar_file, self.get_resource(self.full_name)) if not os.path.isfile(csar_file): raise exceptions.PackageClassLoadError( self.full_name, 'File with class definition not found') csar_obj = csar.CSAR(csar_file) try: csar_obj.validate() except csar_exception.ValidationError as ve: raise exceptions.PackageFormatError('Not a CSAR archive: ' + str(ve)) translated = { 'Name': self.full_name, 'Extends': 'io.murano.Application' } csar_envs_path = os.path.join(self._source_directory, CSAR_RESOURCES_DIR_NAME, CSAR_ENV_DIR_NAME) validate_csar_parameters = (not os.path.isdir(csar_envs_path) or not os.listdir(csar_envs_path)) tosca = csar_obj.get_main_template_yaml() parameters = CSARPackage._build_properties(tosca, validate_csar_parameters) parameters.update(CSARPackage._translate_outputs(tosca)) translated['Properties'] = parameters hot = yaml.load( self._translate('tosca', csar_obj.csar, parameters, True)) files = CSARPackage._translate_files(self._source_directory) template_file = os.path.join(self._source_directory, CSAR_RESOURCES_DIR_NAME, 'template.yaml') with open(template_file, 'w') as outfile: outfile.write(yaml.safe_dump(hot)) translated.update(CSARPackage._generate_workflow(hot, files)) self._translated_class = yaml.dump(translated, Dumper=Dumper, default_style='"')