def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._nodes = BrainNodesConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._files = BrainFilesConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() BaseContainerConfigurationData.__init__(self, section_name)
def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainNodesConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainFilesConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainOOBSConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
class BrainConfiguration(BaseContainerConfigurationData): def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._nodes = BrainNodesConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._files = BrainFilesConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() BaseContainerConfigurationData.__init__(self, section_name) @property def overrides(self): return self._overrides @property def defaults(self): return self._defaults @property def nodes(self): return self._nodes @property def binaries(self): return self._binaries @property def braintree(self): return self._braintree @property def files(self): return self._files @property def services(self): return self._services @property def security(self): return self._security @property def oob(self): return self._oob @property def dynamics(self): return self._dynamics @property def tokenizer(self): return self._tokenizer def load_configuration(self, configuration_file, bot_root): brain_config = configuration_file.get_section(self.section_name) if brain_config is not None: self._overrides.load_config_section(configuration_file, brain_config, bot_root) self._defaults.load_config_section(configuration_file, brain_config, bot_root) self._nodes.load_config_section(configuration_file, brain_config, bot_root) self._binaries.load_config_section(configuration_file, brain_config, bot_root) self._braintree.load_config_section(configuration_file, brain_config, bot_root) self._files.load_config_section(configuration_file, brain_config, bot_root) self._services.load_config_section(configuration_file, brain_config, bot_root) self._security.load_config_section(configuration_file, brain_config, bot_root) self._oob.load_config_section(configuration_file, brain_config, bot_root) self._dynamics.load_config_section(configuration_file, brain_config, bot_root) self._tokenizer.load_config_section(configuration_file, brain_config, bot_root) def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainNodesConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainFilesConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainOOBSConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: files: aiml: files: $BOT_ROOT/aiml extension: .aiml directories: true errors: /tmp/y-bot_errors.txt duplicates: /tmp/y-bot_duplicates.txt conversation: /tmp/y-bot_conversation.txt sets: files: $BOT_ROOT/sets extension: .txt directories: false maps: files: $BOT_ROOT/maps extension: .txt directories: false denormal: $BOT_ROOT/config/denormal.txt normal: $BOT_ROOT/config/normal.txt gender: $BOT_ROOT/config/gender.txt person: $BOT_ROOT/config/person.txt person2: $BOT_ROOT/config/person2.txt properties: $BOT_ROOT/config/properties.txt triples: $BOT_ROOT/config/triples.txt preprocessors: $BOT_ROOT/config/preprocessors.conf postprocessors: $BOT_ROOT/config/postprocessors.conf regex_templates: $BOT_ROOT/config/regex-templates.txt """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") files_config = BrainFilesConfiguration() files_config.load_config_section(yaml, brain_config, ".") self.assertIsNotNone(files_config.aiml_files) self.assertEqual(["./aiml"], files_config.aiml_files.files) self.assertEqual(".aiml", files_config.aiml_files.extension) self.assertTrue(files_config.aiml_files.directories) self.assertEqual("/tmp/y-bot_errors.txt", files_config.aiml_files.errors.filename) self.assertEqual("/tmp/y-bot_duplicates.txt", files_config.aiml_files.duplicates.filename) self.assertEqual("/tmp/y-bot_conversation.txt", files_config.aiml_files.conversation.filename) self.assertIsNotNone(files_config.set_files) self.assertEqual(["./sets"], files_config.set_files.files) self.assertEqual(".txt", files_config.set_files.extension) self.assertFalse(files_config.set_files.directories) self.assertIsNotNone(files_config.map_files) self.assertEqual(["./maps"], files_config.map_files.files) self.assertEqual(".txt", files_config.map_files.extension) self.assertFalse(files_config.map_files.directories) self.assertEqual(files_config.denormal, "./config/denormal.txt") self.assertEqual(files_config.normal, "./config/normal.txt") self.assertEqual(files_config.gender, "./config/gender.txt") self.assertEqual(files_config.person, "./config/person.txt") self.assertEqual(files_config.person2, "./config/person2.txt") self.assertEqual(files_config.properties, "./config/properties.txt") self.assertEqual(files_config.triples, "./config/triples.txt") self.assertEqual(files_config.preprocessors, "./config/preprocessors.conf") self.assertEqual(files_config.postprocessors, "./config/postprocessors.conf") self.assertEqual(files_config.regex_templates, "./config/regex-templates.txt")