Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_ticket.py @ 3393:2b6f69f6df8c
tools(xml_tools): fixed `<div>` unwrapping + added `parse` instance:
`<div>` unwrapping could fail when a text node was a sibling of the top element (could
easily happen ith a `\n` line feed added by an editor). This is fixed by filtering on
IElement with `elements()`.
A `parse` instance has been added as it is not necessary to create a new `ElementParser`
each time that we want to parse something.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Nov 2020 14:53:15 +0100 |
parents | 71761e9fb984 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # jp: a SàT command line tool |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
21 import json |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
22 import os |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _ |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
24 from sat.tools.common import data_format |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
25 from sat_frontends.jp import common |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
26 from sat_frontends.jp.constants import Const as C |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
27 from . import base |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 __commands__ = ["Ticket"] |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
3028 | 31 FIELDS_MAP = "mapping" |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 class Get(base.CommandBase): |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
36 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
37 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
38 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
39 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
40 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
41 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
42 pubsub_flags={C.MULTI_ITEMS}, |
3028 | 43 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
44 use_output=C.OUTPUT_LIST_XMLUI, |
3028 | 45 help=_("get tickets"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
46 ) |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 def add_parser_options(self): |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 pass |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 |
3040 | 51 async def start(self): |
52 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={}) | |
53 try: | |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
54 tickets_data = data_format.deserialise( |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
55 await self.host.bridge.ticketsGet( |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
56 self.args.service, |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
57 self.args.node, |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
58 self.args.max, |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
59 self.args.items, |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
60 "", |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
61 self.getPubsubExtra(), |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
62 self.profile, |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
63 ), |
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
64 type_check=list |
3040 | 65 ) |
66 except Exception as e: | |
67 self.disp(f"can't get tickets: {e}", error=True) | |
68 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
69 else: | |
70 await self.output(tickets_data[0]) | |
71 self.host.quit(C.EXIT_OK) | |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 |
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 |
3040 | 74 class Import(base.CommandBase): |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 # TODO: factorize with blog/import |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
78 super(Import, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
79 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
80 "import", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
81 use_progress=True, |
3040 | 82 use_verbose=True, |
3028 | 83 help=_("import tickets from external software/dataset"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
84 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
87 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
88 "importer", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
89 nargs="?", |
3028 | 90 help=_("importer name, nothing to display importers list"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
91 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
92 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
93 "-o", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
94 "--option", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
95 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
96 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
97 default=[], |
3028 | 98 metavar=("NAME", "VALUE"), |
99 help=_("importer specific options (see importer description)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
100 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
101 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
102 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
103 "--map", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
104 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
105 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
106 default=[], |
3028 | 107 metavar=("IMPORTED_FIELD", "DEST_FIELD"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
108 help=_( |
3040 | 109 "specified field in import data will be put in dest field (default: use " |
110 "same field name, or ignore if it doesn't exist)" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
111 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
112 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
113 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
114 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
115 "--service", |
3028 | 116 default="", |
117 metavar="PUBSUB_SERVICE", | |
118 help=_("PubSub service where the items must be uploaded (default: server)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
119 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
120 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
121 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
122 "--node", |
3028 | 123 default="", |
124 metavar="PUBSUB_NODE", | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
125 help=_( |
3040 | 126 "PubSub node where the items must be uploaded (default: tickets' " |
127 "defaults)" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
128 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
129 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
130 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
131 "location", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
132 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
133 help=_( |
3040 | 134 "importer data location (see importer description), nothing to show " |
135 "importer description" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
136 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
137 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
3040 | 139 async def onProgressStarted(self, metadata): |
3028 | 140 self.disp(_("Tickets upload started"), 2) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
3040 | 142 async def onProgressFinished(self, metadata): |
3028 | 143 self.disp(_("Tickets uploaded successfully"), 2) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
3040 | 145 async def onProgressError(self, error_msg): |
146 self.disp(_(f"Error while uploading tickets: {error_msg}"), error=True) | |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
3040 | 148 async def start(self): |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 if self.args.location is None: |
3040 | 150 # no location, the list of importer or description is requested |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
151 for name in ("option", "service", "node"): |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 if getattr(self.args, name): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
153 self.parser.error( |
3040 | 154 _(f"{name} argument can't be used without location argument")) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 if self.args.importer is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
156 self.disp( |
3028 | 157 "\n".join( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
158 [ |
3040 | 159 f"{name}: {desc}" |
160 for name, desc in await self.host.bridge.ticketsImportList() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
161 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
162 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
163 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 else: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 try: |
3040 | 166 short_desc, long_desc = await self.host.bridge.ticketsImportDesc( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
167 self.args.importer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
168 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 except Exception as e: |
3040 | 170 self.disp(f"can't get importer description: {e}", error=True) |
171 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 else: |
3040 | 173 self.disp(f"{name}: {short_desc}\n\n{long_desc}") |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 self.host.quit() |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 else: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 # we have a location, an import is requested |
3040 | 177 |
178 if self.args.progress: | |
179 # we use a custom progress bar template as we want a counter | |
180 self.pbar_template = [ | |
181 _("Progress: "), ["Percentage"], " ", ["Bar"], " ", | |
182 ["Counter"], " ", ["ETA"] | |
183 ] | |
184 | |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 options = {key: value for key, value in self.args.option} |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 fields_map = dict(self.args.map) |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 if fields_map: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 if FIELDS_MAP in options: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
189 self.parser.error( |
3040 | 190 _("fields_map must be specified either preencoded in --option or " |
191 "using --map, but not both at the same time") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
192 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 options[FIELDS_MAP] = json.dumps(fields_map) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
194 |
3040 | 195 try: |
196 progress_id = await self.host.bridge.ticketsImport( | |
197 self.args.importer, | |
198 self.args.location, | |
199 options, | |
200 self.args.service, | |
201 self.args.node, | |
202 self.profile, | |
203 ) | |
204 except Exception as e: | |
205 self.disp( | |
206 _(f"Error while trying to import tickets: {e}"), | |
207 error=True, | |
208 ) | |
209 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
210 else: | |
211 await self.set_progress_id(progress_id) | |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 class Ticket(base.CommandBase): |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 subcommands = (Get, Import) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
218 super(Ticket, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
219 host, "ticket", use_profile=False, help=_("tickets handling") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
220 ) |