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_os_release():
'''Given the base layer object, determine if an os-release file exists and
return the PRETTY_NAME string from it. If no release file exists,
return an empty string. Assume that the layer filesystem is mounted'''
# os-release may exist under /etc/ or /usr/lib. We should first check
# for the preferred /etc/os-release and fall back on /usr/lib/os-release
# if it does not exist under /etc
etc_path = os.path.join(rootfs.get_working_dir(), constants.mergedir,
constants.etc_release_path)
lib_path = os.path.join(rootfs.get_working_dir(), constants.mergedir,
constants.lib_release_path)
if not os.path.exists(etc_path):
if not os.path.exists(lib_path):
return ''
etc_path = lib_path
# file exists at this point, try to read it
with open(etc_path, 'r') as f:
lines = f.readlines()
pretty_name = ''
# iterate through os-release file to find OS
for l in lines:
key, val = l.rstrip().split('=', 1)
if key == "PRETTY_NAME":
pretty_name = val
break
return pretty_name.strip('"')
def set_up():
'''Create required directories'''
workdir_path = os.path.join(constants.temp_folder, constants.workdir)
mergedir_path = os.path.join(constants.temp_folder, constants.mergedir)
if not os.path.isdir(workdir_path):
os.mkdir(workdir_path)
if not os.path.isdir(mergedir_path):
os.mkdir(mergedir_path)