annotate libervia/cli/cmd_bookmarks.py @ 4332:71c939e34ca6

XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author Syndace <me@syndace.dev>
date Sat, 13 Jul 2024 18:28:28 +0200
parents 554a87ae17a6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
986
224cafc67324 jp: added bookmarks subcommands
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
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 JΓ©rΓ΄me Poisson (goffi@goffi.org)
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
6
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
11
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
16
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
20 from rich.table import Table
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
21
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.i18n import _
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
23 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
24 from libervia.cli.constants import Const as C
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
25
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
26 from . import base
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
27 from .bookmarks_legacy import BookmarksLegacy
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
28
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
29 __commands__ = ["Bookmarks"]
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
30
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
31
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
32 class BookmarksList(base.CommandBase):
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
33 def __init__(self, host):
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
34 extra_outputs = {"default": self.default_output}
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
35 super().__init__(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
36 host, "list", help=_("list bookmarks"),
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
37 use_output=C.OUTPUT_COMPLEX,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
38 extra_outputs=extra_outputs
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
39 )
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
40
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
41 def add_parser_options(self):
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
42 pass
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
43
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
44 def default_output(self, data: dict) -> None:
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
45 table = Table(title="πŸ“š " + _("Group Chat Bookmarks"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
46 table.add_column("🌐 JID")
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
47 table.add_column("πŸ“ " + _("Name"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
48 table.add_column("πŸ‘€ " + _("Nick"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
49 table.add_column("πŸ”’ " + _("Password"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
50 table.add_column("πŸšͺ " + _("Joined"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
51
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
52 for jid, conference_data in data.items():
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
53 table.add_row(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
54 str(jid),
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
55 conference_data.get("name", ""),
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
56 conference_data.get("nick", ""),
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
57 conference_data.get("password", ""),
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
58 "βœ…" if conference_data.get("autojoin", False) else "❌"
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
59 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
60
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
61 self.console.print(table)
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
62
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 try:
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
65 data = data_format.deserialise(await self.host.bridge.bookmarks_list(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
66 "", self.host.profile
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
67 ))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 self.disp(f"can't get bookmarks list: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
71 return
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
72
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
73 await self.output(data)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
74 self.host.quit()
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
75
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
76
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
77 class BookmarksRemove(base.CommandBase):
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def __init__(self, host):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
79 super().__init__(host, "remove", help=_("remove a bookmark"))
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
80
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 self.parser.add_argument(
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
83 "bookmark", help=_("jid of the bookmark to remove")
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
84 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 self.parser.add_argument(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
86 "-f",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
87 "--force",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
88 action="store_true",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
89 help=_("delete bookmark without confirmation"),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
91
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
92 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
93 if not self.args.force:
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
94 await self.host.confirm_or_quit(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
95 _("Are you sure to delete the bookmark {bookmark_id!r}?")
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
96 .format(bookmark_id=self.args.bookmark)
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
97 )
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
98
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
99 try:
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
100 await self.host.bridge.bookmark_remove(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
101 self.args.bookmark, self.host.profile
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
102 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 self.disp(_("can't delete bookmark: {e}").format(e=e), error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
105 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
106 else:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 self.disp(_("bookmark deleted"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
108 self.host.quit()
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
109
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
110
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
111 class BookmarksSet(base.CommandBase):
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def __init__(self, host):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
113 super().__init__(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
114 host, "set", help=_("add or update a bookmark")
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
115 )
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
116
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def add_parser_options(self):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
118 self.parser.add_argument("bookmark", help=_("jid of the chat room"))
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
119 self.parser.add_argument("-n", "--name", help=_("bookmark name"), dest="name")
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
120 self.parser.add_argument(
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
121 "-j",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
122 "--join",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
123 nargs="?",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
124 # Value use when option is missing.
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
125 default=None,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
126 # Value use when option is used, but value is not specified.
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
127 const=True,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
128 type=base.optional_bool_decoder,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
129 # The bookmark attribute is called "autojoin" for historical reason, but it's
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
130 # now used a "join" flag, so we use ``join`` here for the option.
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
131 dest="autojoin",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
132 metavar="BOOL",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
133 help=_("join the conference room"),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
134 )
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
135 self.parser.add_argument(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
136 "-N",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
137 "--nick", help=_("preferred roomnick for the chatroom")
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
138 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
139 self.parser.add_argument(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
140 "-P",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
141 "--password", help=_("password used to access the chatroom")
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
142 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
143 self.parser.add_argument(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
144 "-u",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
145 "--update",
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
146 action="store_true",
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
147 help=_("update bookmark data instead of replacing")
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
148 )
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
149
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
150 async def start(self):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
151 conference_data = {
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
152 "autojoin": self.args.autojoin,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
153 "name": self.args.name,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
154 "nick": self.args.nick,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
155 "password": self.args.password,
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
156 }
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
157
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
158 conference_data = {k: v for k, v in conference_data.items() if v is not None}
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
159 if self.args.update:
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
160 try:
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
161 old_conference_data = data_format.deserialise(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
162 await self.host.bridge.bookmark_get(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
163 self.args.bookmark, self.host.profile
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
164 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
165 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
166 except Exception as e:
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
167 self.disp(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
168 f"Can't find existing bookmark {self.args.bookmark!r}: {e}. We "
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
169 "create it.",
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
170 error=True
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
171 )
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
172 else:
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
173 old_conference_data.update(conference_data)
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
174 conference_data = old_conference_data
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
175
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
176 try:
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
177 await self.host.bridge.bookmarks_set(
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
178 data_format.serialise({self.args.bookmark: conference_data}),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
179 self.host.profile,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
180 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
181 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
182 self.disp(f"can't add bookmark: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 else:
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
185 self.disp(_("bookmark successfully set"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 self.host.quit()
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
187
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
188
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
189 class Bookmarks(base.CommandBase):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
190 subcommands = (BookmarksList, BookmarksSet, BookmarksRemove, BookmarksLegacy)
986
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
191
224cafc67324 jp: added bookmarks subcommands
Goffi <goffi@goffi.org>
parents:
diff changeset
192 def __init__(self, host):
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
193 super().__init__(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
194 host, "bookmarks", use_profile=False, help=_("manage bookmarks")
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 )