]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
pythonpath_reduction.py: Fix remove link and add ignore option
authorGilles DAVID <gilles-g.david@edf.fr>
Wed, 13 Oct 2021 13:06:03 +0000 (15:06 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Mon, 8 Nov 2021 15:58:10 +0000 (16:58 +0100)
bin/pythonpath_reduction.py

index ac50b226293cca2ce922e9ab2b2cabf6bf14f2fe..eadb78734a78af762652d2769dbb69b429e92d6c 100644 (file)
@@ -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)