comparison sat_frontends/jp/cmd_merge_request.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 989b622faff6
children fee60f17ebac
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
16 16
17 # You should have received a copy of the GNU Affero General Public License 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/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 20
21 import base 21 from . import base
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat.tools.common import data_format 23 from sat.tools.common import data_format
24 from sat_frontends.jp.constants import Const as C 24 from sat_frontends.jp.constants import Const as C
25 from sat_frontends.jp import xmlui_manager 25 from sat_frontends.jp import xmlui_manager
26 from sat_frontends.jp import common 26 from sat_frontends.jp import common
35 base.CommandBase.__init__( 35 base.CommandBase.__init__(
36 self, 36 self,
37 host, 37 host,
38 "set", 38 "set",
39 use_pubsub=True, 39 use_pubsub=True,
40 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")}, 40 pubsub_defaults={"service": _("auto"), "node": _("auto")},
41 help=_(u"publish or update a merge request"), 41 help=_("publish or update a merge request"),
42 ) 42 )
43 self.need_loop = True 43 self.need_loop = True
44 44
45 def add_parser_options(self): 45 def add_parser_options(self):
46 self.parser.add_argument( 46 self.parser.add_argument(
47 "-i", 47 "-i",
48 "--item", 48 "--item",
49 type=base.unicode_decoder, 49 default="",
50 default=u"", 50 help=_("id or URL of the request to update, or nothing for a new one"),
51 help=_(u"id or URL of the request to update, or nothing for a new one"),
52 ) 51 )
53 self.parser.add_argument( 52 self.parser.add_argument(
54 "-r", 53 "-r",
55 "--repository", 54 "--repository",
56 metavar="PATH", 55 metavar="PATH",
57 type=base.unicode_decoder, 56 default=".",
58 default=u".", 57 help=_("path of the repository (DEFAULT: current directory)"),
59 help=_(u"path of the repository (DEFAULT: current directory)"),
60 ) 58 )
61 self.parser.add_argument( 59 self.parser.add_argument(
62 "-f", 60 "-f",
63 "--force", 61 "--force",
64 action="store_true", 62 action="store_true",
65 help=_(u"publish merge request without confirmation"), 63 help=_("publish merge request without confirmation"),
66 ) 64 )
67 self.parser.add_argument( 65 self.parser.add_argument(
68 "-l", 66 "-l",
69 "--label", 67 "--label",
70 dest="labels", 68 dest="labels",
71 type=base.unicode_decoder,
72 action="append", 69 action="append",
73 help=_(u"labels to categorize your request"), 70 help=_("labels to categorize your request"),
74 ) 71 )
75 72
76 def mergeRequestSetCb(self, published_id): 73 def mergeRequestSetCb(self, published_id):
77 if published_id: 74 if published_id:
78 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id)) 75 self.disp("Merge request published at {pub_id}".format(pub_id=published_id))
79 else: 76 else:
80 self.disp(u"Merge request published") 77 self.disp("Merge request published")
81 self.host.quit(C.EXIT_OK) 78 self.host.quit(C.EXIT_OK)
82 79
83 def sendRequest(self): 80 def sendRequest(self):
84 extra = {"update": True} if self.args.item else {} 81 extra = {"update": True} if self.args.item else {}
85 values = {} 82 values = {}
86 if self.args.labels is not None: 83 if self.args.labels is not None:
87 values[u"labels"] = self.args.labels 84 values["labels"] = self.args.labels
88 self.host.bridge.mergeRequestSet( 85 self.host.bridge.mergeRequestSet(
89 self.args.service, 86 self.args.service,
90 self.args.node, 87 self.args.node,
91 self.repository, 88 self.repository,
92 u"auto", 89 "auto",
93 values, 90 values,
94 u"", 91 "",
95 self.args.item, 92 self.args.item,
96 data_format.serialise(extra), 93 data_format.serialise(extra),
97 self.profile, 94 self.profile,
98 callback=self.mergeRequestSetCb, 95 callback=self.mergeRequestSetCb,
99 errback=partial( 96 errback=partial(
100 self.errback, 97 self.errback,
101 msg=_(u"can't create merge request: {}"), 98 msg=_("can't create merge request: {}"),
102 exit_code=C.EXIT_BRIDGE_ERRBACK, 99 exit_code=C.EXIT_BRIDGE_ERRBACK,
103 ), 100 ),
104 ) 101 )
105 102
106 def askConfirmation(self): 103 def askConfirmation(self):
107 if not self.args.force: 104 if not self.args.force:
108 message = _( 105 message = _(
109 u"You are going to publish your changes to service [{service}], are you sure ?" 106 "You are going to publish your changes to service [{service}], are you sure ?"
110 ).format(service=self.args.service) 107 ).format(service=self.args.service)
111 self.host.confirmOrQuit(message, _(u"merge request publication cancelled")) 108 self.host.confirmOrQuit(message, _("merge request publication cancelled"))
112 self.sendRequest() 109 self.sendRequest()
113 110
114 def start(self): 111 def start(self):
115 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) 112 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
116 common.URIFinder(self, self.repository, "merge requests", self.askConfirmation) 113 common.URIFinder(self, self.repository, "merge requests", self.askConfirmation)
123 host, 120 host,
124 "get", 121 "get",
125 use_verbose=True, 122 use_verbose=True,
126 use_pubsub=True, 123 use_pubsub=True,
127 pubsub_flags={C.MULTI_ITEMS}, 124 pubsub_flags={C.MULTI_ITEMS},
128 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")}, 125 pubsub_defaults={"service": _("auto"), "node": _("auto")},
129 help=_(u"get a merge request"), 126 help=_("get a merge request"),
130 ) 127 )
131 self.need_loop = True 128 self.need_loop = True
132 129
133 def add_parser_options(self): 130 def add_parser_options(self):
134 pass 131 pass
139 else: 136 else:
140 whitelist = {"id", "title", "body"} 137 whitelist = {"id", "title", "body"}
141 for request_xmlui in requests_data[0]: 138 for request_xmlui in requests_data[0]:
142 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist) 139 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist)
143 xmlui.show(values_only=True) 140 xmlui.show(values_only=True)
144 self.disp(u"") 141 self.disp("")
145 self.host.quit(C.EXIT_OK) 142 self.host.quit(C.EXIT_OK)
146 143
147 def getRequests(self): 144 def getRequests(self):
148 extra = {} 145 extra = {}
149 self.host.bridge.mergeRequestsGet( 146 self.host.bridge.mergeRequestsGet(
150 self.args.service, 147 self.args.service,
151 self.args.node, 148 self.args.node,
152 self.args.max, 149 self.args.max,
153 self.args.items, 150 self.args.items,
154 u"", 151 "",
155 extra, 152 extra,
156 self.profile, 153 self.profile,
157 callback=self.mergeRequestGetCb, 154 callback=self.mergeRequestGetCb,
158 errback=partial( 155 errback=partial(
159 self.errback, 156 self.errback,
160 msg=_(u"can't get merge request: {}"), 157 msg=_("can't get merge request: {}"),
161 exit_code=C.EXIT_BRIDGE_ERRBACK, 158 exit_code=C.EXIT_BRIDGE_ERRBACK,
162 ), 159 ),
163 ) 160 )
164 161
165 def start(self): 162 def start(self):
174 self, 171 self,
175 host, 172 host,
176 "import", 173 "import",
177 use_pubsub=True, 174 use_pubsub=True,
178 pubsub_flags={C.SINGLE_ITEM, C.ITEM}, 175 pubsub_flags={C.SINGLE_ITEM, C.ITEM},
179 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")}, 176 pubsub_defaults={"service": _("auto"), "node": _("auto")},
180 help=_(u"import a merge request"), 177 help=_("import a merge request"),
181 ) 178 )
182 self.need_loop = True 179 self.need_loop = True
183 180
184 def add_parser_options(self): 181 def add_parser_options(self):
185 self.parser.add_argument( 182 self.parser.add_argument(
186 "-r", 183 "-r",
187 "--repository", 184 "--repository",
188 metavar="PATH", 185 metavar="PATH",
189 type=base.unicode_decoder, 186 default=".",
190 default=u".", 187 help=_("path of the repository (DEFAULT: current directory)"),
191 help=_(u"path of the repository (DEFAULT: current directory)"),
192 ) 188 )
193 189
194 def mergeRequestImportCb(self): 190 def mergeRequestImportCb(self):
195 self.host.quit(C.EXIT_OK) 191 self.host.quit(C.EXIT_OK)
196 192
204 extra, 200 extra,
205 self.profile, 201 self.profile,
206 callback=self.mergeRequestImportCb, 202 callback=self.mergeRequestImportCb,
207 errback=partial( 203 errback=partial(
208 self.errback, 204 self.errback,
209 msg=_(u"can't import merge request: {}"), 205 msg=_("can't import merge request: {}"),
210 exit_code=C.EXIT_BRIDGE_ERRBACK, 206 exit_code=C.EXIT_BRIDGE_ERRBACK,
211 ), 207 ),
212 ) 208 )
213 209
214 def start(self): 210 def start(self):