annotate sat_frontends/jp/cmd_list.py @ 3563:267e4987b58b

doc: fix remaining SàT references/typos + add `libervia-cli` missing commands
author Goffi <goffi@goffi.org>
date Fri, 11 Jun 2021 09:21:41 +0200
parents 059742e925f2
children 04283582966f
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
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
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
76 def __init__(self, host):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
77 base.CommandBase.__init__(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
78 self,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
79 host,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
80 "set",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
81 use_pubsub=True,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
82 pubsub_defaults={"service": _("auto"), "node": _("auto")},
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
83 help=_("set a list item"),
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
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
86 def add_parser_options(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
87 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
88 "-f",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
89 "--field",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
90 action="append",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
91 nargs="+",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
92 dest="fields",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 required=True,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 metavar=("NAME", "VALUES"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
95 help=_("field(s) to set (required)"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
96 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
98 "-U",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 "--update",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
100 choices=("auto", "true", "false"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
101 default="auto",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
102 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
103 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
105 "item",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 nargs="?",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 default="",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 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
109 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
110
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 async def start(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
112 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
113 if self.args.update == "auto":
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
114 # 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
115 update = bool(self.args.item)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
116 else:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
117 update = C.bool(self.args.update)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
119 values = {}
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
121 for field_data in self.args.fields:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 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
123
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
124 extra = {"update": update}
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
126 try:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
127 item_id = await self.host.bridge.listSet(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
128 self.args.service,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
129 self.args.node,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
130 values,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
131 '',
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
132 self.args.item,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
133 data_format.serialise(extra),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
134 self.profile
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
135 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
136 except Exception as e:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
137 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
138 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
139 else:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
140 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
141 self.host.quit(C.EXIT_OK)
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
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
144 class Delete(base.CommandBase):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
146 def __init__(self, host):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
147 base.CommandBase.__init__(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
148 self,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
149 host,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
150 "delete",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
151 use_pubsub=True,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
152 pubsub_defaults={"service": _("auto"), "node": _("auto")},
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
153 help=_("delete a list item"),
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
154 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
156 def add_parser_options(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
157 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
158 "-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
159 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
160 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
161 "-N", "--notify", action="store_true", help=_("notify deletion")
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 self.parser.add_argument(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
164 "item",
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
165 help=_("id of the item to delete"),
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
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
168 async def start(self):
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
169 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
170 if not self.args.item:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 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
172 if not self.args.force:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
173 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
174 item_id=self.args.item
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
175 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
176 await self.host.confirmOrQuit(message, _("item deletion cancelled"))
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
177 try:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
178 await self.host.bridge.listDeleteItem(
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
179 self.args.service,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
180 self.args.node,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
181 self.args.item,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
182 self.args.notify,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
183 self.profile,
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
184 )
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
185 except Exception as e:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
186 self.disp(_(f"can't delete item: {e}"), error=True)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
187 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
188 else:
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
189 self.disp(_(f"item {self.args.item} has been deleted"))
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
190 self.host.quit(C.EXIT_OK)
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
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
193 class Import(base.CommandBase):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
194 # TODO: factorize with blog/import
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
195
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
196 def __init__(self, host):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
197 super(Import, self).__init__(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
198 host,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "import",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
200 use_progress=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
201 use_verbose=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
202 help=_("import tickets from external software/dataset"),
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
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
205 def add_parser_options(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
206 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
207 "importer",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
208 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
209 help=_("importer name, nothing to display importers list"),
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 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
212 "-o",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
213 "--option",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
214 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
215 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
216 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
217 metavar=("NAME", "VALUE"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
218 help=_("importer specific options (see importer description)"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
219 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
220 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
221 "-m",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
222 "--map",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
223 action="append",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
224 nargs=2,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
225 default=[],
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
226 metavar=("IMPORTED_FIELD", "DEST_FIELD"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
227 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
228 "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
229 "same field name, or ignore if it doesn't exist)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
230 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
231 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
232 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
233 "-s",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
234 "--service",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
235 default="",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
236 metavar="PUBSUB_SERVICE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
237 help=_("PubSub service where the items must be uploaded (default: server)"),
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 "-n",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
241 "--node",
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_NODE",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
244 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
245 "PubSub node where the items must be uploaded (default: tickets' "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
246 "defaults)"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
247 ),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
248 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
249 self.parser.add_argument(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
250 "location",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
251 nargs="?",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
252 help=_(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
253 "importer data location (see importer description), nothing to show "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
254 "importer description"
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 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
257
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
258 async def onProgressStarted(self, metadata):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
259 self.disp(_("Tickets upload started"), 2)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
260
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
261 async def onProgressFinished(self, metadata):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.disp(_("Tickets uploaded successfully"), 2)
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 async def onProgressError(self, error_msg):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
265 self.disp(_(f"Error while uploading tickets: {error_msg}"), error=True)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
266
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
267 async def start(self):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
268 if self.args.location is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
269 # no location, the list of importer or description is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
270 for name in ("option", "service", "node"):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
271 if getattr(self.args, name):
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
272 self.parser.error(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
273 _(f"{name} argument can't be used without location argument"))
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
274 if self.args.importer is None:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
275 self.disp(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
276 "\n".join(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
277 [
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
278 f"{name}: {desc}"
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
279 for name, desc in await self.host.bridge.ticketsImportList()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
280 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
281 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
282 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
283 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
284 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
285 short_desc, long_desc = await self.host.bridge.ticketsImportDesc(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
286 self.args.importer
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
287 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
288 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
289 self.disp(f"can't get importer description: {e}", error=True)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
290 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
291 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
292 self.disp(f"{name}: {short_desc}\n\n{long_desc}")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
293 self.host.quit()
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
294 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
295 # we have a location, an import is requested
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
296
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
297 if self.args.progress:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
298 # we use a custom progress bar template as we want a counter
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
299 self.pbar_template = [
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
300 _("Progress: "), ["Percentage"], " ", ["Bar"], " ",
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
301 ["Counter"], " ", ["ETA"]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
302 ]
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
303
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
304 options = {key: value for key, value in self.args.option}
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
305 fields_map = dict(self.args.map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
306 if fields_map:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
307 if FIELDS_MAP in options:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
308 self.parser.error(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
309 _("fields_map must be specified either preencoded in --option or "
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
310 "using --map, but not both at the same time")
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
311 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
312 options[FIELDS_MAP] = json.dumps(fields_map)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
313
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
314 try:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
315 progress_id = await self.host.bridge.ticketsImport(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
316 self.args.importer,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
317 self.args.location,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
318 options,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
319 self.args.service,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
320 self.args.node,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
321 self.profile,
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 except Exception as e:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
324 self.disp(
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
325 _(f"Error while trying to import tickets: {e}"),
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
326 error=True,
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
327 )
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
328 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
329 else:
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
330 await self.set_progress_id(progress_id)
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
331
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
332
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
333 class List(base.CommandBase):
3510
059742e925f2 jp (list): implement `set` and `delete` subcommands.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
334 subcommands = (Get, Set, Delete, Import)
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
335
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
336 def __init__(self, host):
3459
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
337 super(List, self).__init__(
8dc26e5edcd3 plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents: 3458
diff changeset
338 host, "list", use_profile=False, help=_("pubsub lists handling")
3458
b68346a52920 Backed out changeset 6deea0d8d0e7
Goffi <goffi@goffi.org>
parents:
diff changeset
339 )