コード例 #1
0
ファイル: common.py プロジェクト: gahlberg/tern
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)
コード例 #2
0
     if len(image_obj.layers) == 1:
         # mount only one layer
         target = rootfs.mount_base_layer(image_obj.layers[0].tar_file)
     else:
         target = analyze.mount_overlay_fs(image_obj,
                                           len(image_obj.layers) - 1)
     rootfs.prep_rootfs(target)
     # invoke commands in chroot
     # if we're looking up the snippets library
     # we should see 'snippets' in the keys
     if 'snippets' in args.keys and 'packages' in args.keys:
         # get the package info that corresponds to the package name
         # or get the default
         last = args.keys.pop()
         info_list = look_up_lib(args.keys)
         info_dict = command_lib.check_for_unique_package(
             info_list, args.package)[last]
     else:
         info_dict = look_up_lib(args.keys)
     # try to invoke the commands
     try:
         result = command_lib.get_pkg_attr_list(args.shell, info_dict,
                                                args.package)
         print('Output list: ' + ' '.join(result[0]))
         print('Error messages: ' + result[1])
         print('Number of elements: ' + str(len(result[0])))
     except subprocess.CalledProcessError as error:
         print(error.output)
     # undo the mounts
     rootfs.undo_mount()
     rootfs.unmount_rootfs()
 else: