Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def collate_list_metadata(shell, listing):
'''Given the shell and the listing for the package manager, collect
metadata that gets returned as a list'''
pkg_dict = {}
msgs = ''
warnings = ''
for item in command_lib.base_keys:
if item in listing.keys():
items, msg = command_lib.get_pkg_attr_list(shell, listing[item])
msgs = msgs + msg
pkg_dict.update({item: items})
else:
warnings = warnings + errors.no_listing_for_base_key.format(
listing_key=item)
return pkg_dict, msgs, warnings
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:
print("Something when wrong in loading the image")
report.teardown()
report.clean_image_tars(image_obj)
report.clean_working_dir(False)
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'))
# proj_urls
url_listing, listing_msg = command_lib.check_library_key(
pkg_listing, 'proj_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:
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'))
# proj_urls
url_listing, listing_msg = command_lib.check_library_key(
pkg_listing, 'proj_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.proj_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)
if deps_list:
return list(set(deps_list)), ''
return [], invoke_msg
return [], deps_msg