Example #1
0
def test_load_config():
    with TemporaryDirectory() as td:
        subdirA = os.path.join(td, "A")
        subdirA1 = os.path.join(subdirA, "1")

        os.mkdir(subdirA)
        os.mkdir(subdirA1)

        sample_config = 'conf/sample-team-conf.yaml'
        subdirA_config = parse_ozy_conf(sample_config)
        subdirA_config['apps']['nomad']['version'] = '10.10.10.10'
        save_temp_ozy_conf(subdirA_config, os.path.join(subdirA, ".ozy.yaml"))

        loaded_config = load_config(config=parse_ozy_conf(sample_config),
                                    current_working_directory=subdirA)

        assert loaded_config['apps']['nomad']['version'] == '10.10.10.10'

        # lets try with three dirs!
        subdirA1_config = parse_ozy_conf(sample_config)
        subdirA1_config['apps']['nomad']['version'] = '11.11.11.11'
        save_temp_ozy_conf(subdirA1_config,
                           os.path.join(subdirA1, ".ozy.yaml"))

        loaded_config = load_config(config=parse_ozy_conf(sample_config),
                                    current_working_directory=subdirA1)

        assert loaded_config['apps']['nomad']['version'] == '11.11.11.11'
Example #2
0
def info():
    """Print information about the installation and configuration."""
    _LOGGER.info(f"ozy v{__version__}")
    ozy_bin_dir = get_ozy_bin_dir()
    path_ok = check_path(ozy_bin_dir)
    if not path_ok:
        show_path_warning(ozy_bin_dir)
    user_config = load_ozy_user_conf()
    _LOGGER.info("Team URL: %s", user_config.get("url", "(unset)"))
    config = load_config()
    _LOGGER.info("Team config name: %s", config.get("name", "(unset)"))
    for app_name in config['apps']:
        app = App(app_name, config)
        _LOGGER.info("  %s: %s", app_name, app)
        if path_ok:
            found_app = shutil.which(app_name)
            if not found_app:
                _LOGGER.warning(
                    "  %s not found on path: perhaps an 'ozy sync' is needed?",
                    app_name)
            else:
                if os.path.realpath(found_app) != os.path.realpath(
                        os.path.join(ozy_bin_dir, app_name)):
                    _LOGGER.warning(
                        "  %s is not under ozy control! It was found on your PATH earlier than ozy at %s",
                        app_name, found_app)
Example #3
0
def sync():
    """
    Synchronise any local changes.

    If you're defining new applications in local user files, you can use this to ensure
    the relevant symlinks are created in your ozy bin directory.
    """
    symlink_binaries(get_ozy_bin_dir(), load_config())
Example #4
0
def install(apps):
    """Ensures the named applications are installed at their current prevailing versions."""
    config = load_config()
    for app_name in apps:
        if app_name not in config['apps']:
            raise OzyError(f"App '{app_name}' was not found")
        app = App(app_name, config)
        app.ensure_installed()
Example #5
0
File: app.py Project: lhayhurst/ozy
def find_app(tool, version=None):
    overrides = None
    if version:
        overrides = dict(apps=dict(tool=dict(version=version)))
    config = load_config(overrides)
    if tool in config['apps']:
        return App(tool, config)
    else:
        return None
Example #6
0
def makefile_config(makefile_var, required_apps, all_apps):
    """
    Checks apps, and prints a single-line Makefile variable.

    Use as an argument to $(eval). Errors will are output as $(error) directives
    to report in make.
    The given variable is defined to be the ozy binary directory, so any app will be
    $(VAR)/app_name. If undefined, you know ozy isn't installed.

    Example:

    \b
    $ cat Makefile
    $(eval $(shell ozy makefile-config OZY_BIN_DIR terraform))
    ifndef OZY_BIN_DIR
    $(error please install ozy)
    endif

    \b
    install:
        $(OZY_BIN_DIR)/terraform apply
    """
    config = load_config()
    ozy_bin_dir = get_ozy_bin_dir()
    path_ok = check_path(ozy_bin_dir)
    if not path_ok:
        _makefile_error("ozy is not on the path")
    if all_apps:
        required_apps = config['apps'].keys()
    if not required_apps:
        _makefile_error("no ozy apps found to configure")
    for app_name in required_apps:
        if app_name not in config['apps']:
            _makefile_error(f"Missing ozy app '{app_name}'")
        app = App(app_name, config)
        found_app = shutil.which(app_name)
        app_in_bin = os.path.join(ozy_bin_dir, app_name)
        if os.path.realpath(found_app) != os.path.realpath(app_in_bin):
            _makefile_error(
                f"{found_app} found in PATH earlier than ozy: "
                f"results could be inconsistent (found at {found_app})")
    print(f"{makefile_var}:={ozy_bin_dir}")
Example #7
0
def install_all():
    """Ensures all applications are installed at their current prevailing versions."""
    config = load_config()
    for app_name in config['apps']:
        app = App(app_name, config)
        app.ensure_installed()