Simplify and fix copy(), and renamed it to copytree()

parent 77828dd9
......@@ -40,7 +40,6 @@ ARCH_MAP = {
'x86_64': 'x86-64'
}
def readElfAsDict(f):
"""Reads ELF information from file"""
popen = subprocess.Popen(['readelf', '-d', f],
......@@ -165,25 +164,23 @@ class Script:
self.cleanup_dir_list.append(extract_dir)
return extract_dir
def copy(self, origin, destination, ignore_dir_list=[]):
"""Copy directory.
def copytree(self, origin, destination, overwrite=False, ignore_dir_list=[]):
"""Recursively Copy directory. if "overwrite" is set to False, will stop if
destination already exists. ignore_dir_list is an array of directories
you want to exclude.
Example : copytree("/from", "/to", overwrite=True, ignore_dir_list=["a_private_dir"])
"""
if os.path.exists(destination):
self.logger.info('No need to re-install java part')
if os.path.exists(destination) and not overwrite:
self.logger.info('Destination already exists, aborting.')
return False
self.logger.info("Copying unpacked contents")
java_dir = ''
if 'ignore' in shutil.copytree.func_code.co_varnames:
shutil.copytree(os.path.join(origin, java_dir),
destination,
self.logger.info("Copying %s to %s" % (origin, destination))
try:
shutil.copytree(origin, destination,
ignore=lambda src,names:ignore_dir_list)
else:
shutil.copytree(origin,
destination)
for ignore_dir in ignore_dir_list:
ignore_dir = os.path.join(destination, ignore_dir)
if os.path.exists(ignore_dir):
shutil.rmtree(ignore_dir)
except shutil.Error:
self.logger.error("Error occurred : %s")
shutil.rmtree(destination)
return False
return True
script = 'raise NotImplementedError'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment