util/misc.py
author Edouard Tisserant
Mon, 21 May 2012 16:40:57 +0200
changeset 740 cee825fbe9b3
parent 734 5c42cafaee15
child 781 cdc6393705ce
permissions -rw-r--r--
fixed exception when launching discovery dialog without network
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
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     6
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     7
# helper func to get path to images
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     8
def opjimg(imgname):
734
5c42cafaee15 Moved LPC sources to a separate project
Edouard Tisserant
parents: 731
diff changeset
     9
    return os.path.join(sys.path[0], "images", imgname+".png")
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    10
    
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    11
# helper func to check path write permission
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    12
def CheckPathPerm(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    13
    if path is None or not os.path.isdir(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    14
        return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    15
    for root, dirs, files in os.walk(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    16
         for name in files:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    17
             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
    18
                 return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    19
    return True
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    20
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    21
def GetClassImporter(classpath):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    22
    if type(classpath)==str:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    23
        def fac():
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    24
            mod=__import__(classpath.rsplit('.',1)[0])
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    25
            return reduce(getattr, classpath.split('.')[1:], mod)
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    26
        return fac
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    27
    else:
731
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 728
diff changeset
    28
        return classpath
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    29