Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_merge_request.py @ 2580:5e54afd17321
quick frontend (chat): added a property to Message which is True when message comes from history
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 10 May 2018 08:34:44 +0200 |
parents | 26edcf3a30eb |
children | 56f94936df1e |
rev | line source |
---|---|
2450 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # jp: a SàT command line tool | |
2483 | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
2450 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import base | |
22 from sat.core.i18n import _ | |
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 |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
25 from sat_frontends.jp import common |
2450 | 26 from functools import partial |
27 import os.path | |
28 | |
29 __commands__ = ["MergeRequest"] | |
30 | |
31 | |
32 class Set(base.CommandBase): | |
33 | |
34 def __init__(self, host): | |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
35 base.CommandBase.__init__(self, host, 'set', use_pubsub=True, |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
36 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
37 help=_(u'publish or update a merge request')) |
2450 | 38 self.need_loop=True |
39 | |
40 def add_parser_options(self): | |
41 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")) | |
42 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)")) | |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
43 self.parser.add_argument("-f", "--force", action="store_true", help=_(u"publish merge request without confirmation")) |
2554
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
44 self.parser.add_argument("-l", "--label", dest="labels", type=base.unicode_decoder, action='append', help=_(u"labels to categorize your request")) |
2450 | 45 |
46 def mergeRequestSetCb(self, published_id): | |
47 if published_id: | |
48 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id)) | |
49 else: | |
50 self.disp(u"Merge request published") | |
51 self.host.quit(C.EXIT_OK) | |
52 | |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
53 def sendRequest(self): |
2450 | 54 extra = {'update': 'true'} if self.args.item else {} |
2554
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
55 values = {} |
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
56 if self.args.labels is not None: |
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
57 values[u'labels'] = self.args.labels |
2450 | 58 self.host.bridge.mergeRequestSet( |
59 self.args.service, | |
60 self.args.node, | |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
61 self.repository, |
2450 | 62 u'auto', |
2554
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
63 values, |
2450 | 64 u'', |
65 self.args.item, | |
66 extra, | |
67 self.profile, | |
68 callback=self.mergeRequestSetCb, | |
69 errback=partial(self.errback, | |
70 msg=_(u"can't create merge request: {}"), | |
71 exit_code=C.EXIT_BRIDGE_ERRBACK)) | |
72 | |
2551
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
73 def askConfirmation(self): |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
74 if not self.args.force: |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
75 message = _(u"You are going to publish your changes to service [{service}], are you sure ?").format( |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
76 service=self.args.service) |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
77 self.host.confirmOrQuit(message, _(u"merge request publication cancelled")) |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
78 self.sendRequest() |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
79 |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
80 def start(self): |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
81 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
82 common.URIFinder(self, self.repository, 'merge requests', self.askConfirmation) |
b27165bf160c
jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents:
2545
diff
changeset
|
83 |
2450 | 84 |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
85 class Get(base.CommandBase): |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
86 |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
87 def __init__(self, host): |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
88 base.CommandBase.__init__(self, host, 'get', use_verbose=True, |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
89 use_pubsub=True, pubsub_flags={C.MULTI_ITEMS}, |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
90 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
91 help=_(u'get a merge request')) |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
92 self.need_loop=True |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
93 |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
94 def add_parser_options(self): |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
95 pass |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
96 |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
97 def mergeRequestGetCb(self, requests_data): |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
98 if self.verbosity >= 1: |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
99 whitelist = None |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
100 else: |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
101 whitelist = {'id', 'title', 'body'} |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
102 for request_xmlui in requests_data[0]: |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
103 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
|
104 xmlui.show(values_only=True) |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
105 self.disp(u'') |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
106 self.host.quit(C.EXIT_OK) |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
107 |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
108 def getRequests(self): |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
109 extra = {} |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
110 self.host.bridge.mergeRequestsGet( |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
111 self.args.service, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
112 self.args.node, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
113 self.args.max, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
114 self.args.items, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
115 u'', |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
116 extra, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
117 self.profile, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
118 callback=self.mergeRequestGetCb, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
119 errback=partial(self.errback, |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
120 msg=_(u"can't get merge request: {}"), |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
121 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
122 |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
123 def start(self): |
2558
501b0f827f63
jp (merge-request,common): fixed URIFinder when metadata are not needed:
Goffi <goffi@goffi.org>
parents:
2554
diff
changeset
|
124 common.URIFinder(self, os.getcwd(), 'merge requests', self.getRequests, meta_map={}) |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
125 |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
126 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
127 class Import(base.CommandBase): |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
128 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
129 def __init__(self, host): |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
130 base.CommandBase.__init__(self, host, 'import', |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
131 use_pubsub=True, pubsub_flags={C.SINGLE_ITEM, C.ITEM}, |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
132 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
133 help=_(u'import a merge request')) |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
134 self.need_loop=True |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
135 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
136 def add_parser_options(self): |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
137 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
|
138 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
139 def mergeRequestImportCb(self): |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
140 self.host.quit(C.EXIT_OK) |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
141 |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
142 def importRequest(self): |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
143 extra = {} |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
144 self.host.bridge.mergeRequestsImport( |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
145 self.repository, |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
146 self.args.item, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
147 self.args.service, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
148 self.args.node, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
149 extra, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
150 self.profile, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
151 callback=self.mergeRequestImportCb, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
152 errback=partial(self.errback, |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
153 msg=_(u"can't import merge request: {}"), |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
154 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
155 |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
156 def start(self): |
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
157 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) |
2558
501b0f827f63
jp (merge-request,common): fixed URIFinder when metadata are not needed:
Goffi <goffi@goffi.org>
parents:
2554
diff
changeset
|
158 common.URIFinder(self, self.repository, 'merge requests', self.importRequest, meta_map={}) |
2553
39b10475f56b
jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents:
2551
diff
changeset
|
159 |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
160 |
2450 | 161 class MergeRequest(base.CommandBase): |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
162 subcommands = (Set, Get, Import) |
2450 | 163 |
164 def __init__(self, host): | |
165 super(MergeRequest, self).__init__(host, 'merge-request', use_profile=False, help=_('merge-request management')) |