def load_from_cache(layer): '''Given a layer object, check against cache to see if that layer id exists if yes then get the package list and load it in the layer and return true. If it doesn't exist return false Add notices to the layer's origins matching the origin_str''' loaded = False origin_layer = 'Layer: ' + layer.diff_id[:10] if not layer.packages: # there are no packages in this layer # try to get it from the cache raw_pkg_list = cache.get_packages(layer.diff_id) if raw_pkg_list: logger.debug('Loaded from cache: layer {}'.format( layer.diff_id[:10])) message = formats.loading_from_cache.format( layer_id=layer.diff_id[:10]) # add notice to the origin layer.origins.add_notice_to_origins(origin_layer, Notice( message, 'info')) for pkg_dict in raw_pkg_list: pkg = Package(pkg_dict['name']) pkg.fill(pkg_dict) layer.add_package(pkg) loaded = True return loaded
def load_from_cache(image): '''Given an image object, check against cache to see if a layer id exists if yes then get the package list and load it in the image layer. If it doesn't exist continue. If not all the layers have packages, return False else return True''' is_full = True # check if we can use repotag origin_str = '' if image.repotag: origin_str = image.repotag else: origin_str = 'Image ID - ' + image.id[:10] for layer in image.layers: if not layer.packages: # create an origin for this layer origin_str = origin_str + ': ' + layer.diff_id[:10] # there are no packages in this layer # try to get it from the cache raw_pkg_list = cache.get_packages(layer.diff_id) if not raw_pkg_list: is_full = False else: logger.debug('Loaded from cache: layer {}'.format( layer.diff_id[:10])) message = formats.loading_from_cache.format( layer_id=layer.diff_id[:10]) # add notice to the origin layer.origins.add_notice_to_origins(origin_str, Notice(message, 'info')) for pkg_dict in raw_pkg_list: pkg = Package(pkg_dict['name']) pkg.fill(pkg_dict) layer.add_package(pkg) return is_full
def get_layer_obj(sha): '''Given the sha, retrieve the list of packages from the cache and return a layer object''' layer_obj = Layer(sha) packages = cache.get_packages(sha) for package in packages: pkg_obj = Package(package['name']) pkg_obj.fill(package) layer_obj.add(pkg_obj) return layer_obj