def fill_package_metadata(pkg_obj, pkg_listing, shell): '''Given a Package object and the Package listing from the command library, fill in the attribute value returned from looking up the data and methods of the package listing. Fill out: version, license and src_url If there are errors, fill out notices''' # create a NoticeOrigin for the package origin_str = 'command_lib/snippets.yml' # version version_listing, listing_msg = command_lib.check_library_key( pkg_listing, 'version') if version_listing: version_list, invoke_msg = command_lib.get_pkg_attr_list( shell, version_listing, package_name=pkg_obj.name) if version_list: pkg_obj.version = version_list[0] else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(invoke_msg, 'error')) else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(listing_msg, 'warning')) # license license_listing, listing_msg = command_lib.check_library_key( pkg_listing, 'license') if license_listing: license_list, invoke_msg = command_lib.get_pkg_attr_list( shell, license_listing, package_name=pkg_obj.name) if license_list: pkg_obj.license = license_list[0] else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(invoke_msg, 'error')) else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(listing_msg, 'warning')) # src_urls url_listing, listing_msg = command_lib.check_library_key( pkg_listing, 'src_url') if url_listing: url_list, invoke_msg = command_lib.get_pkg_attr_list( shell, url_listing, package_name=pkg_obj.name) if url_list: pkg_obj.src_url = url_list[0] else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(invoke_msg, 'error')) else: pkg_obj.origins.add_notice_to_origins( origin_str, Notice(listing_msg, 'warning'))
def get_package_dependencies(package_listing, package_name, shell): '''The package listing is the result of looking up the command name in the command library. Given this listing, the package name and the shell return a list of package dependency names''' deps_listing, deps_msg = command_lib.check_library_key(package_listing, 'deps') if deps_listing: deps_list, invoke_msg = command_lib.get_pkg_attr_list( shell, deps_listing, package_name=package_name, chroot=False) if deps_list: return list(set(deps_list)), '' else: return [], invoke_msg else: return [], deps_msg