Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_ticket.py @ 2719:45189c8bd165
jp (message/mam): display metadata when verbose
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 10 Dec 2018 20:34:45 +0100 |
parents | 56f94936df1e |
children | 4b693ea24d5f |
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 |
2483 | 5 # Copyright (C) 2009-2018 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 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import base |
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 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
31 FIELDS_MAP = u"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}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
43 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
44 use_output=C.OUTPUT_LIST_XMLUI, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
45 help=_(u"get tickets"), |
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, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
62 u"", |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 {}, |
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, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
68 msg=_(u"can't get tickets: {}"), |
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, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
85 help=_(u"import tickets from external software/dataset"), |
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 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
93 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
94 help=_(u"importer name, nothing to display importers list"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
95 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
96 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
97 "-o", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
98 "--option", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
99 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
100 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
101 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
102 metavar=(u"NAME", u"VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
103 help=_(u"importer specific options (see importer description)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
104 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
105 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
106 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
107 "--map", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
108 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
109 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
110 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
111 metavar=(u"IMPORTED_FIELD", u"DEST_FIELD"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
112 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
113 u"specified field in import data will be put in dest field (default: use same field name, or ignore if it doesn't exist)" |
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 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
116 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
117 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
118 "--service", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
119 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
120 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
121 metavar=u"PUBSUB_SERVICE", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
122 help=_(u"PubSub service where the items must be uploaded (default: server)"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
123 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
124 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
125 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
126 "--node", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
127 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
128 default=u"", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
129 metavar=u"PUBSUB_NODE", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
130 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
131 u"PubSub node where the items must be uploaded (default: tickets' defaults)" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
132 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
133 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
134 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
135 "location", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
136 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
137 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
138 help=_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
139 u"importer data location (see importer description), nothing to show importer description" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
140 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
141 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 def onProgressStarted(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
144 self.disp(_(u"Tickets upload started"), 2) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 def onProgressFinished(self, metadata): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
147 self.disp(_(u"Tickets uploaded successfully"), 2) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def onProgressError(self, error_msg): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
150 self.disp(_(u"Error while uploading tickets: {}").format(error_msg), error=True) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 def error(self, failure): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
153 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
154 _("Error while trying to upload tickets: {reason}").format(reason=failure), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
155 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
156 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self.host.quit(1) |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 def start(self): |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 if self.args.location is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
161 for name in ("option", "service", "node"): |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 if getattr(self.args, name): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
163 self.parser.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
164 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
165 u"{name} argument can't be used without location argument" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
166 ).format(name=name) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
167 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if self.args.importer is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
169 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
170 u"\n".join( |
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 u"{}: {}".format(name, desc) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
173 for name, desc in self.host.bridge.ticketsImportList() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
174 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
175 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
176 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 else: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
179 short_desc, long_desc = self.host.bridge.ticketsImportDesc( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
180 self.args.importer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
181 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 except Exception as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
183 msg = [l for l in unicode(e).split("\n") if l][ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
184 -1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
185 ] # we only keep the last line |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 self.disp(msg) |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 self.host.quit(1) |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
189 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
190 u"{name}: {short_desc}\n\n{long_desc}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
191 name=self.args.importer, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
192 short_desc=short_desc, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
193 long_desc=long_desc, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
194 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
195 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 self.host.quit() |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 else: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 # we have a location, an import is requested |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 options = {key: value for key, value in self.args.option} |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 fields_map = dict(self.args.map) |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 if fields_map: |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 if FIELDS_MAP in options: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
203 self.parser.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
204 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
205 u"fields_map must be specified either preencoded in --option or using --map, but not both at the same time" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
206 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
207 ) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 options[FIELDS_MAP] = json.dumps(fields_map) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
209 |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 def gotId(id_): |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 self.progress_id = id_ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
212 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
213 self.host.bridge.ticketsImport( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
214 self.args.importer, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
215 self.args.location, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
216 options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
217 self.args.service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
218 self.args.node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
219 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
220 callback=gotId, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
221 errback=self.error, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
222 ) |
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 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 class Ticket(base.CommandBase): |
2602
41db2f58c753
jp (ticket): new "get" subcommand, to retrieve ticket(s)
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 subcommands = (Get, Import) |
2374
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 |
686f84ebb670
jp (ticket): ticket command first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
229 super(Ticket, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
230 host, "ticket", use_profile=False, help=_("tickets handling") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2602
diff
changeset
|
231 ) |