annotate sat_frontends/jp/cmd_ticket.py @ 3320:bb92085720c8

plugin XEP-0329: implemented ways to get/set affiliations: PubSub-like affiliations can now be get/set using non standard methods. This has been done to prepare the move to a pubsub based file sharing system.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:12:44 +0200
parents 71761e9fb984
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
51 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
52 await common.fill_well_known_uri(self, os.getcwd(), "tickets", meta_map={})
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 self.disp(f"can't get tickets: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70 await self.output(tickets_data[0])
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
98 metavar=("NAME", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
107 metavar=("IMPORTED_FIELD", "DEST_FIELD"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
108 help=_(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
109 "specified field in import data will be put in dest field (default: use "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
116 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
117 metavar="PUBSUB_SERVICE",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
124 metavar="PUBSUB_NODE",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
125 help=_(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
126 "PubSub node where the items must be uploaded (default: tickets' "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
134 "importer data location (see importer description), nothing to show "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
139 async def onProgressStarted(self, metadata):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
140 self.disp(_("Tickets upload started"), 2)
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
142 async def onProgressFinished(self, metadata):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
143 self.disp(_("Tickets uploaded successfully"), 2)
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 async def onProgressError(self, error_msg):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
157 "\n".join(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
158 [
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 f"{name}: {desc}"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
170 self.disp(f"can't get importer description: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
177
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
178 if self.args.progress:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
179 # we use a custom progress bar template as we want a counter
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
180 self.pbar_template = [
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
181 _("Progress: "), ["Percentage"], " ", ["Bar"], " ",
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
182 ["Counter"], " ", ["ETA"]
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 ]
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
190 _("fields_map must be specified either preencoded in --option or "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
196 progress_id = await self.host.bridge.ticketsImport(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
197 self.args.importer,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 self.args.location,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
199 options,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
200 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
201 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
202 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
203 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
204 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
205 self.disp(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
206 _(f"Error while trying to import tickets: {e}"),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
207 error=True,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
208 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
209 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
210 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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 )