def send_notification(title: str,
                      text: str,
                      icon_name: str = "",
                      timeout: int = 0,
                      app_name: str = "",
                      notification_id: int = -1,
                      actions_manager: NotificationActionManager = None,
                      urgency_level: NotificationUrgencyLevel = None,
                      capture_notification_id: bool = True) -> str:

    # TODO: check that `pt-notify-send` is available, as it's not a hard dependency of the package

    cmd = "/usr/bin/pt-notify-send "
    cmd += "--print-id "
    cmd += "--expire-time=" + str(timeout) + " "

    if icon_name:
        cmd += "--icon=" + icon_name + " "

    if notification_id >= 0:
        cmd += "--replace=" + str(notification_id) + " "

    if actions_manager is not None:
        for action in actions_manager.actions:
            cmd += "--action=\"" + action.call_to_action_text + \
                ":" + action.command_str + "\" "

        if actions_manager.default_action is not None:
            cmd += "--default-action=" + actions_manager.default_action.command_str + " "

        if actions_manager.close_action is not None:
            cmd += "--close-action=" + actions_manager.close_action.command_str + " "

    if app_name:
        cmd += "--app-name=" + app_name + " "

    if urgency_level is not None:
        cmd += "--urgency=" + urgency_level.name + " "

    cmd += " \"" + title + "\" "
    cmd += "\"" + text + "\""

    PTLogger.info("pt-notify-send command: {}".format(cmd))

    try:
        resp_stdout = run_command(cmd,
                                  2000,
                                  capture_output=capture_notification_id)
    except Exception as e:
        PTLogger.warning("Failed to show message: {}".format(e))
        raise
    return resp_stdout
Beispiel #2
0
    def __connect_to_socket(self):
        self.__zmq_context = zmq.Context()
        self.__zmq_socket = self.__zmq_context.socket(zmq.REQ)
        self.__zmq_socket.sndtimeo = _TIMEOUT_MS
        self.__zmq_socket.rcvtimeo = _TIMEOUT_MS

        try:
            self.__zmq_socket.connect("tcp://127.0.0.1:3782")
            PTLogger.debug("pt-device-manager request client is ready")

        except zmq.error.ZMQError as e:
            PTLogger.error("Error starting the request client: " + str(e))
            PTLogger.info(format_exc())
            raise
Beispiel #3
0
    def __connect_to_socket(self):
        self.__zmq_context = zmq.Context()
        self.__zmq_socket = self.__zmq_context.socket(zmq.SUB)
        self.__zmq_socket.setsockopt_string(zmq.SUBSCRIBE, "")

        try:
            self.__zmq_socket.connect("tcp://127.0.0.1:3781")
            PTLogger.debug("pt-device-manager subscribe client is ready")

        except zmq.error.ZMQError as e:
            PTLogger.error("Error starting the subscribe client: " + str(e))
            PTLogger.info(format_exc())

            return False

        return True