util/misc.py
author Edouard Tisserant
Thu, 20 Sep 2012 22:30:41 +0200
changeset 835 8145be14a2ae
parent 815 e4f24593a758
child 1388 67c9a9482d24
permissions -rw-r--r--
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
"""
Misc definitions
"""

import os,sys

# helper func to check path write permission
def CheckPathPerm(path):
    if path is None or not os.path.isdir(path):
        return False
    for root, dirs, files in os.walk(path):
         for name in files:
             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
                 return False
    return True

def GetClassImporter(classpath):
    if type(classpath)==str:
        def fac():
            mod=__import__(classpath.rsplit('.',1)[0])
            return reduce(getattr, classpath.split('.')[1:], mod)
        return fac
    else:
        return classpath