Beispiel #1
0
def test_that_set_config_creates_directories_if_required():
    with scoped_curdir() as d:
        os.environ['XDG_CONFIG_HOME'] = d + '/.config'
        if 'STBT_CONFIG_FILE' in os.environ:
            del os.environ['STBT_CONFIG_FILE']
        set_config('global', 'test', 'hello2')
        assert os.path.isfile(d + '/.config/stbt/stbt.conf')
        _config_init(force=True)
        assert get_config('global', 'test') == 'hello2'
def test_that_set_config_creates_directories_if_required():
    with _directory_sandbox() as d:
        os.environ["XDG_CONFIG_HOME"] = d + "/.config"
        if "STBT_CONFIG_FILE" in os.environ:
            del os.environ["STBT_CONFIG_FILE"]
        set_config("global", "test", "hello2")
        assert os.path.isfile(d + "/.config/stbt/stbt.conf")
        _config_init(force=True)
        assert get_config("global", "test") == "hello2"
Beispiel #3
0
def test_that_set_config_creates_directories_if_required():
    with scoped_curdir() as d:
        os.environ['XDG_CONFIG_HOME'] = d + '/.config'
        if 'STBT_CONFIG_FILE' in os.environ:
            del os.environ['STBT_CONFIG_FILE']
        set_config('global', 'test', 'hello2')
        assert os.path.isfile(d + '/.config/stbt/stbt.conf')
        _config_init(force=True)
        assert get_config('global', 'test') == 'hello2'
Beispiel #4
0
def temporary_config(contents):
    with named_temporary_directory(prefix="stbt-test-config") as d:
        original_env = os.environ.get("STBT_CONFIG_FILE", "")
        filename = os.path.join(d, "stbt.conf")
        os.environ["STBT_CONFIG_FILE"] = ":".join([filename, original_env])
        with open(filename, "w") as f:
            f.write(dedent(contents))
        _config_init(force=True)
        try:
            yield
        finally:
            os.environ["STBT_CONFIG_FILE"] = original_env
            _config_init(force=True)
Beispiel #5
0
def temporary_config(contents):
    with named_temporary_directory(prefix="stbt-test-config") as d:
        original_env = os.environ.get("STBT_CONFIG_FILE", "")
        filename = os.path.join(d, "stbt.conf")
        os.environ["STBT_CONFIG_FILE"] = ":".join([filename, original_env])
        with open(filename, "w") as f:
            f.write(dedent(contents))
        _config_init(force=True)
        try:
            yield
        finally:
            os.environ["STBT_CONFIG_FILE"] = original_env
            _config_init(force=True)
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.prog = "stbt config"
    parser.description = """Prints the value of the specified key from the stbt
        configuration file. See 'configuration' in the stbt(1) man page."""
    parser.epilog = """Returns non-zero exit status if the specified key or
        section isn't found."""
    parser.add_argument("--bash-completion",
                        action="store_true",
                        help=argparse.SUPPRESS)
    parser.add_argument(
        "name",
        metavar="section.key",
        help="e.g. 'global.source_pipeline' or 'record.control_recorder'")
    args = parser.parse_args(sys.argv[1:])

    if args.bash_completion:
        cfg = _config_init()
        for section in cfg.sections():
            for option in cfg.options(section):
                print "%s.%s" % (section, option)
        sys.exit(0)

    if args.name.rfind(".") == -1:
        error("'name' parameter must contain the section and key "
              "separated by a dot")

    section, key = args.name.rsplit(".", 1)

    try:
        print get_config(section, key)
    except ConfigurationError as e:
        error(e.message)
Beispiel #7
0
def main():
    parser = argparse.ArgumentParser()
    parser.prog = "stbt config"
    parser.description = """Prints the value of the specified key from the stbt
        configuration file. See 'configuration' in the stbt(1) man page."""
    parser.epilog = """Returns non-zero exit status if the specified key or
        section isn't found."""
    parser.add_argument(
        "--bash-completion", action="store_true", help=argparse.SUPPRESS)
    parser.add_argument(
        "name", metavar="section.key",
        help="e.g. 'global.source_pipeline' or 'record.control_recorder'")
    args = parser.parse_args(sys.argv[1:])

    if args.bash_completion:
        cfg = _config_init()
        for section in cfg.sections():
            for option in cfg.options(section):
                print "%s.%s" % (section, option)
        sys.exit(0)

    if args.name.rfind(".") == -1:
        error("'name' parameter must contain the section and key "
              "separated by a dot")

    section, key = args.name.rsplit(".", 1)

    try:
        print get_config(section, key)
    except ConfigurationError as e:
        error(e.message)
def test_that_set_config_creates_new_sections_if_required():
    with set_config_test():
        set_config("non_existent_section", "test", "goodbye")
        assert get_config("non_existent_section", "test") == "goodbye"
        _config_init(force=True)
        assert get_config("non_existent_section", "test") == "goodbye"
def test_that_set_config_modifies_config_value():
    with set_config_test():
        set_config("global", "test", "goodbye")
        assert get_config("global", "test") == "goodbye"
        _config_init(force=True)
        assert get_config("global", "test") == "goodbye"
Beispiel #10
0
def test_that_set_config_creates_new_sections_if_required():
    with set_config_test():
        set_config('non_existent_section', 'test', 'goodbye')
        assert get_config('non_existent_section', 'test') == 'goodbye'
        _config_init(force=True)
        assert get_config('non_existent_section', 'test') == 'goodbye'
Beispiel #11
0
def test_that_set_config_modifies_config_value():
    with set_config_test():
        set_config('global', 'test', 'goodbye')
        assert get_config('global', 'test') == 'goodbye'
        _config_init(force=True)
        assert get_config('global', 'test') == 'goodbye'
Beispiel #12
0
def test_that_set_config_creates_new_sections_if_required():
    with set_config_test():
        set_config('non_existent_section', 'test', 'goodbye')
        assert get_config('non_existent_section', 'test') == 'goodbye'
        _config_init(force=True)
        assert get_config('non_existent_section', 'test') == 'goodbye'
Beispiel #13
0
def test_that_set_config_modifies_config_value():
    with set_config_test():
        set_config('global', 'test', 'goodbye')
        assert get_config('global', 'test') == 'goodbye'
        _config_init(force=True)
        assert get_config('global', 'test') == 'goodbye'