util/misc.py
changeset 1923 65edbc03fdbf
parent 1920 584ad449ee58
child 1930 e6de7df5f401
equal deleted inserted replaced
1922:5353f4086a45 1923:65edbc03fdbf
    44         for name in files:
    44         for name in files:
    45             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
    45             if os.access(root, os.W_OK) is not True or os.access(os.path.join(root, name), os.W_OK) is not True:
    46                 return False
    46                 return False
    47     return True
    47     return True
    48 
    48 
    49 def GetClassImporter(classpath):
    49 def GetClassImporter(param):
    50     """
    50     """
    51     is used to resolve library class names in features.py
    51     is used to resolve library class names in features.py
    52     returns a callable that return the class pointed by classpath string
    52     if param is a string, returns a callable that return the class pointed by param
    53     if a class is given instead of string, then returns a callable returning it.
    53     if a class is given, then returns a callable that returns the given class.
    54     """
    54     """
    55 
    55 
    56     if isinstance(classpath, str):
    56     if isinstance(param, str):
    57         def factory():
    57         def factory():
    58             # on-demand import, only when using class
    58             # on-demand import, only when using class
    59             mod = __import__(classpath.rsplit('.', 1)[0])
    59             mod = __import__(param.rsplit('.', 1)[0])
    60             return reduce(getattr, classpath.split('.')[1:], mod)
    60             return reduce(getattr, param.split('.')[1:], mod)
    61         return factory
    61         return factory
       
    62     elif isinstance(param,types.ClassType):
       
    63         return lambda : param
    62     else:
    64     else:
    63         return classpath
    65         # backward compatibility 
       
    66         # for old extensions that pass some callables
       
    67         # deprecated, should not be used anymore
       
    68         return param
    64 
    69 
    65 
    70 
    66 def InstallLocalRessources(CWD):
    71 def InstallLocalRessources(CWD):
    67     # Beremiz bitmaps
    72     # Beremiz bitmaps
    68     AddBitmapFolder(os.path.join(CWD, "images"))
    73     AddBitmapFolder(os.path.join(CWD, "images"))