annotate libervia/cli/cmd_notifications.py @ 4190:92551baea115

component AP gateway: be sure to have a string for error message.
author Goffi <goffi@goffi.org>
date Mon, 11 Dec 2023 18:07:58 +0100
parents 8d361adf0ee1
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4134
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
2
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia CLI
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
5
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
10
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
15
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
18
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from libervia.backend.core.i18n import _
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from libervia.backend.memory.memory import (
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
21 NotificationPriority,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
22 NotificationStatus,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
23 NotificationType,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
24 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from libervia.backend.tools.common import data_format, date_utils
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from libervia.cli.constants import Const as C
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from rich.live import Live
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from rich.table import Table
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from rich.text import Text
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
30
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from . import base
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
32
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
33 __commands__ = ["Notification"]
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
34
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
35
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
36 class Add(base.CommandBase):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
37 """Create and broadcast a notification"""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
38
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def __init__(self, host):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
40 super(Add, self).__init__(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
41 host, "add", use_verbose=True, help=_("create and broadcast a notification")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
42 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
43
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def add_parser_options(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "type",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
47 choices=[e.name for e in NotificationType],
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
48 help=_("notification type (default: %(default)s)"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
49 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
50
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "body_plain", help=_("plain text body of the notification")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
53 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
54
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
55 # TODO:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
56 # self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
57 # "-r", "--body-rich", default="", help=_("rich text body of the notification")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
58 # )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
59
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "-t", "--title", default="", help=_("title of the notification")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
62 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
63
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "-g",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
66 "--is-global",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
67 action="store_true",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
68 help=_("indicates if the notification is for all profiles"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
69 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
70
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
71 # TODO:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
72 # self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
73 # "--requires-action",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
74 # action="store_true",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
75 # help=_("indicates if the notification requires action"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
76 # )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
77
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "-P",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "--priority",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
81 default="MEDIUM",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
82 choices=[p.name for p in NotificationPriority],
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
83 help=_("priority level of the notification (default: %(default)s)"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
84 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
85
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
86 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "-e",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
88 "--expire-at",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
89 type=base.date_decoder,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
90 default=0,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
91 help=_(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
92 "expiration timestamp for the notification (optional, can be 0 for none)"
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
93 ),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
94 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
95
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
96 async def start(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
97 try:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
98 await self.host.bridge.notification_add(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.args.type,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.args.body_plain,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
101 "", # TODO: self.args.body_rich or "",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self.args.title or "",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self.args.is_global,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
104 False, # TODO: self.args.requires_action,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.args.priority,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.args.expire_at,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.profile,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
109 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
110 except Exception as e:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.disp(f"can't add notification: {e}", error=True)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
113 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.disp("Notification added.")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
115
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.host.quit()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
117
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
118
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
119 class Get(base.CommandBase):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
120 """Get available notifications"""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
121
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def __init__(self, host):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
123 super(Get, self).__init__(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
124 host,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
125 "get",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
126 use_output=C.OUTPUT_LIST_DICT,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
127 extra_outputs={"default": self.default_output},
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
128 help=_("display notifications"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
129 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
130
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def add_parser_options(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "-f",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "--follow",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
135 action="store_true",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
136 help=_("wait and print incoming notifications"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
137 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
138
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
140 "-t",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
141 "--type",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
142 type=str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
143 choices=[t.name for t in NotificationType],
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
144 help=_("filter by type of the notification"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
145 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
146
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
148 "-s",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
149 "--status",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
150 type=str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
151 choices=[s.name for s in NotificationStatus],
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
152 help=_("filter by status of the notification"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
153 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
154
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
155 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
156 "-a",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
157 "--requires-action",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
158 type=C.bool,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
159 default=None,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
160 help=_(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
161 "filter notifications that require (or not) user action, true by "
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "default, don't filter if omitted"
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
163 ),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
164 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
165
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
166 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
167 "-P",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
168 "--min-priority",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
169 type=str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
170 choices=[p.name for p in NotificationPriority],
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
171 help=_("filter notifications with at least the specified priority"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
172 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
173
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
174 def create_table(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
175 table = Table(box=None, show_header=False, collapse_padding=True)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
176 table.add_column("is_new")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
177 table.add_column("type")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
178 table.add_column("id")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
179 table.add_column("priority")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
180 table.add_column("timestamp")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
181 table.add_column("body")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
182 return table
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
183
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
184 def default_output(self, notifs):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
185 if self.args.follow:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
186 if self.live is None:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.table = table = self.create_table()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
188 self.live = Live(table, auto_refresh=False, console=self.console)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.host.add_on_quit_callback(self.live.stop)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
190 self.live.start()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
191 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
192 table = self.table
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
193 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
194 table = self.create_table()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
195
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
196 for notif in notifs:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
197 emoji_mapper = {
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
198 "chat": "💬",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "blog": "📝",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
200 "calendar": "📅",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
201 "file": "📂",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
202 "call": "📞",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
203 "service": "📢",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
204 "other": "🟣",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
205 }
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
206 emoji = emoji_mapper[notif.get("type", "other")]
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
207 notif_id = Text(notif["id"])
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
208 created = date_utils.date_fmt(notif["timestamp"], tz_info=date_utils.TZ_LOCAL)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
209
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
210 priority_name = NotificationPriority(notif["priority"]).name.lower()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
211
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
212 priority = Text(f"[{priority_name}]", style=f"priority_{priority_name}")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
213
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
214 body_parts = []
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
215 title = notif.get("title")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
216 if title:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
217 body_parts.append((f"{title}\n", "notif_title"))
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
218 body_parts.append(notif["body_plain"])
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
219 body = Text.assemble(*body_parts)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
220
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
221 new_flag = "🌟 " if notif.get("new") else ""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
222 table.add_row(new_flag, emoji, notif_id, created, priority, body)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
223
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
224 if self.args.follow:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
225 self.live.refresh()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
226 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
227 self.print(table)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
228
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
229 async def on_notification_new(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
230 self,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
231 id_: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
232 timestamp: float,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
233 type_: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
234 body_plain: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
235 body_rich: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
236 title: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
237 requires_action: bool,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
238 priority: int,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
239 expire_at: float,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
240 extra: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
241 profile: str,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
242 ) -> None:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
243 """Callback when a new notification is emitted."""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
244 notification_data = {
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
245 "id": id_,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
246 "timestamp": timestamp,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
247 "type": type_,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
248 "body_plain": body_plain,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
249 "body_rich": body_rich,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
250 "title": title,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
251 "requires_action": requires_action,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
252 "priority": priority,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
253 "expire_at": expire_at,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
254 "extra": data_format.deserialise(extra),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
255 "profile": profile,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
256 "new": True,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
257 }
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
258
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
259 await self.output([notification_data])
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
260
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
261 async def start(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
262 keys = ["type", "status", "requires_action", "min_priority"]
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
263 filters = {
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
264 key: getattr(self.args, key) for key in keys if getattr(self.args, key)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
265 }
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
266 try:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
267 notifications = data_format.deserialise(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
268 await self.host.bridge.notifications_get(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
269 data_format.serialise(filters),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
270 self.profile,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
271 ),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
272 type_check=list,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
273 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
274 except Exception as e:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
275 self.disp(f"can't get notifications: {e}", error=True)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
276 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
277 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
278 self.live = None
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
279 await self.output(notifications)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
280 if self.args.follow:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
281 self.host.bridge.register_signal(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
282 "notification_new", self.on_notification_new, "core"
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
283 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
284 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
285 self.host.quit()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
286
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
287
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
288 class Delete(base.CommandBase):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
289 """Delete a notification"""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
290
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
291 def __init__(self, host):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
292 super(Delete, self).__init__(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
293 host, "delete", use_verbose=True, help=_("delete a notification")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
294 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
295
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
296 def add_parser_options(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
297 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
298 "id",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
299 help=_("ID of the notification to delete"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
300 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
301
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
302 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
303 "-g", "--is-global",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
304 action="store_true",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
305 help=_("true if the notification is a global one"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
306 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
307
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
308 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
309 "--profile-key",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
310 default="@ALL@",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
311 help=_("Profile key (use '@ALL@' for all profiles, default: %(default)s)"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
312 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
313
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
314 async def start(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
315 try:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
316 await self.host.bridge.notification_delete(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
317 self.args.id, self.args.is_global, self.profile
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
318 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
319 except Exception as e:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
320 self.disp(f"can't delete notification: {e}", error=True)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
321 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
322 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
323 self.disp("Notification deleted.")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
324 self.host.quit()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
325
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
326
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
327 class Expire(base.CommandBase):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
328 """Clean expired notifications"""
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
329
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
330 def __init__(self, host):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
331 super(Expire, self).__init__(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
332 host, "expire", use_verbose=True, help=_("clean expired notifications")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
333 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
334
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
335 def add_parser_options(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
336 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
337 "-l",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
338 "--limit",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
339 type=base.date_decoder,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
340 metavar="TIME_PATTERN",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
341 help=_("time limit for older notifications. default: no limit used)"),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
342 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
343 self.parser.add_argument(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
344 "-a",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
345 "--all",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
346 action="store_true",
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
347 help=_(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
348 "expire notifications for all profiles (default: use current profile)"
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
349 ),
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
350 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
351
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
352 async def start(self):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
353 try:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
354 await self.host.bridge.notifications_expired_clean(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
355 -1.0 if self.args.limit is None else self.args.limit,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
356 C.PROF_KEY_NONE if self.args.all else self.profile,
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
357 )
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
358 except Exception as e:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
359 self.disp(f"can't clean expired notifications: {e}", error=True)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
360 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
361 else:
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
362 self.disp("Expired notifications cleaned.")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
363 self.host.quit()
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
364
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
365
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
366 class Notification(base.CommandBase):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
367 subcommands = (Add, Get, Delete, Expire)
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
368
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
369 def __init__(self, host):
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
370 super(Notification, self).__init__(
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
371 host, "notification", use_profile=False, help=_("Notifications handling")
8d361adf0ee1 cli: add `notification` commands
Goffi <goffi@goffi.org>
parents:
diff changeset
372 )