annotate frontends/src/jp/cmd_merge_request.py @ 2546:48820e4a1f8a

plugin merge-requests: fixed labels (they were using textbox instead of list)
author Goffi <goffi@goffi.org>
date Fri, 30 Mar 2018 19:49:35 +0200
parents 2df1ca79cb30
children b27165bf160c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2450
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
24 from sat_frontends.jp import xmlui_manager
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from functools import partial
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import os.path
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 __commands__ = ["MergeRequest"]
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class Set(base.CommandBase):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def __init__(self, host):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 base.CommandBase.__init__(self, host, 'set', use_pubsub=True, help=_(u'publish or update a merge request'))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.need_loop=True
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def add_parser_options(self):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.parser.add_argument("-i", "--item", type=base.unicode_decoder, default=u'', help=_(u"id or URL of the request to update, or nothing for a new one"))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)"))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def mergeRequestSetCb(self, published_id):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 if published_id:
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 else:
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.disp(u"Merge request published")
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.host.quit(C.EXIT_OK)
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def start(self):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 repository = os.path.expanduser(os.path.abspath(self.args.repository))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 extra = {'update': 'true'} if self.args.item else {}
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.host.bridge.mergeRequestSet(
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.args.service,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.args.node,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 repository,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 u'auto',
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 {},
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 u'',
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.args.item,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 extra,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.profile,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 callback=self.mergeRequestSetCb,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 errback=partial(self.errback,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 msg=_(u"can't create merge request: {}"),
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 exit_code=C.EXIT_BRIDGE_ERRBACK))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
67 class Get(base.CommandBase):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
68
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
69 def __init__(self, host):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
70 base.CommandBase.__init__(self, host, 'get', use_pubsub=True, pubsub_flags={C.MULTI_ITEMS}, use_verbose=True, help=_(u'get a merge request'))
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
71 self.need_loop=True
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
72
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
73 def add_parser_options(self):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
74 pass
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
75
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
76 def mergeRequestGetCb(self, requests_data):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
77 if self.verbosity >= 1:
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
78 whitelist = None
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
79 else:
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
80 whitelist = {'id', 'title', 'body'}
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
81 for request_xmlui in requests_data[0]:
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
82 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist)
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
83 xmlui.show(values_only=True)
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
84 self.host.quit(C.EXIT_OK)
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
85
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
86 def start(self):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
87 extra = {}
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
88 self.host.bridge.mergeRequestsGet(
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
89 self.args.service,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
90 self.args.node,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
91 self.args.max,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
92 self.args.items,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
93 u'',
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
94 extra,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
95 self.profile,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
96 callback=self.mergeRequestGetCb,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
97 errback=partial(self.errback,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
98 msg=_(u"can't get merge request: {}"),
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
99 exit_code=C.EXIT_BRIDGE_ERRBACK))
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
100
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
101
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
102
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
103 class Import(base.CommandBase):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
104
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
105 def __init__(self, host):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
106 base.CommandBase.__init__(self, host, 'import', use_pubsub=True, pubsub_flags={C.SINGLE_ITEM}, help=_(u'import a merge request'))
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
107 self.need_loop=True
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
108
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
109 def add_parser_options(self):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
110 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)"))
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
111
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
112 def mergeRequestImportCb(self):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
113 self.host.quit(C.EXIT_OK)
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
114
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
115 def start(self):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
116 repository = os.path.expanduser(os.path.abspath(self.args.repository))
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
117 extra = {}
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
118 self.host.bridge.mergeRequestsImport(
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
119 repository,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
120 self.args.item,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
121 self.args.service,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
122 self.args.node,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
123 extra,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
124 self.profile,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
125 callback=self.mergeRequestImportCb,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
126 errback=partial(self.errback,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
127 msg=_(u"can't import merge request: {}"),
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
128 exit_code=C.EXIT_BRIDGE_ERRBACK))
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
129
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
130
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 class MergeRequest(base.CommandBase):
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
132 subcommands = (Set, Get, Import)
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def __init__(self, host):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 super(MergeRequest, self).__init__(host, 'merge-request', use_profile=False, help=_('merge-request management'))