annotate libervia/cli/cmd_blocking.py @ 4278:240d8b7ad906

component Conferences: implementation of SFU component to make multi-party A/V conferences: This component wrap `Galène` SFU and translate its signaling to XMPP Jingle in both direction. rel 445
author Goffi <goffi@goffi.org>
date Fri, 05 Jul 2024 17:18:37 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import json
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import os
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
24 from libervia.backend.tools.common import data_format
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
25 from libervia.cli import common
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
26 from libervia.cli.constants import Const as C
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from . import base
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 __commands__ = ["Blocking"]
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 class List(base.CommandBase):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def __init__(self, host):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 super().__init__(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 host,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "list",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 use_output=C.OUTPUT_LIST,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 help=_("list blocked entities"),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def add_parser_options(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 pass
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 async def start(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3788
diff changeset
46 blocked_jids = await self.host.bridge.blocking_list(
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.profile,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 except Exception as e:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.disp(f"can't get blocked entities: {e}", error=True)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 else:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 await self.output(blocked_jids)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.host.quit(C.EXIT_OK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class Block(base.CommandBase):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def __init__(self, host):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 super().__init__(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 host,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "block",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 help=_("block one or more entities"),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def add_parser_options(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.parser.add_argument(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 "entities",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 nargs="+",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 metavar="JID",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 help=_("JIDs of entities to block"),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 async def start(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
75 await self.host.bridge.blocking_block(self.args.entities, self.profile)
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 except Exception as e:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.disp(f"can't block entities: {e}", error=True)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 else:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.host.quit(C.EXIT_OK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
81
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 class Unblock(base.CommandBase):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def __init__(self, host):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 super().__init__(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 host,
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "unblock",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 help=_("unblock one or more entities"),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def add_parser_options(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.parser.add_argument(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 "entities",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 nargs="+",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 metavar="JID",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 help=_("JIDs of entities to unblock"),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 self.parser.add_argument(
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 "-f",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 "--force",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 action="store_true",
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 help=_('when "all" is used, unblock all entities without confirmation'),
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
104
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 async def start(self):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 if self.args.entities == ["all"]:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 if not self.args.force:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3788
diff changeset
108 await self.host.confirm_or_quit(
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 _("All entities will be unblocked, are you sure"),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
110 _("unblock cancelled"),
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 )
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.args.entities.clear()
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 elif self.args.force:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.parser.error(_('--force is only allowed when "all" is used as target'))
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
117 await self.host.bridge.blocking_unblock(self.args.entities, self.profile)
3788
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 except Exception as e:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.disp(f"can't unblock entities: {e}", error=True)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 else:
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.host.quit(C.EXIT_OK)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
123
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 class Blocking(base.CommandBase):
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 subcommands = (List, Block, Unblock)
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
12317ba98d99 cli: new `blocking` commands:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def __init__(self, host):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
129 super().__init__(host, "blocking", use_profile=False, help=_("entities blocking"))