예제 #1
0
    def ensure_hk_bundle(
        store: HousekeeperAPI, bundle_data: dict, include: bool = False
    ) -> hk_models.Bundle:
        """Utility function to add a bundle of information to a housekeeper api"""

        bundle_exists = False
        for bundle in store.bundles():
            if bundle.name != bundle_data["name"]:
                continue
            bundle_exists = True
            _bundle = bundle
            break

        if not bundle_exists:
            _bundle, _version = store.add_bundle(bundle_data)
            store.add_commit(_bundle, _version)

        if include:
            store.include(_version)

        return _bundle
예제 #2
0
def get_versions(hk_api: HousekeeperAPI,
                 bundle_name: str = None) -> Iterator[hk_models.Version]:
    """Generates versions from hk bundles

    If no bundle name is given generate latest version for every bundle
    """
    if bundle_name:
        bundle = hk_api.bundle(bundle_name)
        if not bundle:
            LOG.info("Could not find bundle %s", bundle_name)
            return
        bundles = [bundle]
    else:
        bundles = hk_api.bundles()

    for bundle in bundles:
        LOG.debug("Check for versions in %s", bundle.name)
        last_version = hk_api.last_version(bundle.name)
        if not last_version:
            LOG.warning("No bundle found for %s in housekeeper", bundle.name)
            return
        yield last_version