예제 #1
0
    def __init__(self,
                 name,
                 stop_cb=None,
                 is_manager=False,
                 parser=None,
                 daemonize=True,
                 log_prefix="xplplugin_",
                 log_on_stdout=True,
                 test=False,
                 nohub=False,
                 source=None):
        '''
        Create XplPlugin instance, which defines system handlers
        @param nohub : if set the hub discovery will be disabled
        @param source : overwrite the source value (client-device.instance)
        '''

        Plugin.__init__(self,
                        name,
                        stop_cb=stop_cb,
                        is_manager=is_manager,
                        parser=parser,
                        daemonize=daemonize,
                        log_prefix=log_prefix,
                        log_on_stdout=log_on_stdout,
                        test=test)

        ### start xpl dedicated part

        self.log.info(u"Start of the xPL init")

        # start the xPL manager
        if 'broadcast' in self.config:
            broadcast = self.config['broadcast']
        else:
            broadcast = "255.255.255.255"
        if 'bind_interface' in self.config:
            self.myxpl = Manager(self.config['bind_interface'],
                                 broadcast=broadcast,
                                 plugin=self,
                                 nohub=nohub,
                                 source=source)
        else:
            self.myxpl = Manager(broadcast=broadcast, plugin=self, nohub=nohub)

        # hbeat not yet called (will be called by the ready() function by a developper plugin)
        self.enable_hbeat_called = False

        # define the source (in can be used in some plugins)
        if source == None:
            self.source = "{0}-{1}.{2}".format(DMG_VENDOR_ID,
                                               self.get_plugin_name(),
                                               self.get_sanitized_hostname())
            # in case we overwrite the source :
            self.source = source
        self.log.info(u"End of the xPL init")
예제 #2
0
    def __init__(self,
                 name,
                 stop_cb=None,
                 is_manager=False,
                 parser=None,
                 daemonize=True,
                 log_prefix="xplplugin_",
                 test=False,
                 nohub=False):
        '''
        Create XplPlugin instance, which defines system handlers
        @param nohub : if set the hub discovery will be disabled
        '''

        Plugin.__init__(self,
                        name,
                        stop_cb=stop_cb,
                        is_manager=is_manager,
                        parser=parser,
                        daemonize=daemonize,
                        log_prefix=log_prefix,
                        test=test)

        ### start xpl dedicated part

        self.log.info(u"Start of the xPL init")

        # start the xPL manager
        if 'broadcast' in self.config:
            broadcast = self.config['broadcast']
        else:
            broadcast = "255.255.255.255"
        if 'bind_interface' in self.config:
            self.myxpl = Manager(self.config['bind_interface'],
                                 broadcast=broadcast,
                                 plugin=self,
                                 nohub=nohub)
        else:
            self.myxpl = Manager(broadcast=broadcast, plugin=self, nohub=nohub)

        # hbeat not yet called (will be called by the ready() function by a developper plugin)
        self.enable_hbeat_called = False

        self.log.info(u"End of the xPL init")
예제 #3
0
파일: plugin.py 프로젝트: kopec77/domogik
    def __init__(self,
                 name,
                 stop_cb=None,
                 is_manager=False,
                 reload_cb=None,
                 dump_cb=None,
                 parser=None,
                 daemonize=True,
                 nohub=False):
        '''
        Create XplPlugin instance, which defines system handlers
        @param name : The name of the current plugin
        @param stop_cb : Additionnal method to call when a stop request is received
        @param is_manager : Must be True if the child script is a Domogik Manager process
        You should never need to set it to True unless you develop your own manager
        @param reload_cb : Callback to call when a "RELOAD" order is received, if None,
        nothing will happen
        @param dump_cb : Callback to call when a "DUMP" order is received, if None,
        nothing will happen
        @param parser : An instance of OptionParser. If you want to add extra options to the generic option parser,
        create your own optionparser instance, use parser.addoption and then pass your parser instance as parameter.
        Your options/params will then be available on self.options and self.args
        @param daemonize : If set to False, force the instance *not* to daemonize, even if '-f' is not passed
        on the command line. If set to True (default), will check if -f was added.
        @param nohub : if set the hub discovery will be disabled
        '''
        BasePlugin.__init__(self, name, stop_cb, parser, daemonize)
        Watcher(self)
        self.log.info("----------------------------------")
        self.log.info("Starting plugin '%s' (new manager instance)" % name)
        self._is_manager = is_manager
        self._name = name
        cfg = Loader('domogik')
        my_conf = cfg.load()
        self._config_files = CONFIG_FILE
        config = dict(my_conf[1])

        # Get pid and write it in a file
        self._pid_dir_path = config['pid_dir_path']
        self._get_pid()

        if len(self.get_sanitized_hostname()) > 16:
            self.log.error(
                "You must use 16 char max hostnames ! %s is %s long" %
                (self.get_sanitized_hostname(),
                 len(self.get_sanitized_hostname())))
            self.force_leave()
            return

        if 'broadcast' in config:
            broadcast = config['broadcast']
        else:
            broadcast = "255.255.255.255"
        if 'bind_interface' in config:
            self.myxpl = Manager(config['bind_interface'],
                                 broadcast=broadcast,
                                 plugin=self,
                                 nohub=nohub)
        else:
            self.myxpl = Manager(broadcast=broadcast, plugin=self, nohub=nohub)
        self._l = Listener(self._system_handler, self.myxpl, {
            'schema': 'domogik.system',
            'xpltype': 'xpl-cmnd'
        })
        self._reload_cb = reload_cb
        self._dump_cb = dump_cb

        # Create object which get process informations (cpu, memory, etc)
        # TODO : activate
        #self._process_info = ProcessInfo(os.getpid(),
        #                                 TIME_BETWEEN_EACH_PROCESS_STATUS,
        #                                 self._send_process_info,
        #                                 self.log,
        #                                 self.myxpl)
        #self._process_info.start()

        self.log.debug("end single xpl plugin")
