comparison sat_frontends/jp/cmd_merge_request.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/jp/cmd_merge_request.py@501b0f827f63
children 56f94936df1e
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # jp: a SàT command line tool
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
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
24 from sat_frontends.jp import xmlui_manager
25 from sat_frontends.jp import common
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):
35 base.CommandBase.__init__(self, host, 'set', use_pubsub=True,
36 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')},
37 help=_(u'publish or update a merge request'))
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)"))
43 self.parser.add_argument("-f", "--force", action="store_true", help=_(u"publish merge request without confirmation"))
44 self.parser.add_argument("-l", "--label", dest="labels", type=base.unicode_decoder, action='append', help=_(u"labels to categorize your request"))
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
53 def sendRequest(self):
54 extra = {'update': 'true'} if self.args.item else {}
55 values = {}
56 if self.args.labels is not None:
57 values[u'labels'] = self.args.labels
58 self.host.bridge.mergeRequestSet(
59 self.args.service,
60 self.args.node,
61 self.repository,
62 u'auto',
63 values,
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
73 def askConfirmation(self):
74 if not self.args.force:
75 message = _(u"You are going to publish your changes to service [{service}], are you sure ?").format(
76 service=self.args.service)
77 self.host.confirmOrQuit(message, _(u"merge request publication cancelled"))
78 self.sendRequest()
79
80 def start(self):
81 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
82 common.URIFinder(self, self.repository, 'merge requests', self.askConfirmation)
83
84
85 class Get(base.CommandBase):
86
87 def __init__(self, host):
88 base.CommandBase.__init__(self, host, 'get', use_verbose=True,
89 use_pubsub=True, pubsub_flags={C.MULTI_ITEMS},
90 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')},
91 help=_(u'get a merge request'))
92 self.need_loop=True
93
94 def add_parser_options(self):
95 pass
96
97 def mergeRequestGetCb(self, requests_data):
98 if self.verbosity >= 1:
99 whitelist = None
100 else:
101 whitelist = {'id', 'title', 'body'}
102 for request_xmlui in requests_data[0]:
103 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist)
104 xmlui.show(values_only=True)
105 self.disp(u'')
106 self.host.quit(C.EXIT_OK)
107
108 def getRequests(self):
109 extra = {}
110 self.host.bridge.mergeRequestsGet(
111 self.args.service,
112 self.args.node,
113 self.args.max,
114 self.args.items,
115 u'',
116 extra,
117 self.profile,
118 callback=self.mergeRequestGetCb,
119 errback=partial(self.errback,
120 msg=_(u"can't get merge request: {}"),
121 exit_code=C.EXIT_BRIDGE_ERRBACK))
122
123 def start(self):
124 common.URIFinder(self, os.getcwd(), 'merge requests', self.getRequests, meta_map={})
125
126
127 class Import(base.CommandBase):
128
129 def __init__(self, host):
130 base.CommandBase.__init__(self, host, 'import',
131 use_pubsub=True, pubsub_flags={C.SINGLE_ITEM, C.ITEM},
132 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')},
133 help=_(u'import a merge request'))
134 self.need_loop=True
135
136 def add_parser_options(self):
137 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)"))
138
139 def mergeRequestImportCb(self):
140 self.host.quit(C.EXIT_OK)
141
142 def importRequest(self):
143 extra = {}
144 self.host.bridge.mergeRequestsImport(
145 self.repository,
146 self.args.item,
147 self.args.service,
148 self.args.node,
149 extra,
150 self.profile,
151 callback=self.mergeRequestImportCb,
152 errback=partial(self.errback,
153 msg=_(u"can't import merge request: {}"),
154 exit_code=C.EXIT_BRIDGE_ERRBACK))
155
156 def start(self):
157 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
158 common.URIFinder(self, self.repository, 'merge requests', self.importRequest, meta_map={})
159
160
161 class MergeRequest(base.CommandBase):
162 subcommands = (Set, Get, Import)
163
164 def __init__(self, host):
165 super(MergeRequest, self).__init__(host, 'merge-request', use_profile=False, help=_('merge-request management'))