annotate src/plugins/plugin_tickets_import.py @ 2391:07e1543d6992

template: new "adv_format" filter which use Python's format and return whole value if template is None
author Goffi <goffi@goffi.org>
date Fri, 20 Oct 2017 08:49:39 +0200
parents f57a8eaec8ed
children 8ed4ac10cb5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SàT plugin for import external ticketss
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
22 from sat.core import exceptions
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.log import getLogger
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.internet import defer
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
26 from sat.tools.common import uri
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 PLUGIN_INFO = {
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 C.PI_NAME: "tickets import",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 C.PI_IMPORT_NAME: "TICKETS_IMPORT",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 C.PI_TYPE: C.PLUG_TYPE_IMPORT,
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
33 C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "XEP-0277", "PUBSUB_SCHEMA"],
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_MAIN: "TicketsImportPlugin",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_HANDLER: "no",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_DESCRIPTION: _(u"""Tickets import management:
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""")
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 }
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 NS_TICKETS = 'org.salut-a-toi.tickets:0'
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class TicketsImportPlugin(object):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 BOOL_OPTIONS = ()
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 OPT_DEFAULTS = {}
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def __init__(self, host):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 log.info(_("plugin Tickets Import initialization"))
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.host = host
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self._importers = {}
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self._p = host.plugins['XEP-0060']
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
52 self._m = host.plugins['XEP-0277']
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self._s = host.plugins['PUBSUB_SCHEMA']
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 host.plugins['IMPORT'].initialize(self, u'tickets')
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 @defer.inlineCallbacks
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def importItem(self, client, item_import_data, session, options, return_data, service, node):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 """
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 @param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored.
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 Following names are recommendations which should be used where suitable in importers.
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 'id': unique id (must be unique in the node) of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 'title': title (or short description/summary) of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 'body': main description of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 'creation': date of creation
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 'update': date of last update
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
67 'reporter': full name of reporter
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
68 'reporter_jid': jid of reporter
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 'reporter_email': email of reporter
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 'assigned_to_name': full name of person working on it
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 'assigned_to_email': email of person working on it
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 'cc_emails': iterable of emails subscribed to the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 'priority': priority of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 'severity': severity of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 'product': product concerned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 'component': part of the product concerned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 'version': version of the product/component concerned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 'platform': platform converned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 'os': operating system concerned by this ticket
2382
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
80 'status': current status of the ticket, values:
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
81 - "queued": ticket is waiting
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
82 - "started": progress is ongoing
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
83 - "review": ticket is fixed and waiting for review
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
84 - "closed": ticket is finished or invalid
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 'milestone': target milestone for this ticket
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
86 'comments': list of microblog data (comment metadata, check [XEP_0277.send] data argument)
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 """
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
88 if 'comments_uri' in item_import_data:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
89 raise exceptions.DataError(_(u'comments_uri key will be generated and must not be used by importer'))
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
90 if session[u'root_node'] is None:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
91 session[u'root_node'] = NS_TICKETS
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if not 'schema' in session:
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
93 session['schema'] = yield self._s.getSchemaForm(client, service, node or session[u'root_node'])
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 defer.returnValue(item_import_data)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
96 @defer.inlineCallbacks
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 def importSubItems(self, client, item_import_data, ticket_data, session, options):
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
98 # TODO: force "open" permission (except if private, check below)
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
99 # TODO: handle "private" metadata, to have non public access for node
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
100 comments = ticket_data.get('comments', [])
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
101 service, node = self._m.getCommentsService(client), self._m.getCommentsNode(session['root_node'] + u'_' + ticket_data['id'])
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
102 yield self._p.createIfNewNode(client, service, node)
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
103 ticket_data['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=service.full(), node=node)
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
104 for comment in comments:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
105 if 'updated' not in comment and 'published' in comment:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
106 # we don't want an automatic update date
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
107 comment['updated'] = comment['published']
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
108 yield self._m.send(client, comment, service, node)
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def publishItem(self, client, ticket_data, service, node, session):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 if node is None:
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 node = NS_TICKETS
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 id_ = ticket_data.pop('id', None)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 log.debug(u"uploading item [{id}]: {title}".format(id=id_, title=ticket_data.get('title','')))
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 return self._s.sendDataFormItem(client, service, node, ticket_data, session['schema'], id_)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def itemFilters(self, client, ticket_data, session, options):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return None