Mercurial > libervia-backend
annotate frontends/src/jp/cmd_merge_request.py @ 2542:100563768196
jp (merge/get): "get" command first draft:
get allows to retrieve a merge request, to display it. By default it only display "id", "title" and "body" ; verbosity must be augmented to display more.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Mar 2018 09:09:33 +0200 |
parents | 772447ec070f |
children | 2df1ca79cb30 |
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 |
2450 | 25 from functools import partial |
26 import os.path | |
27 | |
28 __commands__ = ["MergeRequest"] | |
29 | |
30 | |
31 class Set(base.CommandBase): | |
32 | |
33 def __init__(self, host): | |
34 base.CommandBase.__init__(self, host, 'set', use_pubsub=True, help=_(u'publish or update a merge request')) | |
35 self.need_loop=True | |
36 | |
37 def add_parser_options(self): | |
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")) | |
39 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)")) | |
40 | |
41 def mergeRequestSetCb(self, published_id): | |
42 if published_id: | |
43 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id)) | |
44 else: | |
45 self.disp(u"Merge request published") | |
46 self.host.quit(C.EXIT_OK) | |
47 | |
48 def start(self): | |
49 repository = os.path.expanduser(os.path.abspath(self.args.repository)) | |
50 extra = {'update': 'true'} if self.args.item else {} | |
51 self.host.bridge.mergeRequestSet( | |
52 self.args.service, | |
53 self.args.node, | |
54 repository, | |
55 u'auto', | |
56 {}, | |
57 u'', | |
58 self.args.item, | |
59 extra, | |
60 self.profile, | |
61 callback=self.mergeRequestSetCb, | |
62 errback=partial(self.errback, | |
63 msg=_(u"can't create merge request: {}"), | |
64 exit_code=C.EXIT_BRIDGE_ERRBACK)) | |
65 | |
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 |
2450 | 102 class MergeRequest(base.CommandBase): |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
103 subcommands = (Set, Get) |
2450 | 104 |
105 def __init__(self, host): | |
106 super(MergeRequest, self).__init__(host, 'merge-request', use_profile=False, help=_('merge-request management')) |