comparison sat_frontends/jp/cmd_merge_request.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
28 28
29 __commands__ = ["MergeRequest"] 29 __commands__ = ["MergeRequest"]
30 30
31 31
32 class Set(base.CommandBase): 32 class Set(base.CommandBase):
33 33 def __init__(self, host):
34 def __init__(self, host): 34 base.CommandBase.__init__(
35 base.CommandBase.__init__(self, host, 'set', use_pubsub=True, 35 self,
36 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, 36 host,
37 help=_(u'publish or update a merge request')) 37 "set",
38 self.need_loop=True 38 use_pubsub=True,
39 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
40 help=_(u"publish or update a merge request"),
41 )
42 self.need_loop = True
39 43
40 def add_parser_options(self): 44 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")) 45 self.parser.add_argument(
42 self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)")) 46 "-i",
43 self.parser.add_argument("-f", "--force", action="store_true", help=_(u"publish merge request without confirmation")) 47 "--item",
44 self.parser.add_argument("-l", "--label", dest="labels", type=base.unicode_decoder, action='append', help=_(u"labels to categorize your request")) 48 type=base.unicode_decoder,
49 default=u"",
50 help=_(u"id or URL of the request to update, or nothing for a new one"),
51 )
52 self.parser.add_argument(
53 "-r",
54 "--repository",
55 metavar="PATH",
56 type=base.unicode_decoder,
57 default=u".",
58 help=_(u"path of the repository (DEFAULT: current directory)"),
59 )
60 self.parser.add_argument(
61 "-f",
62 "--force",
63 action="store_true",
64 help=_(u"publish merge request without confirmation"),
65 )
66 self.parser.add_argument(
67 "-l",
68 "--label",
69 dest="labels",
70 type=base.unicode_decoder,
71 action="append",
72 help=_(u"labels to categorize your request"),
73 )
45 74
46 def mergeRequestSetCb(self, published_id): 75 def mergeRequestSetCb(self, published_id):
47 if published_id: 76 if published_id:
48 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id)) 77 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id))
49 else: 78 else:
50 self.disp(u"Merge request published") 79 self.disp(u"Merge request published")
51 self.host.quit(C.EXIT_OK) 80 self.host.quit(C.EXIT_OK)
52 81
53 def sendRequest(self): 82 def sendRequest(self):
54 extra = {'update': 'true'} if self.args.item else {} 83 extra = {"update": "true"} if self.args.item else {}
55 values = {} 84 values = {}
56 if self.args.labels is not None: 85 if self.args.labels is not None:
57 values[u'labels'] = self.args.labels 86 values[u"labels"] = self.args.labels
58 self.host.bridge.mergeRequestSet( 87 self.host.bridge.mergeRequestSet(
59 self.args.service, 88 self.args.service,
60 self.args.node, 89 self.args.node,
61 self.repository, 90 self.repository,
62 u'auto', 91 u"auto",
63 values, 92 values,
64 u'', 93 u"",
65 self.args.item, 94 self.args.item,
66 extra, 95 extra,
67 self.profile, 96 self.profile,
68 callback=self.mergeRequestSetCb, 97 callback=self.mergeRequestSetCb,
69 errback=partial(self.errback, 98 errback=partial(
70 msg=_(u"can't create merge request: {}"), 99 self.errback,
71 exit_code=C.EXIT_BRIDGE_ERRBACK)) 100 msg=_(u"can't create merge request: {}"),
101 exit_code=C.EXIT_BRIDGE_ERRBACK,
102 ),
103 )
72 104
73 def askConfirmation(self): 105 def askConfirmation(self):
74 if not self.args.force: 106 if not self.args.force:
75 message = _(u"You are going to publish your changes to service [{service}], are you sure ?").format( 107 message = _(
76 service=self.args.service) 108 u"You are going to publish your changes to service [{service}], are you sure ?"
109 ).format(service=self.args.service)
77 self.host.confirmOrQuit(message, _(u"merge request publication cancelled")) 110 self.host.confirmOrQuit(message, _(u"merge request publication cancelled"))
78 self.sendRequest() 111 self.sendRequest()
79 112
80 def start(self): 113 def start(self):
81 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) 114 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
82 common.URIFinder(self, self.repository, 'merge requests', self.askConfirmation) 115 common.URIFinder(self, self.repository, "merge requests", self.askConfirmation)
83 116
84 117
85 class Get(base.CommandBase): 118 class Get(base.CommandBase):
86 119 def __init__(self, host):
87 def __init__(self, host): 120 base.CommandBase.__init__(
88 base.CommandBase.__init__(self, host, 'get', use_verbose=True, 121 self,
89 use_pubsub=True, pubsub_flags={C.MULTI_ITEMS}, 122 host,
90 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, 123 "get",
91 help=_(u'get a merge request')) 124 use_verbose=True,
92 self.need_loop=True 125 use_pubsub=True,
126 pubsub_flags={C.MULTI_ITEMS},
127 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
128 help=_(u"get a merge request"),
129 )
130 self.need_loop = True
93 131
94 def add_parser_options(self): 132 def add_parser_options(self):
95 pass 133 pass
96 134
97 def mergeRequestGetCb(self, requests_data): 135 def mergeRequestGetCb(self, requests_data):
98 if self.verbosity >= 1: 136 if self.verbosity >= 1:
99 whitelist = None 137 whitelist = None
100 else: 138 else:
101 whitelist = {'id', 'title', 'body'} 139 whitelist = {"id", "title", "body"}
102 for request_xmlui in requests_data[0]: 140 for request_xmlui in requests_data[0]:
103 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist) 141 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist)
104 xmlui.show(values_only=True) 142 xmlui.show(values_only=True)
105 self.disp(u'') 143 self.disp(u"")
106 self.host.quit(C.EXIT_OK) 144 self.host.quit(C.EXIT_OK)
107 145
108 def getRequests(self): 146 def getRequests(self):
109 extra = {} 147 extra = {}
110 self.host.bridge.mergeRequestsGet( 148 self.host.bridge.mergeRequestsGet(
111 self.args.service, 149 self.args.service,
112 self.args.node, 150 self.args.node,
113 self.args.max, 151 self.args.max,
114 self.args.items, 152 self.args.items,
115 u'', 153 u"",
116 extra, 154 extra,
117 self.profile, 155 self.profile,
118 callback=self.mergeRequestGetCb, 156 callback=self.mergeRequestGetCb,
119 errback=partial(self.errback, 157 errback=partial(
120 msg=_(u"can't get merge request: {}"), 158 self.errback,
121 exit_code=C.EXIT_BRIDGE_ERRBACK)) 159 msg=_(u"can't get merge request: {}"),
160 exit_code=C.EXIT_BRIDGE_ERRBACK,
161 ),
162 )
122 163
123 def start(self): 164 def start(self):
124 common.URIFinder(self, os.getcwd(), 'merge requests', self.getRequests, meta_map={}) 165 common.URIFinder(
166 self, os.getcwd(), "merge requests", self.getRequests, meta_map={}
167 )
125 168
126 169
127 class Import(base.CommandBase): 170 class Import(base.CommandBase):
128 171 def __init__(self, host):
129 def __init__(self, host): 172 base.CommandBase.__init__(
130 base.CommandBase.__init__(self, host, 'import', 173 self,
131 use_pubsub=True, pubsub_flags={C.SINGLE_ITEM, C.ITEM}, 174 host,
132 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')}, 175 "import",
133 help=_(u'import a merge request')) 176 use_pubsub=True,
134 self.need_loop=True 177 pubsub_flags={C.SINGLE_ITEM, C.ITEM},
178 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
179 help=_(u"import a merge request"),
180 )
181 self.need_loop = True
135 182
136 def add_parser_options(self): 183 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)")) 184 self.parser.add_argument(
185 "-r",
186 "--repository",
187 metavar="PATH",
188 type=base.unicode_decoder,
189 default=u".",
190 help=_(u"path of the repository (DEFAULT: current directory)"),
191 )
138 192
139 def mergeRequestImportCb(self): 193 def mergeRequestImportCb(self):
140 self.host.quit(C.EXIT_OK) 194 self.host.quit(C.EXIT_OK)
141 195
142 def importRequest(self): 196 def importRequest(self):
147 self.args.service, 201 self.args.service,
148 self.args.node, 202 self.args.node,
149 extra, 203 extra,
150 self.profile, 204 self.profile,
151 callback=self.mergeRequestImportCb, 205 callback=self.mergeRequestImportCb,
152 errback=partial(self.errback, 206 errback=partial(
153 msg=_(u"can't import merge request: {}"), 207 self.errback,
154 exit_code=C.EXIT_BRIDGE_ERRBACK)) 208 msg=_(u"can't import merge request: {}"),
209 exit_code=C.EXIT_BRIDGE_ERRBACK,
210 ),
211 )
155 212
156 def start(self): 213 def start(self):
157 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) 214 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
158 common.URIFinder(self, self.repository, 'merge requests', self.importRequest, meta_map={}) 215 common.URIFinder(
216 self, self.repository, "merge requests", self.importRequest, meta_map={}
217 )
159 218
160 219
161 class MergeRequest(base.CommandBase): 220 class MergeRequest(base.CommandBase):
162 subcommands = (Set, Get, Import) 221 subcommands = (Set, Get, Import)
163 222
164 def __init__(self, host): 223 def __init__(self, host):
165 super(MergeRequest, self).__init__(host, 'merge-request', use_profile=False, help=_('merge-request management')) 224 super(MergeRequest, self).__init__(
225 host, "merge-request", use_profile=False, help=_("merge-request management")
226 )