def execute_snippets(layer_obj, command_obj, prereqs): """Given in ImageLayer object, shell and binary to look up, find packages installed in the layer using the default method: For snippets, we will get the packages installed by the command""" # set up a notice origin for the layer origin_layer = 'Layer {}'.format(layer_obj.layer_index) # find packages for the command cmd_msg = (formats.invoke_for_snippets + '\n' + content.print_package_invoke(command_obj.name)) layer_obj.origins.add_notice_to_origins(origin_layer, Notice(cmd_msg, 'info')) pkg_list = filter.get_installed_package_names(command_obj) # collect all the dependencies for each package name all_pkgs = [] for pkg_name in pkg_list: pkg_invoke = command_lib.check_for_unique_package( prereqs.listing, pkg_name) deps, deps_msg = com.get_package_dependencies(pkg_invoke, pkg_name, prereqs.shell) if deps_msg: logger.warning(deps_msg) layer_obj.origins.add_notice_to_origins(origin_layer, Notice(deps_msg, 'error')) all_pkgs.append(pkg_name) all_pkgs.extend(deps) unique_pkgs = list(set(all_pkgs)) # get package metadata for each package name for pkg_name in unique_pkgs: pkg = Package(pkg_name) dcom.fill_package_metadata(pkg, pkg_invoke, prereqs.shell, layer_obj.get_layer_workdir(), prereqs.envs) layer_obj.add_package(pkg)
def add_snippet_packages(image_layer, command, pkg_listing, shell): '''Given an image layer object, a command object, the package listing and the shell used to invoke commands, add package metadata to the layer object. We assume the filesystem is already mounted and ready 1. Get the packages installed by the command 3. For each package get the dependencies 4. For each unique package name, find the metadata and add to the layer''' # set up a notice origin for the layer origin_layer = 'Layer: ' + image_layer.fs_hash[:10] # find packages for the command cmd_msg = formats.invoke_for_snippets + '\n' + \ content.print_package_invoke(command.name) image_layer.origins.add_notice_to_origins(origin_layer, Notice(cmd_msg, 'info')) pkg_list = get_installed_package_names(command) # collect all the dependencies for each package name all_pkgs = [] for pkg_name in pkg_list: pkg_invoke = command_lib.check_for_unique_package( pkg_listing, pkg_name) deps, deps_msg = get_package_dependencies(pkg_invoke, pkg_name, shell) if deps_msg: logger.warning(deps_msg) image_layer.origins.add_notice_to_origins( origin_layer, Notice(deps_msg, 'error')) all_pkgs.append(pkg_name) all_pkgs.extend(deps) unique_pkgs = list(set(all_pkgs)) # get package metadata for each package name for pkg_name in unique_pkgs: pkg = Package(pkg_name) fill_package_metadata(pkg, pkg_invoke, shell) image_layer.add_package(pkg)