Salome HOME
Merge branch 'master' into V9_dev
[modules/kernel.git] / src / KERNEL_PY / kernel / syshelper.py
index eb83e7966b546e81f7f8951fdb41422c2e07abde..abf8b893587cdcb44b45e9ffbf21f64f02877583 100644 (file)
@@ -1,5 +1,5 @@
 # -*- coding: iso-8859-1 -*-
 # -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -25,7 +25,7 @@ __author__="gboulant"
 __date__ ="$21 mai 2010 18:00:23$"
 
 
 __date__ ="$21 mai 2010 18:00:23$"
 
 
-def findFiles(rootpath, excludes=[]):
+def findFiles(rootpath, excludes=None):
     """
     This looks after files recursively from the specified rootpath,
     but without visiting directories whose basename is in the list
     """
     This looks after files recursively from the specified rootpath,
     but without visiting directories whose basename is in the list
@@ -34,6 +34,8 @@ def findFiles(rootpath, excludes=[]):
     if not os.path.exists(rootpath):
         raise RuntimeError("the path %s does not exists"%rootpath)
 
     if not os.path.exists(rootpath):
         raise RuntimeError("the path %s does not exists"%rootpath)
 
+    if excludes is None:
+        excludes = []
     exclude_options=""
     for excludepath in excludes:
         exclude_options+="-e %s "%excludepath
     exclude_options=""
     for excludepath in excludes:
         exclude_options+="-e %s "%excludepath
@@ -56,7 +58,7 @@ def walktree(rootpath, callback, **kwargs):
         pathname = os.path.join(rootpath, f)
         try:
             mode = os.stat(pathname)[ST_MODE]
         pathname = os.path.join(rootpath, f)
         try:
             mode = os.stat(pathname)[ST_MODE]
-        except OSError, e:
+        except OSError as e:
             # It probably means that the file is a broken inode
             mode = -1
         if S_ISDIR(mode):
             # It probably means that the file is a broken inode
             mode = -1
         if S_ISDIR(mode):
@@ -67,7 +69,7 @@ def walktree(rootpath, callback, **kwargs):
             callback(pathname, **kwargs)
         else:
             # Unknown file type, print a message
             callback(pathname, **kwargs)
         else:
             # Unknown file type, print a message
-            print 'Skipping %s' % pathname
+            print('Skipping %s' % pathname)
 
 
 #
 
 
 #
@@ -82,26 +84,26 @@ except KeyError:
     TESTDOCDIR="/tmp"
     
 def TEST_findFiles():
     TESTDOCDIR="/tmp"
     
 def TEST_findFiles():
-    print "########## find 1"
+    print("########## find 1")
     rootpath=TESTDOCDIR
     listfiles=findFiles(rootpath)
     for filename in listfiles:
     rootpath=TESTDOCDIR
     listfiles=findFiles(rootpath)
     for filename in listfiles:
-        print filename
+        print(filename)
 
 
-    print "########## find 2"
+    print("########## find 2")
     excludes=[os.path.join(TESTDOCDIR,"doc")]
     listfiles=findFiles(rootpath,excludes)
     for filename in listfiles:
     excludes=[os.path.join(TESTDOCDIR,"doc")]
     listfiles=findFiles(rootpath,excludes)
     for filename in listfiles:
-        print filename
+        print(filename)
 
     return True
 
 # This is the test callback function
 def visitfile_withargs(file, rootid):
 
     return True
 
 # This is the test callback function
 def visitfile_withargs(file, rootid):
-    print 'visiting file %s (rootid=%s)'%(file,str(rootid))
+    print('visiting file %s (rootid=%s)'%(file,str(rootid)))
 
 def visitfile_withoutargs(file):
 
 def visitfile_withoutargs(file):
-    print 'visiting file %s'%(file)
+    print('visiting file %s'%(file))
 
 def TEST_walktree():
     #walktree(TESTDOCDIR, visitfile_withargs, rootid=2)
 
 def TEST_walktree():
     #walktree(TESTDOCDIR, visitfile_withargs, rootid=2)
@@ -109,6 +111,6 @@ def TEST_walktree():
     return True
 
 if __name__ == "__main__":
     return True
 
 if __name__ == "__main__":
-    import unittester
+    from . import unittester
     unittester.run("syshelper", "TEST_findFiles")
     unittester.run("syshelper", "TEST_walktree")
     unittester.run("syshelper", "TEST_findFiles")
     unittester.run("syshelper", "TEST_walktree")