Mercurial > libervia-backend
diff sat/plugins/plugin_misc_merge_requests.py @ 2622:8fb99ed47db4
core: lines limit
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 07:50:35 +0200 |
parents | 700327fa9281 |
children | 003b8b4b56a7 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_merge_requests.py Wed Jun 27 07:23:59 2018 +0200 +++ b/sat/plugins/plugin_misc_merge_requests.py Wed Jun 27 07:50:35 2018 +0200 @@ -84,7 +84,8 @@ async=True) host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin", in_sign='sss', out_sign='s', - method=utils.partial(self._s._getUISchema, default_node=NS_MERGE_REQUESTS), + method=utils.partial(self._s._getUISchema, + default_node=NS_MERGE_REQUESTS), async=True) host.bridge.addMethod("mergeRequestParseData", ".plugin", in_sign='ss', out_sign='aa{ss}', @@ -104,14 +105,15 @@ It must have the following methods, which may all return a Deferred: - check(repository): True if repository can be handled - export(repository): return export data, i.e. the patches - - parse(export_data): parse report data and return a list of dict (1 per patch) with: + - parse(export_data): parse report data and return a list of dict + (1 per patch) with: - title: title of the commit message (first line) - body: body of the commit message @aram data_types(list[unicode]): data types that his handler can generate or parse """ if name in self._handlers: - raise exceptions.ConflictError(_(u"a handler with name {name} already exists!").format( - name = name)) + raise exceptions.ConflictError(_(u"a handler with name {name} already " + u"exists!").format(name = name)) self._handlers[name] = MergeRequestHandler(name, handler, data_types, @@ -123,19 +125,22 @@ data_types = [data_types] for data_type in data_types: if data_type in self._type_handlers: - log.warning(_(u'merge requests of type {type} are already handled by {old_handler}, ' - u'ignoring {new_handler}').format( - type = data_type, + log.warning(_(u'merge requests of type {type} are already handled by ' + u'{old_handler}, ignoring {new_handler}').format( + type = data_type, old_handler = self._type_handlers[data_type].name, new_handler = name)) continue self._type_handlers[data_type] = self._handlers[name] - def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): + def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, + extra_dict=None, profile_key=C.PROF_KEY_NONE): if extra_dict and 'parse' in extra_dict: extra_dict['parse'] = C.bool(extra_dict['parse']) - client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet(service, node, max_items, sub_id, extra_dict, profile_key) - d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, extra.rsm_request, extra.extra) + client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet( + service, node, max_items, sub_id, extra_dict, profile_key) + d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, + extra.rsm_request, extra.extra) d.addCallback(lambda (tickets, metadata, parsed_patches): ( self._p.serItemsData((tickets, metadata)) + ([[{key: unicode(value) for key, value in p.iteritems()} @@ -143,7 +148,8 @@ return d @defer.inlineCallbacks - def get(self, client, service=None, node=None, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None): + def get(self, client, service=None, node=None, max_items=None, item_ids=None, + sub_id=None, rsm_request=None, extra=None): """Retrieve merge requests and convert them to XMLUI @param extra(XEP-0060.parse, None): can have following keys: @@ -184,21 +190,26 @@ parsed_patches.append(parsed_data) defer.returnValue((tickets_xmlui, metadata, parsed_patches)) - def _set(self, service, node, repository, method, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE): - client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(service, node, schema, item_id, extra, profile_key) - d = self.set(client, service, node, repository, method, values, schema, item_id, extra, deserialise=True) + def _set(self, service, node, repository, method, values, schema=None, item_id=None, + extra=None, profile_key=C.PROF_KEY_NONE): + client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( + service, node, schema, item_id, extra, profile_key) + d = self.set(client, service, node, repository, method, values, schema, item_id, + extra, deserialise=True) d.addCallback(lambda ret: ret or u'') return d @defer.inlineCallbacks - def set(self, client, service, node, repository, method=u'auto', values=None, schema=None, item_id=None, extra=None, deserialise=False): + def set(self, client, service, node, repository, method=u'auto', values=None, + schema=None, item_id=None, extra=None, deserialise=False): """Publish a tickets @param service(None, jid.JID): Pubsub service to use @param node(unicode, None): Pubsub node to use None to use default tickets node @param repository(unicode): path to the repository where the code stands - @param method(unicode): name of one of the registered handler, or "auto" to try autodetection. + @param method(unicode): name of one of the registered handler, + or "auto" to try autodetection. other arguments are same as for [TICKETS.set] @return (unicode): id of the created item """ @@ -213,8 +224,8 @@ raise exceptions.DataError(_(u"repository must be specified")) if FIELD_DATA in values: - raise exceptions.DataError(_(u"{field} is set by backend, you must not set it in frontend").format( - field = FIELD_DATA)) + raise exceptions.DataError(_(u"{field} is set by backend, you must not set " + u"it in frontend").format(field = FIELD_DATA)) if repository: if method == u'auto': @@ -225,9 +236,11 @@ log.info(_(u"{name} handler will be used").format(name=name)) break else: - log.warning(_(u"repository {path} can't be handled by any installed handler").format( + log.warning(_(u"repository {path} can't be handled by any installed " + u"handler").format( path = repository)) - raise exceptions.NotFound(_(u"no handler for this repository has been found")) + raise exceptions.NotFound(_(u"no handler for this repository has " + u"been found")) else: try: handler = self._handlers[name].handler @@ -236,7 +249,8 @@ data = yield handler.export(repository) if not data.strip(): - raise exceptions.DataError(_(u'export data is empty, do you have any change to send?')) + raise exceptions.DataError(_(u'export data is empty, do you have any ' + u'change to send?')) if not values.get(u'title') or not values.get(u'body'): patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) @@ -249,7 +263,8 @@ values[FIELD_DATA] = data - item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns=NS_MERGE_REQUESTS) + item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, + deserialise, form_ns=NS_MERGE_REQUESTS) defer.returnValue(item_id) def _parseData(self, data_type, data): @@ -270,17 +285,21 @@ try: handler = self._type_handlers[data_type] except KeyError: - raise exceptions.NotFound(_(u'No handler can handle data type "{type}"').format(type=data_type)) + raise exceptions.NotFound(_(u'No handler can handle data type "{type}"') + .format(type=data_type)) return defer.maybeDeferred(handler.handler.parse, data, data_type) - def _import(self, repository, item_id, service=None, node=None, extra=None, profile_key=C.PROF_KEY_NONE): + def _import(self, repository, item_id, service=None, node=None, extra=None, + profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key) service = jid.JID(service) if service else None - d = self.import_request(client, repository, item_id, service, node or None, extra=extra or None) + d = self.import_request(client, repository, item_id, service, node or None, + extra=extra or None) return d @defer.inlineCallbacks - def import_request(self, client, repository, item, service=None, node=None, extra=None): + def import_request(self, client, repository, item, service=None, node=None, + extra=None): """Import a merge request in specified directory @param repository(unicode): path to the repository where the code stands @@ -300,8 +319,10 @@ try: handler = self._type_handlers[data_type] except KeyError: - raise exceptions.NotFound(_(u'No handler found to import {data_type}').format(data_type=data_type)) + raise exceptions.NotFound(_(u'No handler found to import {data_type}') + .format(data_type=data_type)) log.info(_(u"Importing patch [{item_id}] using {name} handler").format( item_id = item, name = handler.name)) - yield handler.handler.import_(repository, data, data_type, item, service, node, extra) + yield handler.handler.import_(repository, data, data_type, item, service, node, + extra)