Mercurial > libervia-backend
annotate libervia/cli/cmd_list.py @ 4118:07370d2a9bde
plugin XEP-0167: keep media order when starting a call:
media content order is relevant when building Jingle contents/SDP notably for bundling.
This patch fixes the previous behaviour of always using the same order by keeping the
order of the data (i.e. order of original SDP offer). Previous behaviour could lead to
call failure.
rel 424
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Oct 2023 15:15:24 +0200 |
parents | 47401850dec6 |
children | 89a0999884ac |
rev | line source |
---|---|
3458 | 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 |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3458 | 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 |
3458 | 27 from . import base |
28 | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
29 __commands__ = ["List"] |
3458 | 30 |
31 FIELDS_MAP = "mapping" | |
32 | |
33 | |
34 class Get(base.CommandBase): | |
35 def __init__(self, host): | |
36 base.CommandBase.__init__( | |
37 self, | |
38 host, | |
39 "get", | |
40 use_verbose=True, | |
41 use_pubsub=True, | |
42 pubsub_flags={C.MULTI_ITEMS}, | |
43 pubsub_defaults={"service": _("auto"), "node": _("auto")}, | |
44 use_output=C.OUTPUT_LIST_XMLUI, | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
45 help=_("get lists"), |
3458 | 46 ) |
47 | |
48 def add_parser_options(self): | |
49 pass | |
50 | |
51 async def start(self): | |
52 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={}) | |
53 try: | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
54 lists_data = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
55 await self.host.bridge.list_get( |
3458 | 56 self.args.service, |
57 self.args.node, | |
58 self.args.max, | |
59 self.args.items, | |
60 "", | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
61 self.get_pubsub_extra(), |
3458 | 62 self.profile, |
63 ), | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
64 type_check=list, |
3458 | 65 ) |
66 except Exception as e: | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
67 self.disp(f"can't get lists: {e}", error=True) |
3458 | 68 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
69 else: | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
70 await self.output(lists_data[0]) |
3458 | 71 self.host.quit(C.EXIT_OK) |
72 | |
73 | |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
74 class Set(base.CommandBase): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
75 def __init__(self, host): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
76 base.CommandBase.__init__( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
77 self, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
78 host, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
79 "set", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
80 use_pubsub=True, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
81 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
82 help=_("set a list item"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
83 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
84 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
85 def add_parser_options(self): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
86 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
87 "-f", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
88 "--field", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
89 action="append", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
90 nargs="+", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
91 dest="fields", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
92 required=True, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
93 metavar=("NAME", "VALUES"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
94 help=_("field(s) to set (required)"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
95 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
96 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
97 "-U", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
98 "--update", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
99 choices=("auto", "true", "false"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
100 default="auto", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
101 help=_("update existing item instead of replacing it (DEFAULT: auto)"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
102 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
103 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
104 "item", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
105 nargs="?", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
106 default="", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
107 help=_("id, URL of the item to update, or nothing for new item"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
108 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
109 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
110 async def start(self): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
111 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={}) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
112 if self.args.update == "auto": |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
113 # we update if we have a item id specified |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
114 update = bool(self.args.item) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
115 else: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
116 update = C.bool(self.args.update) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
117 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
118 values = {} |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
119 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
120 for field_data in self.args.fields: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
121 values.setdefault(field_data[0], []).extend(field_data[1:]) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
122 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
123 extra = {"update": update} |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
124 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
125 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
126 item_id = await self.host.bridge.list_set( |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 self.args.service, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 self.args.node, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
129 values, |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
130 "", |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
131 self.args.item, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
132 data_format.serialise(extra), |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
133 self.profile, |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
134 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
135 except Exception as e: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
136 self.disp(f"can't set list item: {e}", error=True) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
137 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
138 else: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
139 self.disp(f"item {str(item_id or self.args.item)!r} set successfully") |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
140 self.host.quit(C.EXIT_OK) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
141 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
142 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
143 class Delete(base.CommandBase): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
144 def __init__(self, host): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
145 base.CommandBase.__init__( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
146 self, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
147 host, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
148 "delete", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
149 use_pubsub=True, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
150 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
151 help=_("delete a list item"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
152 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
153 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
154 def add_parser_options(self): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
155 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
156 "-f", "--force", action="store_true", help=_("delete without confirmation") |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
157 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
158 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
159 "-N", "--notify", action="store_true", help=_("notify deletion") |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
160 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
161 self.parser.add_argument( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
162 "item", |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
163 help=_("id of the item to delete"), |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
164 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
165 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
166 async def start(self): |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
167 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={}) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
168 if not self.args.item: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
169 self.parser.error(_("You need to specify a list item to delete")) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
170 if not self.args.force: |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
171 message = _("Are you sure to delete list item {item_id} ?").format( |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
172 item_id=self.args.item |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
173 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
174 await self.host.confirm_or_quit(message, _("item deletion cancelled")) |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
175 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
176 await self.host.bridge.list_delete_item( |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
177 self.args.service, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
178 self.args.node, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
179 self.args.item, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
180 self.args.notify, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
181 self.profile, |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
182 ) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
183 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
184 self.disp(_("can't delete item: {e}").format(e=e), error=True) |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
185 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
186 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
187 self.disp(_("item {item} has been deleted").format(item=self.args.item)) |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
188 self.host.quit(C.EXIT_OK) |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
189 |
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
190 |
3458 | 191 class Import(base.CommandBase): |
192 # TODO: factorize with blog/import | |
193 | |
194 def __init__(self, host): | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
195 super().__init__( |
3458 | 196 host, |
197 "import", | |
198 use_progress=True, | |
199 use_verbose=True, | |
200 help=_("import tickets from external software/dataset"), | |
201 ) | |
202 | |
203 def add_parser_options(self): | |
204 self.parser.add_argument( | |
205 "importer", | |
206 nargs="?", | |
207 help=_("importer name, nothing to display importers list"), | |
208 ) | |
209 self.parser.add_argument( | |
210 "-o", | |
211 "--option", | |
212 action="append", | |
213 nargs=2, | |
214 default=[], | |
215 metavar=("NAME", "VALUE"), | |
216 help=_("importer specific options (see importer description)"), | |
217 ) | |
218 self.parser.add_argument( | |
219 "-m", | |
220 "--map", | |
221 action="append", | |
222 nargs=2, | |
223 default=[], | |
224 metavar=("IMPORTED_FIELD", "DEST_FIELD"), | |
225 help=_( | |
226 "specified field in import data will be put in dest field (default: use " | |
227 "same field name, or ignore if it doesn't exist)" | |
228 ), | |
229 ) | |
230 self.parser.add_argument( | |
231 "-s", | |
232 "--service", | |
233 default="", | |
234 metavar="PUBSUB_SERVICE", | |
235 help=_("PubSub service where the items must be uploaded (default: server)"), | |
236 ) | |
237 self.parser.add_argument( | |
238 "-n", | |
239 "--node", | |
240 default="", | |
241 metavar="PUBSUB_NODE", | |
242 help=_( | |
243 "PubSub node where the items must be uploaded (default: tickets' " | |
244 "defaults)" | |
245 ), | |
246 ) | |
247 self.parser.add_argument( | |
248 "location", | |
249 nargs="?", | |
250 help=_( | |
251 "importer data location (see importer description), nothing to show " | |
252 "importer description" | |
253 ), | |
254 ) | |
255 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
256 async def on_progress_started(self, metadata): |
3458 | 257 self.disp(_("Tickets upload started"), 2) |
258 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
259 async def on_progress_finished(self, metadata): |
3458 | 260 self.disp(_("Tickets uploaded successfully"), 2) |
261 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
262 async def on_progress_error(self, error_msg): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
263 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
264 _("Error while uploading tickets: {error_msg}").format(error_msg=error_msg), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
265 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
266 ) |
3458 | 267 |
268 async def start(self): | |
269 if self.args.location is None: | |
270 # no location, the list of importer or description is requested | |
271 for name in ("option", "service", "node"): | |
272 if getattr(self.args, name): | |
273 self.parser.error( | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
274 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
275 "{name} argument can't be used without location argument" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
276 ).format(name=name) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
277 ) |
3458 | 278 if self.args.importer is None: |
279 self.disp( | |
280 "\n".join( | |
281 [ | |
282 f"{name}: {desc}" | |
283 for name, desc in await self.host.bridge.ticketsImportList() | |
284 ] | |
285 ) | |
286 ) | |
287 else: | |
288 try: | |
289 short_desc, long_desc = await self.host.bridge.ticketsImportDesc( | |
290 self.args.importer | |
291 ) | |
292 except Exception as e: | |
293 self.disp(f"can't get importer description: {e}", error=True) | |
294 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
295 else: | |
296 self.disp(f"{name}: {short_desc}\n\n{long_desc}") | |
297 self.host.quit() | |
298 else: | |
299 # we have a location, an import is requested | |
300 | |
301 if self.args.progress: | |
302 # we use a custom progress bar template as we want a counter | |
303 self.pbar_template = [ | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
304 _("Progress: "), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
305 ["Percentage"], |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
306 " ", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
307 ["Bar"], |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
308 " ", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
309 ["Counter"], |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
310 " ", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
311 ["ETA"], |
3458 | 312 ] |
313 | |
314 options = {key: value for key, value in self.args.option} | |
315 fields_map = dict(self.args.map) | |
316 if fields_map: | |
317 if FIELDS_MAP in options: | |
318 self.parser.error( | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
319 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
320 "fields_map must be specified either preencoded in --option or " |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
321 "using --map, but not both at the same time" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
322 ) |
3458 | 323 ) |
324 options[FIELDS_MAP] = json.dumps(fields_map) | |
325 | |
326 try: | |
327 progress_id = await self.host.bridge.ticketsImport( | |
328 self.args.importer, | |
329 self.args.location, | |
330 options, | |
331 self.args.service, | |
332 self.args.node, | |
333 self.profile, | |
334 ) | |
335 except Exception as e: | |
336 self.disp( | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3510
diff
changeset
|
337 _("Error while trying to import tickets: {e}").format(e=e), |
3458 | 338 error=True, |
339 ) | |
340 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
341 else: | |
342 await self.set_progress_id(progress_id) | |
343 | |
344 | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
345 class List(base.CommandBase): |
3510
059742e925f2
jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
346 subcommands = (Get, Set, Delete, Import) |
3458 | 347 |
348 def __init__(self, host): | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
349 super(List, self).__init__( |
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
350 host, "list", use_profile=False, help=_("pubsub lists handling") |
3458 | 351 ) |