Exemplo n.º 1
0
    def main(self, *args):
        self.setup_logger()

        if self.config_path:
            if exists(self.config_path):
                config_name = basename(self.config_path)
                config_dir = dirname(self.config_path)
                self.config = load_config(ClientConfig, config_name,
                                          directories=[config_dir])
            else:
                self.log.error("Config not found: %s" % self.config_path)
        else:
            self.config = load_config(ClientConfig, ".upaas.yml",
                                      directories=[".", expanduser("~")])
        if not self.config:
            self.log.error("Missing config file")
            return ExitCodes.missing_config

        if args:
            self.log.error("Unknown command '%s'" % ' '.join(args))
            return ExitCodes.command_error

        if not self.nested_command:
            self.help()
            return ExitCodes.command_error
Exemplo n.º 2
0
def test_load_config_missing():
    cfg = base.load_config(BasicConfig, 'non existing file',
                           directories=['/non/existing/dir'])
    assert cfg is None
Exemplo n.º 3
0
def test_load_config_using_env():
    os.environ['UPAAS_CONFIG_DIR'] = os.path.dirname(__file__)
    cfg = base.load_config(BasicConfig, 'test_config.yml')
    assert cfg is not None
    assert cfg.required_string == "abc"
    assert cfg.folder1.subfolder1.required_int == 123
Exemplo n.º 4
0
def test_load_config_invalid():
    cfg = base.load_config(BasicConfig, os.path.basename(__file__),
                           directories=[os.path.dirname(__file__)])
    assert cfg is None
Exemplo n.º 5
0
def test_load_config_using_path():
    cfg = base.load_config(BasicConfig, 'test_config.yml',
                           directories=[os.path.dirname(__file__)])
    assert cfg is not None
    assert cfg.required_string == "abc"
    assert cfg.folder1.subfolder1.required_int == 123