Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def untar_or_copy(p, dest):
"""
Depending on a kind of the provided path, either copy or extract it to the destination directory
:param str p: path to the directory to be copied or tarball to be extracted
:param str dest: where to extract file or copy dir
:return bool: whether the process was successful
"""
if os.path.exists(p):
if os.path.isdir(p):
fun = move
dest = os.path.join(dest, os.path.basename(p))
elif tarfile.is_tarfile(p):
fun = untar
print("Extracting '{}'".format(p))
else:
raise ValueError("Provided path is neither a directory nor a tar archive.")
fun(p, dest)
print("Moved '{}' to '{}'".format(p, dest))
return True
return False