From: Gilles DAVID Date: Wed, 13 Oct 2021 13:06:03 +0000 (+0200) Subject: pythonpath_reduction.py: Fix remove link and add ignore option X-Git-Tag: EMC2P_V_1_3_4~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=853fe3fbad999e30fe182b6f9aa3f3499db612fa;p=modules%2Fkernel.git pythonpath_reduction.py: Fix remove link and add ignore option --- diff --git a/bin/pythonpath_reduction.py b/bin/pythonpath_reduction.py index ac50b2262..eadb78734 100644 --- a/bin/pythonpath_reduction.py +++ b/bin/pythonpath_reduction.py @@ -20,12 +20,15 @@ logging.basicConfig() logger = logging.getLogger(os.path.basename(__file__)) logger.setLevel(logging.INFO) +IGNORE = ['__pycache__', '__init__.py', '.yamm', 'NEWS', 'README'] + def remove(path): - if os.path.isdir(path): + logger.debug('Removing %r' % (path)) + if os.path.islink(path): + os.unlink(path) + elif os.path.isdir(path): shutil.rmtree(path) - elif os.path.islink(path): - os.remove(path) else: os.remove(path) @@ -34,15 +37,18 @@ def copy(src, dst): logger.debug('Copy %r to %r' % (src, dst)) if os.path.exists(dst): remove(dst) - if os.path.isdir(src): - shutil.copytree(src, dst) - else: + if not os.path.isdir(src): shutil.copyfile(src, dst) + else: + shutil.copytree(src, dst) def copy_or_link(src, dst): if sys.platform in ('linux', 'linux2'): if os.path.exists(dst): + current_dst = os.readlink(dst) + logger.warning('Destination link %r already exists and links to %r.' % (dst, current_dst)) + logger.warning('It is overwritten to %r' % (src)) remove(dst) os.symlink(src, dst) else: @@ -53,8 +59,13 @@ if sys.version_info[0] < 3: raise Exception("Must be using Python 3") -def main(prerequis_install_dir, salome_install_dir, context_file_name, env_file_name): +def main(prerequis_install_dir, salome_install_dir, context_file_name, env_file_name, ignore=None): # Create the new python module folder on the same directory of prerequisites folder (salome install path ) + if ignore: + ignore = IGNORE + ignore + else: + ignore = IGNORE[::] + while(prerequis_install_dir[-1] == '/'): prerequis_install_dir = prerequis_install_dir[:-1] if salome_install_dir.strip() == '': @@ -110,6 +121,8 @@ def main(prerequis_install_dir, salome_install_dir, context_file_name, env_file_ easy_install.write("./%s\n" % egg_file) else: for f in os.listdir(d): + if f in ignore: + continue full_file_srcpath = os.path.join(d, f) full_file_dstpath = os.path.join(pythonpath_common, f) copy_or_link(full_file_srcpath, full_file_dstpath) @@ -165,8 +178,10 @@ if __name__ == '__main__': help='Context file name (default: %(default)s)') parser.add_argument('-e', '--env-file', default='salome_prerequisites.sh', help='Env file name (default: %(default)s)') + parser.add_argument('-i', '--ignore', nargs='*', + help='List of comma separated files to ignore') parser.add_argument(dest='prerequis_install_dir', help='Prerequisites install directory') args = parser.parse_args() if args.verbose: logger.setLevel(logging.DEBUG) - main(args.prerequis_install_dir, args.salome_install_dir, args.context_file, args.env_file) + main(args.prerequis_install_dir, args.salome_install_dir, args.context_file, args.env_file, args.ignore)