annotate sat_frontends/jp/cmd_list.py @ 3503:482098e521ff

plugin misc account: specify domain in new account email sent to admins
author Goffi <goffi@goffi.org>
date Wed, 21 Apr 2021 11:36:26 +0200
parents be6d91572633
children 059742e925f2
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools.common import data_format
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat_frontends.jp import common
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat_frontends.jp.constants import Const as C
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(
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
55 await self.host.bridge.listGet(
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 "",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.getPubsubExtra(),
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 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
64 type_check=list
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
74 class Import(base.CommandBase):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
75 # TODO: factorize with blog/import
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
76
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def __init__(self, host):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
78 super(Import, self).__init__(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
79 host,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "import",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
81 use_progress=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
82 use_verbose=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
83 help=_("import tickets from external software/dataset"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
84 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
85
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def add_parser_options(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
88 "importer",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
89 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
90 help=_("importer name, nothing to display importers list"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
91 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
93 "-o",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
94 "--option",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
95 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
96 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
97 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
98 metavar=("NAME", "VALUE"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
99 help=_("importer specific options (see importer description)"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
100 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
102 "-m",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
103 "--map",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
104 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
105 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
106 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
107 metavar=("IMPORTED_FIELD", "DEST_FIELD"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
108 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
109 "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
110 "same field name, or ignore if it doesn't exist)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
111 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
112 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
114 "-s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
115 "--service",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
116 default="",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
117 metavar="PUBSUB_SERVICE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
118 help=_("PubSub service where the items must be uploaded (default: server)"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
119 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
121 "-n",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
122 "--node",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
123 default="",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
124 metavar="PUBSUB_NODE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
125 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
126 "PubSub node where the items must be uploaded (default: tickets' "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "defaults)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
128 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
129 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
130 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "location",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
132 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
133 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "importer data location (see importer description), nothing to show "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "importer description"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
136 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
137 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
138
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
139 async def onProgressStarted(self, metadata):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self.disp(_("Tickets upload started"), 2)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
141
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
142 async def onProgressFinished(self, metadata):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
143 self.disp(_("Tickets uploaded successfully"), 2)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
144
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
145 async def onProgressError(self, error_msg):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self.disp(_(f"Error while uploading tickets: {error_msg}"), error=True)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
147
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
148 async def start(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
149 if self.args.location is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
150 # no location, the list of importer or description is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
151 for name in ("option", "service", "node"):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if getattr(self.args, name):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self.parser.error(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
154 _(f"{name} argument can't be used without location argument"))
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if self.args.importer is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self.disp(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
157 "\n".join(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
158 [
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
159 f"{name}: {desc}"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
160 for name, desc in await self.host.bridge.ticketsImportList()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
161 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
162 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
163 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
164 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
165 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
166 short_desc, long_desc = await self.host.bridge.ticketsImportDesc(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
167 self.args.importer
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
168 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
169 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self.disp(f"can't get importer description: {e}", error=True)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
172 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.disp(f"{name}: {short_desc}\n\n{long_desc}")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.host.quit()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
175 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
176 # we have a location, an import is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
177
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
178 if self.args.progress:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
179 # we use a custom progress bar template as we want a counter
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.pbar_template = [
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
181 _("Progress: "), ["Percentage"], " ", ["Bar"], " ",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
182 ["Counter"], " ", ["ETA"]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
183 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
184
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
185 options = {key: value for key, value in self.args.option}
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
186 fields_map = dict(self.args.map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
187 if fields_map:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
188 if FIELDS_MAP in options:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.parser.error(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
190 _("fields_map must be specified either preencoded in --option or "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
191 "using --map, but not both at the same time")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
192 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
193 options[FIELDS_MAP] = json.dumps(fields_map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
194
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
195 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
196 progress_id = await self.host.bridge.ticketsImport(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
197 self.args.importer,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
198 self.args.location,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
199 options,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
200 self.args.service,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
201 self.args.node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.profile,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
203 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
204 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
205 self.disp(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
206 _(f"Error while trying to import tickets: {e}"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
207 error=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
208 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
209 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
210 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
211 await self.set_progress_id(progress_id)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
212
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
213
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
214 class List(base.CommandBase):
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
215 subcommands = (Get, Import)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
216
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
217 def __init__(self, host):
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
218 super(List, self).__init__(
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
219 host, "list", use_profile=False, help=_("pubsub lists handling")
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
220 )