util/misc.py
author laurent
Wed, 29 Aug 2012 19:26:40 +0200
changeset 807 17c97fec1164
parent 806 abf1afc1f04d
child 814 5743cbdff669
permissions -rw-r--r--
Fix import order in Beremiz.py to prevent wrong translations in internationalization
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
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
     7
from TextViewer import TextViewer
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
     8
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
     9
# helper func to check path write permission
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    10
def CheckPathPerm(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    11
    if path is None or not os.path.isdir(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    12
        return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    13
    for root, dirs, files in os.walk(path):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    14
         for name in files:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    15
             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
    16
                 return False
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    17
    return True
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    18
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    19
def GetClassImporter(classpath):
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    20
    if type(classpath)==str:
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    21
        def fac():
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    22
            mod=__import__(classpath.rsplit('.',1)[0])
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    23
            return reduce(getattr, classpath.split('.')[1:], mod)
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    24
        return fac
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    25
    else:
731
4fc681ed0c61 refecored library extension machanism
Edouard Tisserant
parents: 728
diff changeset
    26
        return classpath
725
31dade089db5 refactoring
Edouard Tisserant
parents:
diff changeset
    27
806
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    28
class IECCodeViewer(TextViewer):
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    29
    
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    30
    def __del__(self):
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    31
        TextViewer.__del__(self)
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    32
        if getattr(self, "_OnClose"):
abf1afc1f04d Fix bug when closing IECCodeView and IECRawCodeView, reopening them was impossible
laurent
parents: 781
diff changeset
    33
            self._OnClose(self)