Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_base_listing(key):
'''Given the key listing in base.yml, return the dictionary'''
listing = {}
if key in command_lib['base'].keys():
listing = command_lib['base'][key]
else:
logger.warning("%s", errors.no_listing_for_base_key.format(
listing_key=key))
return listing
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
def check_library_key(listing, key):
'''Given the command library listing, check to see if a key is present.
If the key is in the list of keys that should be in there then provide
a note'''
try:
return listing[key], ''
except KeyError as e:
if e in base_keys and e not in package_keys:
return {}, errors.no_listing_for_base_key.format(
listing_key=e)
if e in package_keys and e not in base_keys:
return {}, errors.no_listing_for_package_key.format(
listing_key=e)
return {}, errors.unsupported_listing_for_key.format(listing_key=e)
origin_command_lib = formats.invoking_base_commands
# set up a notice origin for the first layer
origin_first_layer = 'Layer: ' + image_obj.layers[0].fs_hash[:10]
# find the shell to invoke commands in
shell, _ = command_lib.get_image_shell(
command_lib.get_base_listing(binary))
if not shell:
# add a warning notice for no shell in the command library
logger.warning('No shell listing in command library. '
'Using default shell')
no_shell_message = errors.no_shell_listing.format(
binary=binary, default_shell=constants.shell)
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(no_shell_message, 'warning'))
# add a hint notice to add the shell to the command library
add_shell_message = errors.no_listing_for_base_key.format(
listing_key='shell')
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(add_shell_message, 'hint'))
shell = constants.shell
# only extract packages if there is a known binary and the layer is not
# cached
if binary:
if not common.load_from_cache(image_obj.layers[0], redo):
# Determine pacakge/os style from binary in the image layer
common.get_os_style(image_obj.layers[0], binary)
# get the packages of the first layer
rootfs.prep_rootfs(target)
common.add_base_packages(image_obj.layers[0], binary, shell)
# unmount proc, sys and dev
rootfs.undo_mount()
else:
def get_shell(image_obj, binary):
# set up a notice origin referring to the base command library listing
origin_command_lib = formats.invoking_base_commands
# find the shell to invoke commands in
shell, _ = command_lib.get_image_shell(
command_lib.get_base_listing(binary))
if not shell:
# add a warning notice for no shell in the command library
logger.warning('No shell listing in command library. '
'Using default shell')
no_shell_message = errors.no_shell_listing.format(
binary=binary, default_shell=constants.shell)
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(no_shell_message, 'warning'))
# add a hint notice to add the shell to the command library
add_shell_message = errors.no_listing_for_base_key.format(
listing_key='shell')
image_obj.layers[0].origins.add_notice_to_origins(
origin_command_lib, Notice(add_shell_message, 'hint'))
shell = constants.shell
return shell