def get_packages_from_base(base_image_tag): '''Get a list of package objects from invoking the commands in the command library base section: 1. For the image and tag name find if there is a list of package names 2. If there is an invoke dictionary, invoke the commands 3. Create a list of packages''' pkg_list = [] # information under the base image tag in the command library info = cmds.get_base_info(base_image_tag) if info: names = cmds.get_pkg_attr_list(info['shell'], info['names']) versions = cmds.get_pkg_attr_list(info['shell'], info['versions']) licenses = cmds.get_pkg_attr_list(info['shell'], info['licenses']) src_urls = cmds.get_pkg_attr_list(info['shell'], info['src_urls']) if names and len(names) > 1: for index in range(0, len(names)): pkg = Package(names[index]) if len(versions) == len(names): pkg.version = versions[index] if len(licenses) == len(names): pkg.license = licenses[index] if len(src_urls) == len(names): pkg.src_url = src_urls[index] pkg_list.append(pkg) else: logger.warning( cannot_retrieve_base_packages.format(image=base_image_tag[0], tag=base_image_tag[1])) else: logger.warning( no_image_tag_listing.format(image=base_image_tag[0], tag=base_image_tag[1])) return pkg_list
def get_package_obj(command_name, package_name, shell): '''Given the command name, and the package name, retrieve the package information, create an oject and return the package object''' # look up command name in snippet library if command_name in cmds.command_lib['snippets'].keys(): # get the unique or default information pkg_list = cmds.command_lib['snippets'][command_name]['packages'] pkg_info = check_for_unique_package(pkg_list, package_name) if pkg_info: pkg = Package(package_name) # get the information for values keys = pkg_info.keys() if 'version' in keys: try: pkg.version = cmds.get_pkg_attr_list( shell, pkg_info['version'], package_name=package_name)[0] except subprocess.CalledProcessError as error: logger.warning(error.output) if 'license' in keys: try: pkg.license = cmds.get_pkg_attr_list( shell, pkg_info['license'], package_name=package_name)[0] except subprocess.CalledProcessError as error: logger.warning(error.output) if 'src_url' in keys: try: pkg.src_url = cmds.get_pkg_attr_list( shell, pkg_info['src_url'], package_name=package_name)[0] except subprocess.CalledProcessError as error: logger.warning(error.output) return pkg else: print( 'No package named {} nor default listing'.format(package_name)) else: print('No command {} listed in snippet library'.format(command_name))
def get_package_dependencies(command_name, package_name, shell): '''Given the command name, the package name and the shell, find the list of dependencies''' deps = [] # look up snippet library pkg_list = cmds.command_lib['snippets'][command_name]['packages'] pkg_dict = check_for_unique_package(pkg_list, package_name) if pkg_dict and 'deps' in pkg_dict.keys(): deps.extend( cmds.get_pkg_attr_list(shell, pkg_dict['deps'], package_name=package_name)) return list(set(deps))
A script to test if the set of commands that get executed within a container produce expected results. Give a list of keys to point to in the command library and the image''') parser.add_argument('--container', default=cmds.container, help='Name of the running container') parser.add_argument('--keys', nargs='+', help='List of keys to look up in the command library') parser.add_argument('--shell', default='/bin/bash', help='The shell executable that the container uses') parser.add_argument('--package', default='', help='A package name that the command needs to \ execute with') args = parser.parse_args() if 'snippets' in args.keys and 'packages' in args.keys: # we're looking up the snippet library # 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 = check_for_unique_package(info_list, args.package)[last] else: info_dict = look_up_lib(args.keys) try: result = cmds.get_pkg_attr_list( args.shell, info_dict, args.package, args.container) print(result) print(len(result)) except subprocess.CalledProcessError as error: print(error.output)