Esempio n. 1
0
    def __init__(self, name, callback_function, queue, threadlist, modules):
        HomeAutomationQueueThread.__init__(self,
                                           name=name,
                                           callback_function=callback_function,
                                           queue=queue,
                                           threadlist=threadlist)

        global WebServiceDefinitions
        WebServiceDefinitions = WebServiceDefinitionList()

        for mod in modules:
            wsdef = modules[mod].cls.webservice_definitions

            if wsdef is not None:
                if type(wsdef) == types.FunctionType:
                    logging.debug('wsdef is function, trying to execute')
                    wsdef_addition = wsdef(
                    )  # extend submodules or other dynamic collection
                    if type(wsdef_addition) == types.ListType:
                        wsdef = wsdef_addition
                elif type(wsdef) != types.ListType:
                    wsdef = []

                if hasattr(modules[mod].cls, '_webservice_definitions'):
                    # automatically created through decorator
                    wsdef_internal = getattr(modules[mod].cls,
                                             '_webservice_definitions')
                    wsdef.extend(wsdef_internal)
                    logging.info('added decorator definitions')

                WebServiceDefinitions.extend(wsdef)
                logging.debug(
                    str(len(wsdef)) + ' definitions loaded from module ' + mod)

                for wsdi in wsdef:
                    try:
                        logging.info('wsdi ' + str(wsdi))
                        _c = getattr(modules[mod].module, wsdi.cl)
                        if wsdi.methodname is not None and wsdi.argnames is not None:
                            c = copy.deepcopy(
                                _c
                            )  # make a copy so that the following overwrites aren't inherited on the next iter
                            wsdi.cl = wsdi.cl + '_' + wsdi.methodname  # modify the class instance name reference of our copied class
                            # logging.info(wsdi.cl + ' - attaching methodname and argnames ' + wsdi.methodname)
                            # c.methodname = wsdi.methodname
                            # c.argnames = wsdi.argnames
                            globals()[wsdi.cl] = c  # just a little hacky
                            # logging.info('resolved to: ' + `c`)
                        else:
                            globals()[wsdi.cl] = _c  # just a little hacky
                            # logging.info('resolved to: ' + `_c`)
                    except AttributeError:
                        logging.info(
                            'Unexpected exception caught while loading WSD ' +
                            wsdi.cl + ' from module ' + mod + ' - ' +
                            traceback.format_exc())

        logging.info(str(len(WebServiceDefinitions)) + ' definitions loaded.')

        global SharedQueue  # deprecated?
        SharedQueue = queue

        global ThreadList
        ThreadList = threadlist

        webservice_hawebservice_init(SharedQueue=SharedQueue,
                                     ThreadList=ThreadList)