Mercurial > libervia-backend
comparison src/plugins/plugin_tickets_import.py @ 2372:95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
import tickets in a node with schema. Comments are not handled yet.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Oct 2017 10:55:54 +0200 |
parents | |
children | a49a19f06e38 |
comparison
equal
deleted
inserted
replaced
2371:2268df8c99bf | 2372:95a41c5f67c0 |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SàT plugin for import external ticketss | |
5 # Copyright (C) 2009-2016 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 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from sat.core.log import getLogger | |
23 log = getLogger(__name__) | |
24 from twisted.internet import defer | |
25 | |
26 | |
27 PLUGIN_INFO = { | |
28 C.PI_NAME: "tickets import", | |
29 C.PI_IMPORT_NAME: "TICKETS_IMPORT", | |
30 C.PI_TYPE: C.PLUG_TYPE_IMPORT, | |
31 C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "PUBSUB_SCHEMA"], | |
32 C.PI_MAIN: "TicketsImportPlugin", | |
33 C.PI_HANDLER: "no", | |
34 C.PI_DESCRIPTION: _(u"""Tickets import management: | |
35 This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""") | |
36 } | |
37 | |
38 NS_TICKETS = 'org.salut-a-toi.tickets:0' | |
39 | |
40 | |
41 class TicketsImportPlugin(object): | |
42 BOOL_OPTIONS = () | |
43 OPT_DEFAULTS = {} | |
44 | |
45 def __init__(self, host): | |
46 log.info(_("plugin Tickets Import initialization")) | |
47 self.host = host | |
48 self._importers = {} | |
49 self._p = host.plugins['XEP-0060'] | |
50 self._s = host.plugins['PUBSUB_SCHEMA'] | |
51 host.plugins['IMPORT'].initialize(self, u'tickets') | |
52 | |
53 @defer.inlineCallbacks | |
54 def importItem(self, client, item_import_data, session, options, return_data, service, node): | |
55 """ | |
56 | |
57 @param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored. | |
58 Following names are recommendations which should be used where suitable in importers. | |
59 'id': unique id (must be unique in the node) of the ticket | |
60 'title': title (or short description/summary) of the ticket | |
61 'body': main description of the ticket | |
62 'creation': date of creation | |
63 'update': date of last update | |
64 'reporter_name': full name of reporter | |
65 'reporter_email': email of reporter | |
66 'assigned_to_name': full name of person working on it | |
67 'assigned_to_email': email of person working on it | |
68 'cc_emails': iterable of emails subscribed to the ticket | |
69 'priority': priority of the ticket | |
70 'severity': severity of the ticket | |
71 'product': product concerned by this ticket | |
72 'component': part of the product concerned by this ticket | |
73 'version': version of the product/component concerned by this ticket | |
74 'platform': platform converned by this ticket | |
75 'os': operating system concerned by this ticket | |
76 'status': current status of the ticket | |
77 'milestone': target milestone for this ticket | |
78 """ | |
79 if not 'schema' in session: | |
80 session['schema'] = yield self._s.getSchemaForm(client, service, node or NS_TICKETS) | |
81 defer.returnValue(item_import_data) | |
82 | |
83 def importSubItems(self, client, item_import_data, ticket_data, session, options): | |
84 return None | |
85 | |
86 def publishItem(self, client, ticket_data, service, node, session): | |
87 if node is None: | |
88 node = NS_TICKETS | |
89 id_ = ticket_data.pop('id', None) | |
90 log.debug(u"uploading item [{id}]: {title}".format(id=id_, title=ticket_data.get('title',''))) | |
91 return self._s.sendDataFormItem(client, service, node, ticket_data, session['schema'], id_) | |
92 | |
93 def itemFilters(self, client, ticket_data, session, options): | |
94 return None |