From: boulant Date: Thu, 10 Nov 2011 10:27:47 +0000 (+0000) Subject: IMP: modufication of virtual_salome.py for the needs of plugins directories X-Git-Tag: RELIQUAT_6x_15112011 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f9f1cecdf3d6e507cfe42076ee73b063544f787;p=modules%2Fkernel.git IMP: modufication of virtual_salome.py for the needs of plugins directories ADD: syshelper for the need of plugins management --- diff --git a/bin/virtual_salome.py b/bin/virtual_salome.py index 02502849e..5a25222ee 100644 --- a/bin/virtual_salome.py +++ b/bin/virtual_salome.py @@ -205,17 +205,14 @@ def link_module(options): if not os.path.exists(module_lib_py_dir): print "Python directory %s does not exist" % module_lib_py_dir else: - # __GBO__ specific action for the package salome + # Specific action for the package salome module_lib_pypkg_dir=os.path.join(module_lib_py_dir,"salome") lib_pypkg_dir=os.path.join(lib_py_dir,"salome") mkdir(lib_pypkg_dir) - # __GBO__ mkdir(lib_py_shared_dir) for fn in os.listdir(module_lib_py_dir): if fn == "shared_modules": continue - # __GBO__ if fn == "salome": continue - # __GBO__ symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn)) pass if os.path.exists(module_lib_py_shared_dir): @@ -223,13 +220,11 @@ def link_module(options): symlink(os.path.join(module_lib_py_shared_dir, fn), os.path.join(lib_py_shared_dir, fn)) pass pass - # __GBO__ if os.path.exists(module_lib_pypkg_dir): for fn in os.listdir(module_lib_pypkg_dir): symlink(os.path.join(module_lib_pypkg_dir, fn), os.path.join(lib_pypkg_dir, fn)) pass pass - # __GBO__ else: if verbose: print module_lib_py_shared_dir, " doesn't exist" @@ -265,14 +260,14 @@ def link_module(options): if os.path.exists(module_share_dir): mkdir(share_dir) for fn in os.listdir(module_share_dir): - if fn=="resources": - #resources : create it and link content - mkdir(os.path.join(share_dir,"resources")) - for ffn in os.listdir(os.path.join(module_share_dir,"resources")): - symlink(os.path.join(module_share_dir, "resources", ffn), os.path.join(share_dir,"resources", ffn)) - else: - #other directories (not resources) - symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn)) + if fn in ["resources","plugins"] : + # Create the directory and then link the content + mkdir(os.path.join(share_dir,fn)) + for ffn in os.listdir(os.path.join(module_share_dir,fn)): + symlink(os.path.join(module_share_dir, fn, ffn), os.path.join(share_dir,fn, ffn)) + else: + #other directories (not resources) + symlink(os.path.join(module_share_dir, fn), os.path.join(share_dir, fn)) else: print "share/salome directory %s does not exist" % module_share_dir pass diff --git a/src/KERNEL_PY/kernel/Makefile.am b/src/KERNEL_PY/kernel/Makefile.am index e89076a49..a817b7ea2 100644 --- a/src/KERNEL_PY/kernel/Makefile.am +++ b/src/KERNEL_PY/kernel/Makefile.am @@ -35,7 +35,8 @@ mypkgpython_PYTHON = \ datamodeler.py \ testdata.py \ diclookup.py \ - threadhelper.py + threadhelper.py \ + syshelper.py nodist_mypkgpython_PYTHON = \ logconfig.py diff --git a/src/KERNEL_PY/kernel/kernelpy_autotest.sh.in b/src/KERNEL_PY/kernel/kernelpy_autotest.sh.in index 31bf4b68d..1c169192b 100644 --- a/src/KERNEL_PY/kernel/kernelpy_autotest.sh.in +++ b/src/KERNEL_PY/kernel/kernelpy_autotest.sh.in @@ -41,7 +41,8 @@ listfiles="\ datamodeler.py \ testdata.py \ diclookup.py \ - pyunittester.py \ + syshelper.py \ + pyunittester.py \ __init__.py" # This files should be add to the list diff --git a/src/KERNEL_PY/kernel/syshelper.py b/src/KERNEL_PY/kernel/syshelper.py new file mode 100644 index 000000000..dbc92c3ae --- /dev/null +++ b/src/KERNEL_PY/kernel/syshelper.py @@ -0,0 +1,114 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2008 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 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +__author__="gboulant" +__date__ ="$21 mai 2010 18:00:23$" + + +def findFiles(rootpath, excludes=[]): + """ + This looks after files recursively from the specified rootpath, + but without visiting directories whose basename is in the list + @param excludes. + """ + if not os.path.exists(rootpath): + raise RuntimeError("the path %s does not exists"%rootpath) + + exclude_options="" + for excludepath in excludes: + exclude_options+="-e %s "%excludepath + + listfiles=[] + stream=os.popen("find %s -type f | grep -v -e '\.svn' %s 2>/dev/null"%(rootpath,exclude_options)) + for line in stream.readlines(): + listfiles.append(line.split('\n')[0]) + + return listfiles + +import sys +from stat import ST_MODE, S_ISDIR, S_ISREG +def walktree(rootpath, callback, **kwargs): + ''' + This recursively descends the directory tree rooted at rootpath, + calling the callback function for each regular file + ''' + for f in os.listdir(rootpath): + pathname = os.path.join(rootpath, f) + try: + mode = os.stat(pathname)[ST_MODE] + except OSError, e: + # It probably means that the file is a broken inode + mode = -1 + if S_ISDIR(mode): + # It's a directory, recurse into it + walktree(pathname, callback, **kwargs) + elif S_ISREG(mode): + # It's a file, call the callback function + callback(pathname, **kwargs) + else: + # Unknown file type, print a message + print 'Skipping %s' % pathname + + +# +# ============================================================= +# Use cases and unit test functions +# ============================================================= +# +import os +try: + TESTDOCDIR=os.path.join(os.environ["KERNEL_ROOT_DIR"],"share") +except KeyError: + TESTDOCDIR="/tmp" + +def TEST_findFiles(): + print "########## find 1" + rootpath=TESTDOCDIR + listfiles=findFiles(rootpath) + for filename in listfiles: + print filename + + print "########## find 2" + excludes=[os.path.join(TESTDOCDIR,"doc")] + listfiles=findFiles(rootpath,excludes) + for filename in listfiles: + print filename + + return True + +# This is the test callback function +def visitfile_withargs(file, rootid): + print 'visiting file %s (rootid=%s)'%(file,str(rootid)) + +def visitfile_withoutargs(file): + print 'visiting file %s'%(file) + +def TEST_walktree(): + #walktree(TESTDOCDIR, visitfile_withargs, rootid=2) + walktree(TESTDOCDIR, visitfile_withoutargs) + return True + +if __name__ == "__main__": + import unittester + unittester.run("syshelper", "TEST_findFiles") + unittester.run("syshelper", "TEST_walktree")