util/misc.py
changeset 1784 64beb9e9c749
parent 1742 92932cd370a4
child 1806 6b4d0f4f2fbc
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    24 
    24 
    25 """
    25 """
    26 Misc definitions
    26 Misc definitions
    27 """
    27 """
    28 
    28 
    29 import os,sys
    29 import os
       
    30 import sys
    30 
    31 
    31 # helper func to check path write permission
    32 
    32 def CheckPathPerm(path):
    33 def CheckPathPerm(path):
       
    34     """ Helper func to check path write permission """
    33     if path is None or not os.path.isdir(path):
    35     if path is None or not os.path.isdir(path):
    34         return False
    36         return False
    35     for root, dirs, files in os.walk(path):
    37     for root, dirs, files in os.walk(path):
    36         files = [f for f in files if not f[0] == '.']
    38         files = [f for f in files if not f[0] == '.']
    37         dirs[:] = [d for d in dirs if not d[0] == '.']
    39         dirs[:] = [d for d in dirs if not d[0] == '.']
    38         for name in files:
    40         for name in files:
    39             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
    41             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
    40                 return False
    42                 return False
    41     return True
    43     return True
    42 
    44 
       
    45 
    43 def GetClassImporter(classpath):
    46 def GetClassImporter(classpath):
    44     if type(classpath)==str:
    47     if type(classpath) == str:
    45         def fac():
    48         def fac():
    46             mod=__import__(classpath.rsplit('.',1)[0])
    49             mod = __import__(classpath.rsplit('.', 1)[0])
    47             return reduce(getattr, classpath.split('.')[1:], mod)
    50             return reduce(getattr, classpath.split('.')[1:], mod)
    48         return fac
    51         return fac
    49     else:
    52     else:
    50         return classpath
    53         return classpath
       
    54 
    51 
    55 
    52 def InstallLocalRessources(CWD):
    56 def InstallLocalRessources(CWD):
    53     from BitmapLibrary import AddBitmapFolder
    57     from BitmapLibrary import AddBitmapFolder
    54     from TranslationCatalogs import AddCatalog
    58     from TranslationCatalogs import AddCatalog
    55     import wx
    59     import wx
    59 
    63 
    60     # Internationalization
    64     # Internationalization
    61     AddCatalog(os.path.join(CWD, "locale"))
    65     AddCatalog(os.path.join(CWD, "locale"))
    62     import gettext
    66     import gettext
    63     import __builtin__
    67     import __builtin__
    64     
    68 
    65     __builtin__.__dict__['_'] = wx.GetTranslation
    69     __builtin__.__dict__['_'] = wx.GetTranslation
    66