util/misc.py
author Laurent Bessard
Mon, 06 May 2013 11:15:05 +0200
changeset 1092 e91f2c8d6f51
parent 815 e4f24593a758
child 1388 67c9a9482d24
permissions -rw-r--r--
Fixed bugs in CustomStyledTextCtrl
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     1
"""
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     2
Misc definitions
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     3
"""
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     4
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     5
import os,sys
806
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
     6
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     7
# helper func to check path write permission
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     8
def CheckPathPerm(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     9
    if path is None or not os.path.isdir(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    10
        return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    11
    for root, dirs, files in os.walk(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    12
         for name in files:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    13
             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    14
                 return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    15
    return True
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    16
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    17
def GetClassImporter(classpath):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    18
    if type(classpath)==str:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    19
        def fac():
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    20
            mod=__import__(classpath.rsplit('.',1)[0])
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    21
            return reduce(getattr, classpath.split('.')[1:], mod)
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    22
        return fac
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    23
    else:
731
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 728
diff changeset
    24
        return classpath