Back to index

salome-kernel  6.5.0
Functions | Variables
KERNEL_PY.kernel.syshelper Namespace Reference

Functions

def findFiles
def walktree
def TEST_findFiles
def visitfile_withargs
def visitfile_withoutargs
def TEST_walktree

Variables

string __author__ = "gboulant"
string __date__ = "$21 mai 2010 18:00:23$"
tuple TESTDOCDIR = os.path.join(os.environ["KERNEL_ROOT_DIR"],"share")

Function Documentation

def KERNEL_PY.kernel.syshelper.findFiles (   rootpath,
  excludes = [] 
)
This looks after files recursively from the specified rootpath,
but without visiting directories whose basename is in the list
@param excludes.

Definition at line 28 of file syshelper.py.

00028 
00029 def findFiles(rootpath, excludes=[]):
00030     """
00031     This looks after files recursively from the specified rootpath,
00032     but without visiting directories whose basename is in the list
00033     @param excludes.
00034     """
00035     if not os.path.exists(rootpath):
00036         raise RuntimeError("the path %s does not exists"%rootpath)
00037 
00038     exclude_options=""
00039     for excludepath in excludes:
00040         exclude_options+="-e %s "%excludepath
00041 
00042     listfiles=[]        
00043     stream=os.popen("find %s -type f | grep -v -e '\.svn' %s 2>/dev/null"%(rootpath,exclude_options))
00044     for line in stream.readlines():
00045         listfiles.append(line.split('\n')[0])
00046         
00047     return listfiles

Here is the caller graph for this function:

Definition at line 84 of file syshelper.py.

00084 
00085 def TEST_findFiles():
00086     print "########## find 1"
00087     rootpath=TESTDOCDIR
00088     listfiles=findFiles(rootpath)
00089     for filename in listfiles:
00090         print filename
00091 
00092     print "########## find 2"
00093     excludes=[os.path.join(TESTDOCDIR,"doc")]
00094     listfiles=findFiles(rootpath,excludes)
00095     for filename in listfiles:
00096         print filename
00097 
00098     return True
00099 
# This is the test callback function

Here is the call graph for this function:

Definition at line 106 of file syshelper.py.

00106 
00107 def TEST_walktree():
00108     #walktree(TESTDOCDIR, visitfile_withargs, rootid=2)
00109     walktree(TESTDOCDIR, visitfile_withoutargs)
00110     return True

Here is the call graph for this function:

def KERNEL_PY.kernel.syshelper.visitfile_withargs (   file,
  rootid 
)

Definition at line 100 of file syshelper.py.

00100 
00101 def visitfile_withargs(file, rootid):
00102     print 'visiting file %s (rootid=%s)'%(file,str(rootid))

Definition at line 103 of file syshelper.py.

00103 
00104 def visitfile_withoutargs(file):
00105     print 'visiting file %s'%(file)

def KERNEL_PY.kernel.syshelper.walktree (   rootpath,
  callback,
  kwargs 
)
This recursively descends the directory tree rooted at rootpath,
calling the callback function for each regular file

Definition at line 50 of file syshelper.py.

00050 
00051 def walktree(rootpath, callback, **kwargs):
00052     '''
00053     This recursively descends the directory tree rooted at rootpath,
00054     calling the callback function for each regular file
00055     '''
00056     for f in os.listdir(rootpath):
00057         pathname = os.path.join(rootpath, f)
00058         try:
00059             mode = os.stat(pathname)[ST_MODE]
00060         except OSError, e:
00061             # It probably means that the file is a broken inode
00062             mode = -1
00063         if S_ISDIR(mode):
00064             # It's a directory, recurse into it
00065             walktree(pathname, callback, **kwargs)
00066         elif S_ISREG(mode):
00067             # It's a file, call the callback function
00068             callback(pathname, **kwargs)
00069         else:
00070             # Unknown file type, print a message
00071             print 'Skipping %s' % pathname
00072 
00073 
00074 #
00075 # =============================================================
00076 # Use cases and unit test functions
00077 # =============================================================
#

Here is the caller graph for this function:


Variable Documentation

Definition at line 24 of file syshelper.py.

string KERNEL_PY.kernel.syshelper.__date__ = "$21 mai 2010 18:00:23$"

Definition at line 25 of file syshelper.py.

string KERNEL_PY.kernel.syshelper.TESTDOCDIR = os.path.join(os.environ["KERNEL_ROOT_DIR"],"share")

Definition at line 80 of file syshelper.py.