Beispiel #1
0
    def __init__(self, bus=None, **kwargs):
        """
        :param bus: Reference to the bus object to be used in the backend
        :type bus: platypush.bus.Bus

        :param kwargs: Key-value configuration for the backend
        :type kwargs: dict
        """

        self._thread_name = self.__class__.__name__
        EventGenerator.__init__(self)
        Thread.__init__(self, name=self._thread_name)

        # If no bus is specified, create an internal queue where
        # the received messages will be pushed
        self.bus = bus or Bus()
        self.device_id = Config.get('device_id')
        self.thread_id = None
        self._stop = False
        self._kwargs = kwargs
        self.logger = logging.getLogger(self.__class__.__name__)

        # Internal-only, we set the request context on a backend if that
        # backend is intended to react for a response to a specific request
        self._request_context = kwargs['_req_ctx'] if '_req_ctx' in kwargs \
            else None

        if 'logging' in kwargs:
            self.logger.setLevel(
                getattr(logging,
                        kwargs.get('logging').upper()))

        Thread.__init__(self)
Beispiel #2
0
    def __init__(self, bus=None, **kwargs):
        """
        Params:
            bus    -- Reference to the Platypush bus where the requests and the
                      responses will be posted [Bus]
            kwargs -- key-value configuration for this backend [Dict]
        """

        # If no bus is specified, create an internal queue where
        # the received messages will be pushed
        self.bus = bus or Bus()
        self.device_id = Config.get('device_id')
        self.thread_id = None
        self._stop = False
        self._kwargs = kwargs

        # Internal-only, we set the request context on a backend if that
        # backend is intended to react for a response to a specific request
        self._request_context = kwargs['_req_ctx'] if '_req_ctx' in kwargs \
            else None

        Thread.__init__(self)
        logging.basicConfig(
            stream=sys.stdout,
            level=Config.get('logging') if 'logging' not in kwargs else
            getattr(logging, kwargs['logging']))
Beispiel #3
0
    def __init__(self, config_file=None, backend=None, on_response=None):
        """
        Constructor.
        Params:
            config_file -- Path to the configuration file - default:
                           ~/.config/platypush/config.yaml or
                           /etc/platypush/config.yaml)
            backend     -- Name of the backend where pusher will send the
                           request and wait for the response (kafka
                           or pushbullet). Default: whatever is specified
                           with pusher=true in your configuration file
            on_response -- Method that will be invoked upon response receipt.
                           Takes a platypush.message.response.Response as arg.
                           Default: print the response and exit.
        """

        # Initialize the configuration
        self.config_file = config_file
        log_conf = Config.get('logging')
        Config.init(config_file)
        logging.basicConfig(level=log_conf['level'] if log_conf
                            and 'level' in log_conf else logging.info,
                            stream=sys.stdout)

        self.on_response = on_response or self.default_on_response()
        self.backend = backend or Config.get_default_pusher_backend()
        self.bus = Bus()
Beispiel #4
0
    def __init__(self,
                 bus: Optional[Bus] = None,
                 poll_seconds: Optional[float] = None,
                 **kwargs):
        """
        :param bus: Reference to the bus object to be used in the backend
        :param poll_seconds: If the backend implements a ``loop`` method, this parameter expresses how often the
            loop should run in seconds.
        :param kwargs: Key-value configuration for the backend
        """

        self._thread_name = self.__class__.__name__
        EventGenerator.__init__(self)
        ExtensionWithManifest.__init__(self)
        Thread.__init__(self, name=self._thread_name, daemon=True)

        # If no bus is specified, create an internal queue where
        # the received messages will be pushed
        self.bus = bus or Bus()
        self.poll_seconds = float(poll_seconds) if poll_seconds else None
        self.device_id = Config.get('device_id')
        self.thread_id = None
        self._stop_event = ThreadEvent()
        self._kwargs = kwargs
        self.logger = logging.getLogger(
            'platypush:backend:' + get_backend_name_by_class(self.__class__))
        self.zeroconf = None
        self.zeroconf_info = None

        # Internal-only, we set the request context on a backend if that
        # backend is intended to react for a response to a specific request
        self._request_context = kwargs['_req_ctx'] if '_req_ctx' in kwargs \
            else None

        if 'logging' in kwargs:
            self.logger.setLevel(
                getattr(logging,
                        kwargs.get('logging').upper()))