예제 #4
0
파일: plugin.py 프로젝트: alphatb/domogik
    def __init__(self, name, stop_cb = None, is_manager = False, reload_cb = None, dump_cb = None, parser = None,
                 daemonize = True, nohub = False, test = False):
        '''
        Create XplPlugin instance, which defines system handlers
        @param name : The name of the current plugin
        @param stop_cb : Additionnal method to call when a stop request is received
        @param is_manager : Must be True if the child script is a Domogik Manager process
        You should never need to set it to True unless you develop your own manager
        @param reload_cb : Callback to call when a "RELOAD" order is received, if None,
        nothing will happen
        @param dump_cb : Callback to call when a "DUMP" order is received, if None,
        nothing will happen
        @param parser : An instance of ArgumentParser. If you want to add extra options to the generic option parser,
        create your own ArgumentParser instance, use parser.add_argument and then pass your parser instance as parameter.
        Your options/params will then be available on self.options and self.args
        @param daemonize : If set to False, force the instance *not* to daemonize, even if '-f' is not passed
        on the command line. If set to True (default), will check if -f was added.
        @param nohub : if set the hub discovery will be disabled
        '''
        BasePlugin.__init__(self, name, stop_cb, parser, daemonize)
        Watcher(self)
        self.log.info(u"----------------------------------")
        self.log.info(u"Starting plugin '%s' (new manager instance)" % name)
        self.log.info(u"Python version is {0}".format(sys.version_info))
        if self.options.test_option:
            self.log.info(u"The plugin is starting in TEST mode. Test option is {0}".format(self.options.test_option))
        self._name = name
        self._test = test   # flag used to avoid loading json in test mode
        
        '''
        Calculate the MQ name
        - For a core component this is just its component name (self._name)
        - For a plugin this is plugin-<self._name>-self.hostname

        The reason is that the core components need a fixed name on the mq network,
        if a plugin starts up it needs to request the config on the network, and it needs to know the worker (core component)
        to ask the config from.

        Because of the above reason, every item in the core_component list can only run once
        '''
        if self._name in CORE_COMPONENTS:
            self._mq_name = self._name
        else:
            self._mq_name = "plugin-{0}.{1}".format(self._name, self.get_sanitized_hostname())

        # MQ publisher and REP
        self.zmq = zmq.Context()
        self._pub = MQPub(self.zmq, self._mq_name)
        self._set_status(STATUS_STARTING)

        # MQ : start the thread which sends the status each N seconds
        thr_send_status = threading.Thread(None,
                                           self._send_status_loop,
                                           "send_status_loop",
                                           (),
                                           {})
        thr_send_status.start()

        ### MQ
        # for stop requests
        MQRep.__init__(self, self.zmq, self._mq_name)

        self.helpers = {}
        self._is_manager = is_manager
        cfg = Loader('domogik')
        my_conf = cfg.load()
        self._config_files = CONFIG_FILE
        config = dict(my_conf[1])
 
        self.libraries_directory = config['libraries_path']
        self.packages_directory = "{0}/{1}".format(config['libraries_path'], PACKAGES_DIR)
        self.resources_directory = "{0}/{1}".format(config['libraries_path'], RESOURCES_DIR)
        self.products_directory = "{0}/{1}_{2}/{3}".format(self.packages_directory, "plugin", self._name, PRODUCTS_DIR)

        # Get pid and write it in a file
        self._pid_dir_path = config['pid_dir_path']
        self._get_pid()

        if len(self.get_sanitized_hostname()) > 16:
            self.log.error(u"You must use 16 char max hostnames ! %s is %s long" % (self.get_sanitized_hostname(), len(self.get_sanitized_hostname())))
            self.force_leave()
            return

        if 'broadcast' in config:
            broadcast = config['broadcast']
        else:
            broadcast = "255.255.255.255"
        if 'bind_interface' in config:
            self.myxpl = Manager(config['bind_interface'], broadcast = broadcast, plugin = self, nohub = nohub)
        else:
            self.myxpl = Manager(broadcast = broadcast, plugin = self, nohub = nohub)

        self._reload_cb = reload_cb
        self._dump_cb = dump_cb

        # Create object which get process informations (cpu, memory, etc)
        # TODO : activate
        #self._process_info = ProcessInfo(os.getpid(),
        #                                 TIME_BETWEEN_EACH_PROCESS_STATUS,
        #                                 self._send_process_info,
        #                                 self.log,
        #                                 self.myxpl)
        #self._process_info.start()

        self.enable_hbeat_called = False
        self.dont_run_ready = False

        # for all no core elements, load the json
        # TODO find a way to do it nicer ??
        if self._name not in CORE_COMPONENTS and self._test == False:
            self._load_json()

        # init an empty devices list
        self.devices = []
        # init an empty 'new' devices list
        self.new_devices = []

        # check for products pictures
        if self._name not in CORE_COMPONENTS and self._test == False:
            self.check_for_pictures()

        # init finished
        self.log.debug(u"end single xpl plugin")