Mercurial > libervia-backend
comparison libervia/cli/base.py @ 4327:554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
- Former bookmarks implementation is now labeled as "legacy".
- XEP-0402 is now used for bookmarks when relevant namespaces are found, and it fallbacks
to legacy XEP-0048/XEP-0049 bookmarks otherwise.
- CLI legacy bookmark commands have been moved to `bookmarks legacy`
- CLI bookmarks commands now use the new XEP-0402 (with fallback to legacy one
automatically used if necessary).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Nov 2024 11:43:27 +0100 |
parents | 0d7bb4df2343 |
children |
comparison
equal
deleted
inserted
replaced
4326:5fd6a4dc2122 | 4327:554a87ae17a6 |
---|---|
14 # GNU Affero General Public License for more details. | 14 # GNU Affero General Public License for more details. |
15 | 15 |
16 # You should have received a copy of the GNU Affero General Public License | 16 # You should have received a copy of the GNU Affero General Public License |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 import argparse | |
19 import asyncio | 20 import asyncio |
20 from libervia.backend.core.i18n import _ | 21 from collections import OrderedDict |
21 | 22 from glob import iglob |
22 ### logging ### | 23 from importlib import import_module |
24 import inspect | |
23 import logging as log | 25 import logging as log |
24 | |
25 log.basicConfig(level=log.WARNING, format="[%(name)s] %(message)s") | |
26 ### | |
27 | |
28 import sys | |
29 import os | 26 import os |
30 import os.path | 27 import os.path |
31 import argparse | 28 from pathlib import Path |
32 import inspect | 29 import sys |
30 import termios | |
33 import tty | 31 import tty |
34 import termios | |
35 from pathlib import Path | |
36 from glob import iglob | |
37 from typing import Optional, Set, Union | 32 from typing import Optional, Set, Union |
38 from importlib import import_module | 33 import xml.etree.ElementTree as ET |
39 from libervia.frontends.tools.jid import JID | 34 |
35 from rich import console | |
36 | |
37 from libervia.backend.core import exceptions | |
38 from libervia.backend.core.i18n import _ | |
40 from libervia.backend.tools import config | 39 from libervia.backend.tools import config |
41 from libervia.backend.tools.common import dynamic_import | 40 from libervia.backend.tools.common import dynamic_import |
42 from libervia.backend.tools.common import uri | 41 from libervia.backend.tools.common import uri |
43 from libervia.backend.tools.common import date_utils | 42 from libervia.backend.tools.common import date_utils |
44 from libervia.backend.tools.common import utils | 43 from libervia.backend.tools.common import utils |
45 from libervia.backend.tools.common import data_format | 44 from libervia.backend.tools.common import data_format |
46 from libervia.backend.tools.common.ansi import ANSI as A | 45 from libervia.backend.tools.common.ansi import ANSI as A |
47 from libervia.backend.core import exceptions | |
48 import libervia.cli | 46 import libervia.cli |
47 from libervia.cli.constants import Const as C | |
49 from libervia.cli.loops import QuitException, get_libervia_cli_loop | 48 from libervia.cli.loops import QuitException, get_libervia_cli_loop |
50 from libervia.cli.constants import Const as C | |
51 from libervia.frontends.bridge.bridge_frontend import BridgeException | 49 from libervia.frontends.bridge.bridge_frontend import BridgeException |
52 from libervia.frontends.tools import aio, misc | 50 from libervia.frontends.tools import aio, misc |
53 import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI | 51 from libervia.frontends.tools.jid import JID |
54 from collections import OrderedDict | 52 |
55 from rich import console | 53 log.basicConfig(level=log.WARNING, format="[%(name)s] %(message)s") |
54 ### | |
55 | |
56 | |
56 | 57 |
57 ## bridge handling | 58 ## bridge handling |
58 # we get bridge name from conf and initialise the right class accordingly | 59 # we get bridge name from conf and initialise the right class accordingly |
59 main_config = config.parse_main_conf() | 60 main_config = config.parse_main_conf() |
60 bridge_name = config.config_get(main_config, "", "bridge", "dbus") | 61 bridge_name = config.config_get(main_config, "", "bridge", "dbus") |
87 PROGRESS_DELAY = 0.1 # the progression will be checked every PROGRESS_DELAY s | 88 PROGRESS_DELAY = 0.1 # the progression will be checked every PROGRESS_DELAY s |
88 | 89 |
89 | 90 |
90 def date_decoder(arg): | 91 def date_decoder(arg): |
91 return date_utils.date_parse_ext(arg, default_tz=date_utils.TZ_LOCAL) | 92 return date_utils.date_parse_ext(arg, default_tz=date_utils.TZ_LOCAL) |
93 | |
94 def optional_bool_decoder(arg: str) -> bool: | |
95 """Decode an optional string to a boolean value. | |
96 | |
97 @param value: The input string to decode. | |
98 @return: The decoded boolean value. | |
99 @raise ValueError: If the input string is not a valid boolean representation. | |
100 """ | |
101 lower_arg = arg.lower() | |
102 if lower_arg in ['true', '1', 't', 'y', 'yes']: | |
103 return True | |
104 elif lower_arg in ['false', '0', 'f', 'n', 'no']: | |
105 return False | |
106 else: | |
107 raise ValueError(f"Invalid boolean value: {arg}") | |
92 | 108 |
93 | 109 |
94 class LiberviaCli: | 110 class LiberviaCli: |
95 """ | 111 """ |
96 This class can be use to establish a connection with the | 112 This class can be use to establish a connection with the |