annotate libervia/cli/cmd_list.py @ 4340:ea72364131d5 default tip @

doc (components): Update Email Gateway documentation: A section has been added to explain how attachments are handled. fix 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:53:18 +0100
parents 89a0999884ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b68346a52920 Backed out changeset 6deea0d8d0e7
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: 3459
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
6
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
11
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
16
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
19
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
20
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import json
b68346a52920 Backed out changeset 6deea0d8d0e7
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
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from . import base
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
28
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
29 __commands__ = ["List"]
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
30
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
31 FIELDS_MAP = "mapping"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
32
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
33
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
34 class Get(base.CommandBase):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def __init__(self, host):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
36 base.CommandBase.__init__(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
38 host,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
39 "get",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
40 use_verbose=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
41 use_pubsub=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
42 pubsub_flags={C.MULTI_ITEMS},
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
43 pubsub_defaults={"service": _("auto"), "node": _("auto")},
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
46 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
47
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def add_parser_options(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
49 pass
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
50
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
51 async def start(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
52 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={})
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.args.service,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.args.node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.args.max,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.args.items,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.profile,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
63 ),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
64 type_check=list,
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
65 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.host.quit(C.EXIT_OK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
72
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
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(
4272
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
104 "-C",
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
105 "--comments",
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
106 choices=("auto", "true", "false"),
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
107 default="auto",
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
108 help=_("create comments node (DEFAULT: auto)"),
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
109 )
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
110 self.parser.add_argument(
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 "item",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
112 nargs="?",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
113 default="",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
114 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
115 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
116
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
117 async def start(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118 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
119 if self.args.update == "auto":
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120 # 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
121 update = bool(self.args.item)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 else:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
123 update = C.bool(self.args.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 values = {}
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
126
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
127 for field_data in self.args.fields:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
128 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
129
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
130 extra = {"update": update}
4272
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
131 if self.args.comments != "auto":
89a0999884ac cli (list/set): add "--comments" argument.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
132 extra["comments"] = bool(self.args.comments)
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
133
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
134 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
135 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
136 self.args.service,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
137 self.args.node,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
138 values,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
139 "",
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
140 self.args.item,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
141 data_format.serialise(extra),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
142 self.profile,
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
144 except Exception as e:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145 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
146 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
147 else:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
148 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
149 self.host.quit(C.EXIT_OK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
150
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
151
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
152 class Delete(base.CommandBase):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
153 def __init__(self, host):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
154 base.CommandBase.__init__(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155 self,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
156 host,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
157 "delete",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
158 use_pubsub=True,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
159 pubsub_defaults={"service": _("auto"), "node": _("auto")},
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
160 help=_("delete a list item"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
161 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
162
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
163 def add_parser_options(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
164 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
165 "-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
166 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
167 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
168 "-N", "--notify", action="store_true", help=_("notify deletion")
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
169 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
170 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 "item",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
172 help=_("id of the item to delete"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
173 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
174
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
175 async def start(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
176 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
177 if not self.args.item:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
178 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
179 if not self.args.force:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
180 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
181 item_id=self.args.item
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
182 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
183 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
184 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
185 await self.host.bridge.list_delete_item(
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
186 self.args.service,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
187 self.args.node,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
188 self.args.item,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
189 self.args.notify,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
190 self.profile,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
191 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
192 except Exception as e:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
193 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
194 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 else:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
196 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
197 self.host.quit(C.EXIT_OK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
198
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
199
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
200 class Import(base.CommandBase):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
201 # TODO: factorize with blog/import
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
202
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
203 def __init__(self, host):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
204 super().__init__(
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
205 host,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
206 "import",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
207 use_progress=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
208 use_verbose=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
209 help=_("import tickets from external software/dataset"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
210 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
211
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
212 def add_parser_options(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
214 "importer",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
215 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
216 help=_("importer name, nothing to display importers list"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
217 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
218 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
219 "-o",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
220 "--option",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
221 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
222 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
223 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
224 metavar=("NAME", "VALUE"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
225 help=_("importer specific options (see importer description)"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
226 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
227 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
228 "-m",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
229 "--map",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
230 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
231 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
232 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
233 metavar=("IMPORTED_FIELD", "DEST_FIELD"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
234 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
235 "specified field in import data will be put in dest field (default: use "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
236 "same field name, or ignore if it doesn't exist)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
237 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
238 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
239 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
240 "-s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
241 "--service",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
242 default="",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
243 metavar="PUBSUB_SERVICE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
244 help=_("PubSub service where the items must be uploaded (default: server)"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
245 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
247 "-n",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
248 "--node",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
249 default="",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
250 metavar="PUBSUB_NODE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
251 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
252 "PubSub node where the items must be uploaded (default: tickets' "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
253 "defaults)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
254 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
255 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
256 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
257 "location",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
258 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
259 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
260 "importer data location (see importer description), nothing to show "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
261 "importer description"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
262 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
263 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
264
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
265 async def on_progress_started(self, metadata):
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self.disp(_("Tickets upload started"), 2)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
267
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
268 async def on_progress_finished(self, metadata):
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
269 self.disp(_("Tickets uploaded successfully"), 2)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
270
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
271 async def on_progress_error(self, error_msg):
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
272 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
273 _("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
274 error=True,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
275 )
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
276
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
277 async def start(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
278 if self.args.location is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
279 # no location, the list of importer or description is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
280 for name in ("option", "service", "node"):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
281 if getattr(self.args, name):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
282 self.parser.error(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
283 _(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
284 "{name} argument can't be used without location argument"
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
285 ).format(name=name)
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
286 )
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
287 if self.args.importer is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
288 self.disp(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
289 "\n".join(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
290 [
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
291 f"{name}: {desc}"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
292 for name, desc in await self.host.bridge.ticketsImportList()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
293 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
294 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
295 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
296 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
297 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
298 short_desc, long_desc = await self.host.bridge.ticketsImportDesc(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
299 self.args.importer
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
300 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
301 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
302 self.disp(f"can't get importer description: {e}", error=True)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
303 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
304 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
305 self.disp(f"{name}: {short_desc}\n\n{long_desc}")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
306 self.host.quit()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
307 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
308 # we have a location, an import is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
309
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
310 if self.args.progress:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
311 # we use a custom progress bar template as we want a counter
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
312 self.pbar_template = [
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
313 _("Progress: "),
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
314 ["Percentage"],
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
315 " ",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
316 ["Bar"],
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
317 " ",
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
318 ["Counter"],
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 ["ETA"],
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
321 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
322
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
323 options = {key: value for key, value in self.args.option}
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
324 fields_map = dict(self.args.map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
325 if fields_map:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
326 if FIELDS_MAP in options:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
327 self.parser.error(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
328 _(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
329 "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
330 "using --map, but not both at the same time"
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
331 )
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
332 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
333 options[FIELDS_MAP] = json.dumps(fields_map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
334
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
335 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
336 progress_id = await self.host.bridge.ticketsImport(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
337 self.args.importer,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
338 self.args.location,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
339 options,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
340 self.args.service,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
341 self.args.node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
342 self.profile,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
343 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
344 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
345 self.disp(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3510
diff changeset
346 _("Error while trying to import tickets: {e}").format(e=e),
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
347 error=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
348 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
349 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
350 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
351 await self.set_progress_id(progress_id)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
352
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
353
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
354 class List(base.CommandBase):
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
355 subcommands = (Get, Set, Delete, Import)
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
356
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
357 def __init__(self, host):
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
358 super(List, self).__init__(
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
359 host, "list", use_profile=False, help=_("pubsub lists handling")
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
360 )