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,27 +164,25 @@ class Script: ...@@ -165,27 +164,25 @@ 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
if os.path.exists(destination): you want to exclude.
self.logger.info('No need to re-install java part') Example : copytree("/from", "/to", overwrite=True, ignore_dir_list=["a_private_dir"])
return False """
self.logger.info("Copying unpacked contents") if os.path.exists(destination) and not overwrite:
java_dir = '' self.logger.info('Destination already exists, aborting.')
if 'ignore' in shutil.copytree.func_code.co_varnames: return False
shutil.copytree(os.path.join(origin, java_dir), self.logger.info("Copying %s to %s" % (origin, destination))
destination, try:
ignore=lambda src,names:ignore_dir_list) shutil.copytree(origin, destination,
else: ignore=lambda src,names:ignore_dir_list)
shutil.copytree(origin, except shutil.Error:
destination) self.logger.error("Error occurred : %s")
for ignore_dir in ignore_dir_list: shutil.rmtree(destination)
ignore_dir = os.path.join(destination, ignore_dir) return False
if os.path.exists(ignore_dir): return True
shutil.rmtree(ignore_dir)
return True
script = 'raise NotImplementedError' script = 'raise NotImplementedError'
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
self.cleanup_dir_list = [] self.cleanup_dir_list = []
......
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