Mercurial > libervia-backend
annotate libervia/cli/cmd_blocking.py @ 4320:9658c534287e
plugin XEP-0215, XEP-0376: fix bad calls to `hasFeature`:
`hasFeature` was called like blocking code, missing the `await`. This has been fixed, and
is now using the `memory.disco.has_feature` version.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Sep 2024 14:14:38 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3788 | 1 #!/usr/bin/env python3 |
2 | |
3 | |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
3788 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import json | |
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 | 27 from . import base |
28 | |
29 __commands__ = ["Blocking"] | |
30 | |
31 | |
32 class List(base.CommandBase): | |
33 def __init__(self, host): | |
34 super().__init__( | |
35 host, | |
36 "list", | |
37 use_output=C.OUTPUT_LIST, | |
38 help=_("list blocked entities"), | |
39 ) | |
40 | |
41 def add_parser_options(self): | |
42 pass | |
43 | |
44 async def start(self): | |
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 | 47 self.profile, |
48 ) | |
49 except Exception as e: | |
50 self.disp(f"can't get blocked entities: {e}", error=True) | |
51 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
52 else: | |
53 await self.output(blocked_jids) | |
54 self.host.quit(C.EXIT_OK) | |
55 | |
56 | |
57 class Block(base.CommandBase): | |
58 def __init__(self, host): | |
59 super().__init__( | |
60 host, | |
61 "block", | |
62 help=_("block one or more entities"), | |
63 ) | |
64 | |
65 def add_parser_options(self): | |
66 self.parser.add_argument( | |
67 "entities", | |
68 nargs="+", | |
69 metavar="JID", | |
70 help=_("JIDs of entities to block"), | |
71 ) | |
72 | |
73 async def start(self): | |
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 | 76 except Exception as e: |
77 self.disp(f"can't block entities: {e}", error=True) | |
78 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
79 else: | |
80 self.host.quit(C.EXIT_OK) | |
81 | |
82 | |
83 class Unblock(base.CommandBase): | |
84 def __init__(self, host): | |
85 super().__init__( | |
86 host, | |
87 "unblock", | |
88 help=_("unblock one or more entities"), | |
89 ) | |
90 | |
91 def add_parser_options(self): | |
92 self.parser.add_argument( | |
93 "entities", | |
94 nargs="+", | |
95 metavar="JID", | |
96 help=_("JIDs of entities to unblock"), | |
97 ) | |
98 self.parser.add_argument( | |
99 "-f", | |
100 "--force", | |
101 action="store_true", | |
102 help=_('when "all" is used, unblock all entities without confirmation'), | |
103 ) | |
104 | |
105 async def start(self): | |
106 if self.args.entities == ["all"]: | |
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 | 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 | 111 ) |
112 self.args.entities.clear() | |
113 elif self.args.force: | |
114 self.parser.error(_('--force is only allowed when "all" is used as target')) | |
115 | |
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 | 118 except Exception as e: |
119 self.disp(f"can't unblock entities: {e}", error=True) | |
120 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
121 else: | |
122 self.host.quit(C.EXIT_OK) | |
123 | |
124 | |
125 class Blocking(base.CommandBase): | |
126 subcommands = (List, Block, Unblock) | |
127 | |
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")) |