annotate sat_frontends/jp/cmd_ticket.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2761
diff changeset
5 # Copyright (C) 2009-2019 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
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from . import base
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23 from sat_frontends.jp import common
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24 from sat_frontends.jp.constants import Const as C
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
25 from functools import partial
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import json
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
27 import os
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 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
47 self.need_loop = True
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 def add_parser_options(self):
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 pass
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 def ticketsGetCb(self, tickets_data):
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 self.output(tickets_data[0])
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 self.host.quit(C.EXIT_OK)
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 def getTickets(self):
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 self.host.bridge.ticketsGet(
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 self.args.service,
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self.args.node,
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 self.args.max,
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.args.items,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
62 "",
2761
4b693ea24d5f jp (base, pubsub, ticket): handle order-by:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
63 self.getPubsubExtra(),
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 self.profile,
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 callback=self.ticketsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
66 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
67 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
68 msg=_("can't get tickets: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
69 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
70 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
71 )
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 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
74 common.URIFinder(self, os.getcwd(), "tickets", self.getTickets, meta_map={})
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 class Import(base.CommandAnswering):
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 # TODO: factorize with blog/import
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
81 super(Import, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
82 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
83 "import",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
84 use_progress=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
85 help=_("import tickets from external software/dataset"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
86 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
87 self.need_loop = True
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
90 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
91 "importer",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
92 nargs="?",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
93 help=_("importer name, nothing to display importers list"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
94 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
95 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
96 "-o",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
97 "--option",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
98 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
99 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
100 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 metavar=("NAME", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
102 help=_("importer specific options (see importer description)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
103 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
104 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
105 "-m",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
106 "--map",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
107 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
108 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
109 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
110 metavar=("IMPORTED_FIELD", "DEST_FIELD"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
111 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
112 "specified field in import data will be put in dest field (default: use 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
113 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
114 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
115 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
116 "-s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
117 "--service",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
118 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
119 metavar="PUBSUB_SERVICE",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
120 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
121 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
122 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
123 "-n",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
124 "--node",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
125 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
126 metavar="PUBSUB_NODE",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
127 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
128 "PubSub node where the items must be uploaded (default: tickets' defaults)"
2624
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 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
131 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
132 "location",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
133 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
134 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 "importer data location (see importer description), nothing to show 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
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 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
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 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
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def onProgressError(self, error_msg):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
146 self.disp(_("Error while uploading tickets: {}").format(error_msg), error=True)
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 def error(self, failure):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
149 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
150 _("Error while trying to upload tickets: {reason}").format(reason=failure),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
151 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
152 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self.host.quit(1)
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 def start(self):
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if self.args.location is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
157 for name in ("option", "service", "node"):
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 if getattr(self.args, name):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
159 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
160 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161 "{name} argument can't be used without location argument"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
162 ).format(name=name)
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 if self.args.importer is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
165 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
166 "\n".join(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
167 [
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
168 "{}: {}".format(name, desc)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
169 for name, desc in self.host.bridge.ticketsImportList()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
170 ]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
171 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
172 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 else:
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
175 short_desc, long_desc = self.host.bridge.ticketsImportDesc(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
176 self.args.importer
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
177 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 except Exception as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
179 msg = [l for l in str(e).split("\n") if l][
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
180 -1
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
181 ] # we only keep the last line
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 self.disp(msg)
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.host.quit(1)
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
185 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
186 "{name}: {short_desc}\n\n{long_desc}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
187 name=self.args.importer,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
188 short_desc=short_desc,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
189 long_desc=long_desc,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
190 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
191 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 self.host.quit()
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 else:
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 # we have a location, an import is requested
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 options = {key: value for key, value in self.args.option}
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 fields_map = dict(self.args.map)
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 if fields_map:
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 if FIELDS_MAP in options:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
199 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
200 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
201 "fields_map must be specified either preencoded in --option or using --map, but not both at the same time"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
202 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
203 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 options[FIELDS_MAP] = json.dumps(fields_map)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
205
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 def gotId(id_):
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.progress_id = id_
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
208
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
209 self.host.bridge.ticketsImport(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
210 self.args.importer,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
211 self.args.location,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
212 options,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
213 self.args.service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
214 self.args.node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
215 self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
216 callback=gotId,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
217 errback=self.error,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
218 )
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 class Ticket(base.CommandBase):
2602
41db2f58c753 jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 subcommands = (Get, Import)
2374
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
686f84ebb670 jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
225 super(Ticket, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
226 host, "ticket", use_profile=False, help=_("tickets handling")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2602
diff changeset
227 )