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

parent 77828dd9
...@@ -40,7 +40,6 @@ ARCH_MAP = { ...@@ -40,7 +40,6 @@ ARCH_MAP = {
'x86_64': 'x86-64' 'x86_64': 'x86-64'
} }
def readElfAsDict(f): def readElfAsDict(f):
"""Reads ELF information from file""" """Reads ELF information from file"""
popen = subprocess.Popen(['readelf', '-d', f], popen = subprocess.Popen(['readelf', '-d', f],
...@@ -165,25 +164,23 @@ class Script: ...@@ -165,25 +164,23 @@ class Script:
self.cleanup_dir_list.append(extract_dir) self.cleanup_dir_list.append(extract_dir)
return extract_dir return extract_dir
def copy(self, origin, destination, ignore_dir_list=[]): def copytree(self, origin, destination, overwrite=False, ignore_dir_list=[]):
"""Copy directory. """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): if os.path.exists(destination) and not overwrite:
self.logger.info('No need to re-install java part') self.logger.info('Destination already exists, aborting.')
return False return False
self.logger.info("Copying unpacked contents") self.logger.info("Copying %s to %s" % (origin, destination))
java_dir = '' try:
if 'ignore' in shutil.copytree.func_code.co_varnames: shutil.copytree(origin, destination,
shutil.copytree(os.path.join(origin, java_dir),
destination,
ignore=lambda src,names:ignore_dir_list) ignore=lambda src,names:ignore_dir_list)
else: except shutil.Error:
shutil.copytree(origin, self.logger.error("Error occurred : %s")
destination) shutil.rmtree(destination)
for ignore_dir in ignore_dir_list: return False
ignore_dir = os.path.join(destination, ignore_dir)
if os.path.exists(ignore_dir):
shutil.rmtree(ignore_dir)
return True return True
script = 'raise NotImplementedError' 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