Esempio n. 1
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)
Esempio n. 2
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())
Esempio n. 3
0
def update(dry_run, url):
    """Update base configuration from the remote URL."""
    user_conf = load_ozy_user_conf()
    if not url:
        if 'url' not in user_conf:
            raise OzyError('Missing url in configuration')
        url = user_conf['url']
    ozy_conf_filename = f"{get_ozy_dir()}/ozy.yaml"
    tmp_filename = ozy_conf_filename + ".tmp"
    download_to(tmp_filename, url)
    new_conf_root = parse_ozy_conf(tmp_filename)
    old_conf_root = parse_ozy_conf(ozy_conf_filename)

    changed = False
    for app, new_conf in new_conf_root['apps'].items():
        old_conf = old_conf_root['apps'].get(app, None)
        if not old_conf:
            _LOGGER.info('%s new app %s (%s)',
                         "Would install" if dry_run else "Installing", app,
                         new_conf['version'])
            changed = True
        elif old_conf['version'] != new_conf['version']:
            _LOGGER.info('%s %s from %s to %s',
                         "Would upgrade" if dry_run else "Upgrading", app,
                         old_conf['version'], new_conf['version'])
            changed = True

    if not dry_run:
        ozy_bin_dir = get_ozy_bin_dir()
        user_conf['url'] = url
        save_ozy_user_conf(user_conf)
        os.rename(tmp_filename, ozy_conf_filename)
        symlink_binaries(ozy_bin_dir, new_conf_root)
        if not changed:
            _LOGGER.info("No changes made")
    else:
        if changed:
            _LOGGER.info("Dry run only - no changes made")
        else:
            _LOGGER.info(
                "Dry run only - no changes would be made, even without --dry-run"
            )
        os.unlink(tmp_filename)
Esempio n. 4
0
def init(url):
    """Initialise and install ozy, with configuration from the given URL."""
    ensure_ozy_dirs()
    user_conf = load_ozy_user_conf()
    # TODO: make sure it isn't there already? upgrade/update instead?
    ozy_conf_filename = f"{get_ozy_dir()}/ozy.yaml"
    download_to(ozy_conf_filename, url)
    ozy_bin_dir = get_ozy_bin_dir()
    root_conf = parse_ozy_conf(ozy_conf_filename)  ## TODO think how this interacts with local config files

    symlink_binaries(ozy_bin_dir, root_conf)
    user_conf['url'] = url
    save_ozy_user_conf(user_conf)

    if not check_path(ozy_bin_dir):
        _LOGGER.info("ozy is installed, but needs a little more setup work:")
        show_path_warning(ozy_bin_dir)
    else:
        _LOGGER.info("ozy is installed and is ready to run")
Esempio n. 5
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}")