Mercurial > libervia-backend
annotate src/plugins/plugin_tickets_import.py @ 2373:d2476dc2d55d
plugin tickets import Bugzilla: Bugzilla tickets importer:
it imports tickets from Bugzilla's XML export format.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Oct 2017 10:55:54 +0200 |
parents | 95a41c5f67c0 |
children | a49a19f06e38 |
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 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 log = getLogger(__name__) |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.internet import defer |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 PLUGIN_INFO = { |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 C.PI_NAME: "tickets import", |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 C.PI_IMPORT_NAME: "TICKETS_IMPORT", |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 C.PI_TYPE: C.PLUG_TYPE_IMPORT, |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "PUBSUB_SCHEMA"], |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 C.PI_MAIN: "TicketsImportPlugin", |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 C.PI_HANDLER: "no", |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_DESCRIPTION: _(u"""Tickets import management: |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 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
|
36 } |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 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
|
39 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 class TicketsImportPlugin(object): |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 BOOL_OPTIONS = () |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 OPT_DEFAULTS = {} |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 def __init__(self, host): |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 log.info(_("plugin Tickets Import initialization")) |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.host = host |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 self._importers = {} |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 self._p = host.plugins['XEP-0060'] |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self._s = host.plugins['PUBSUB_SCHEMA'] |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 host.plugins['IMPORT'].initialize(self, u'tickets') |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 @defer.inlineCallbacks |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 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
|
55 """ |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 @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
|
58 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
|
59 '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
|
60 '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
|
61 'body': main description of the ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 'creation': date of creation |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 'update': date of last update |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 'reporter_name': full name of reporter |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 'reporter_email': email of reporter |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 '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
|
67 '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
|
68 '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
|
69 'priority': priority of the ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 'severity': severity of the ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 'product': product concerned by this ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 '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
|
73 '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
|
74 'platform': platform converned by this ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 'os': operating system concerned by this ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 'status': current status of the ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 'milestone': target milestone for this ticket |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 """ |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 if not 'schema' in session: |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 session['schema'] = yield self._s.getSchemaForm(client, service, node or NS_TICKETS) |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 defer.returnValue(item_import_data) |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def importSubItems(self, client, item_import_data, ticket_data, session, options): |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 return None |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 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
|
87 if node is None: |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 node = NS_TICKETS |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 id_ = ticket_data.pop('id', None) |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 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
|
91 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
|
92 |
95a41c5f67c0
plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 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
|
94 return None |