util/misc.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Thu, 28 Apr 2016 12:58:58 +0300
changeset 1506 b9b8978dbc9d
parent 1388 67c9a9482d24
child 1511 91538d0c242c
permissions -rw-r--r--
Fix error about missing attribute 'timeout' that happens sometimes during compilation

The fix [1476:49f1763a5613] of the problem with following trace was wrong.
Traceback (most recent call last):
File "./Beremiz.py", line 1229, in run_with_except_hook
run_old(*args, **kw)
File
"/home/developer/WorkData/PLC/beremiz/beremiz/util/ProcessLogger.py",
line 68, in run
self.endcallback(self.Proc.pid, err)
File
"/home/developer/WorkData/PLC/beremiz/beremiz/util/ProcessLogger.py",
line 169, in finish
if self.timeout: self.timeout.cancel()
AttributeError: ProcessLogger instance has no attribute 'timeout'
The problem was that compilation process was finished before the timeout attribute is set.
Now timeout is set before launcing of compilation process.
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
1388
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    25
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    26
def InstallLocalRessources(CWD):
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    27
    from BitmapLibrary import AddBitmapFolder
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    28
    from TranslationCatalogs import AddCatalog
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    29
    import wx
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    30
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    31
    # Beremiz bitmaps
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    32
    AddBitmapFolder(os.path.join(CWD, "images"))
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    33
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    34
    # Internationalization
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    35
    AddCatalog(os.path.join(CWD, "locale"))
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    36
    import gettext
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    37
    import __builtin__
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    38
    
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    39
    __builtin__.__dict__['_'] = wx.GetTranslation
67c9a9482d24 Factorized bitmap and i18n resources loading in between PLCopenEditor and Beremiz. Now in utils/misc.py
Edouard Tisserant
parents: 815
diff changeset
    40