def testPythonToYaml(self): pythonDict = dict() pythonDict['foo'] = 'test \'legal\' yaml' pythonDict['bar'] = 'test "legal" yaml' pythonDict['baz'] = 'test \'legal\' yaml' pythonDict['newline'] = 'test embedded\nnewline yaml' translator = PythonToFile(pythonDict) translator.write_to_file(self._target_yaml_file) translator = FileToPython(self._target_yaml_file, use_ordering=True) newPythonDict = translator.parse() self.assertEqual('foo' in newPythonDict, True) self.assertEqual('bar' in newPythonDict, True) self.assertEqual('baz' in newPythonDict, True) self.assertEquals('newline' in newPythonDict, True) quotedValue = newPythonDict['foo'] self.assertEqual(quotedValue, 'test \'legal\' yaml') quotedValue = newPythonDict['bar'] self.assertEqual(quotedValue, 'test "legal" yaml') quotedValue = newPythonDict['baz'] self.assertEqual(quotedValue, 'test \'legal\' yaml') quotedValue = newPythonDict['newline'] self.assertEqual(quotedValue, 'test embedded\nnewline yaml')
def extract(self): """ Deploy resource model elements at the domain level, including multi-tenant elements. """ _method_name = 'extract' resource_file = self._model_context.get_domain_resource_file() self._logger.info("WLSDPLY-10000", resource_file, method_name=_method_name, class_name=self._class_name) # create the target file directory, if needed resource_dir = File(resource_file).getParentFile() if (not resource_dir.isDirectory()) and (not resource_dir.mkdirs()): mkdir_ex = exception_helper.create_deploy_exception( 'WLSDPLY-10001', resource_dir) raise mkdir_ex # build the resource file structure from the kubernetes section of the model resource_dict = self._create_domain_resource_dictionary() # revise the resource file structure with values from command line, and elsewhere in model self._update_resource_dictionary(resource_dict) # write the resource file structure to the output file writer = PythonToFile(resource_dict) writer.write_to_file(resource_file) return
def testPythonToJson(self): pythonDict = dict() pythonDict['foo'] = 'this is a "legal" JSON value' pythonDict['keys "can" have quotes too'] = 123 translator = PythonToFile(pythonDict) translator.write_to_file(self._target_json_file) translator = FileToPython(self._target_json_file) newPythonDict = translator.parse() self.assertEqual('foo' in newPythonDict, True) self.assertEqual('keys "can" have quotes too' in newPythonDict, True) self.assertEqual(newPythonDict['foo'], 'this is a "legal" JSON value') self.assertEqual(newPythonDict['keys "can" have quotes too'], 123)
class_name=_class_name, method_name=_method_name) except VariableException, ve: __logger.severe('WLSDPLY-20007', _program_name, variable_file, ve.getLocalizedMessage(), error=ve, class_name=_class_name, method_name=_method_name) return CommandLineArgUtil.PROG_ERROR_EXIT_CODE if model_change_count > 0: try: model_writer = PythonToFile(model) model_writer.write_to_file(model_file) __logger.info('WLSDPLY-04210', _program_name, model_change_count, model_file, class_name=_class_name, method_name=_method_name) except TranslateException, te: __logger.severe('WLSDPLY-04211', _program_name, model_file, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) return CommandLineArgUtil.PROG_ERROR_EXIT_CODE