Ejemplo 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)
Ejemplo n.º 2
0
    def load_ws_definitions(self):
        global WebServiceDefinitions
        WebServiceDefinitions = WebServiceDefinitionList()

        # for x in self.threadlist:
        #     print 'thread name: ' + x.getName()

        for mod in self.modules:
            wsdef = self.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 = []

                wsdef = list(wsdef)  # make a copy (as this is really a class constant and we dont want leakage)

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

                if mod.find('.') != -1:
                    modulename, instancename = mod.split('.', 1)

                    # make urls into instance format
                    for wsd in wsdef:
                        wsd.url = '/' + modulename + '/' + instancename + wsd.url

                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(self.modules[mod].module, wsdi.cl)
                        if wsdi.methodname is not None and wsdi.argnames is not None:
                            # make a copy so that the following overwrites aren't inherited on the next iter
                            c = copy.deepcopy(_c)
                            # modify the class instance name reference of our copied class
                            wsdi.cl = wsdi.cl + '_' + wsdi.methodname
                            # 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.')

        webservice_hawebservice_init(SharedQueue=self.queue, ThreadList=self.threadlist)
Ejemplo n.º 3
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)