annotate src/plugins/plugin_tickets_import.py @ 2396:66baa687c682

plugins tickets import, jp (ticket/import): implemented mapping: - mapping is an option allowing do map imported field to a specific field in the newly created item - importers can now use complexe data types in options using JSON
author Goffi <goffi@goffi.org>
date Fri, 27 Oct 2017 17:58:05 +0200
parents 8ed4ac10cb5e
children 8b37a62336c3
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
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
27 from sat.tools import utils
2372
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
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 PLUGIN_INFO = {
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 C.PI_NAME: "tickets import",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 C.PI_IMPORT_NAME: "TICKETS_IMPORT",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 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
34 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
35 C.PI_MAIN: "TicketsImportPlugin",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_HANDLER: "no",
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_DESCRIPTION: _(u"""Tickets import management:
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 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
39 }
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
41 OPT_MAPPING = 'mapping'
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
42 FIELDS_LIST = (u'labels', u'cc_emails') # fields which must have a list as value
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
43 FIELDS_DATE = (u'created', u'updated')
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
44
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 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
46
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 class TicketsImportPlugin(object):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 BOOL_OPTIONS = ()
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
50 JSON_OPTIONS = (OPT_MAPPING,)
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 OPT_DEFAULTS = {}
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 def __init__(self, host):
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 log.info(_("plugin Tickets Import initialization"))
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.host = host
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self._importers = {}
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self._p = host.plugins['XEP-0060']
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
58 self._m = host.plugins['XEP-0277']
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self._s = host.plugins['PUBSUB_SCHEMA']
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 host.plugins['IMPORT'].initialize(self, u'tickets')
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 @defer.inlineCallbacks
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 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
64 """
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 @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
67 Following names are recommendations which should be used where suitable in importers.
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
68 except if specified in description, values are unicode
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 '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
70 '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
71 'body': main description of the ticket
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
72 'created': date of creation (unix time)
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
73 'updated': date of last update (unix time)
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
74 'reporter': full name of reporter
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
75 'reporter_jid': jid of reporter
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 'reporter_email': email of reporter
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 '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
78 'assigned_to_email': email of person working on it
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
79 'cc_emails': list of emails subscribed to the ticket
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 'priority': priority of the ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 'severity': severity of the ticket
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
82 'labels': list of unicode values to use as label
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 'product': product concerned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 '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
85 '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
86 'platform': platform converned by this ticket
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 '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
88 '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
89 - "queued": ticket is waiting
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
90 - "started": progress is ongoing
a49a19f06e38 plugin import ticket, import ticket bugzilla: some normalization in values:
Goffi <goffi@goffi.org>
parents: 2372
diff changeset
91 - "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
92 - "closed": ticket is finished or invalid
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 'milestone': target milestone for this ticket
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
94 'comments': list of microblog data (comment metadata, check [XEP_0277.send] data argument)
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
95 @param options(dict, None): Below are the generic options,
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
96 tickets importer can have specific ones. All options are serialized unicode values
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
97 generic options:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
98 - OPT_MAPPING (json): dict of imported ticket key => exported ticket key
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
99 e.g.: if you want to map "component" to "labels", you can specify:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
100 {'component': 'labels'}
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
101 If you specify several import ticket key to the same dest key,
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
102 the values will be joined with line feeds
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
104 if 'comments_uri' in item_import_data:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
105 raise exceptions.DataError(_(u'comments_uri key will be generated and must not be used by importer'))
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
106 for key in FIELDS_LIST:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
107 if not isinstance(item_import_data.get(key, []), list):
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
108 raise exceptions.DataError(_(u'{key} must be a list').format(key=key))
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
109 for key in FIELDS_DATE:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
110 try:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
111 item_import_data[key] = utils.xmpp_date(item_import_data[key])
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
112 except KeyError:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
113 continue
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
114 if session[u'root_node'] is None:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
115 session[u'root_node'] = NS_TICKETS
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if not 'schema' in session:
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
117 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
118 defer.returnValue(item_import_data)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
120 @defer.inlineCallbacks
2372
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 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
122 # 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
123 # TODO: handle "private" metadata, to have non public access for node
2393
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
124 # TODO: node access/publish model should be customisable
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
125 comments = ticket_data.get('comments', [])
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
126 service, node = self._m.getCommentsService(client), self._m.getCommentsNode(session['root_node'] + u'_' + ticket_data['id'])
2393
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
127 node_options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
128 self._p.OPT_PERSIST_ITEMS: 1,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
129 self._p.OPT_MAX_ITEMS: -1,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
130 self._p.OPT_DELIVER_PAYLOADS: 1,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
131 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
132 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
133 }
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2390
diff changeset
134 yield self._p.createIfNewNode(client, service, node, options=node_options)
2390
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
135 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
136 for comment in comments:
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
137 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
138 # 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
139 comment['updated'] = comment['published']
f57a8eaec8ed plugins import, tickets import, bugzilla import: comments handling:
Goffi <goffi@goffi.org>
parents: 2382
diff changeset
140 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
141
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 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
143 if node is None:
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 node = NS_TICKETS
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 id_ = ticket_data.pop('id', None)
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 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
147 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
148
95a41c5f67c0 plugin tickets import: specialized importer for tickets, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 def itemFilters(self, client, ticket_data, session, options):
2396
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
150 mapping = options.get(OPT_MAPPING)
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
151 if mapping is not None:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
152 if not isinstance(mapping, dict):
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
153 raise exceptions.DataError(_(u'mapping option must be a dictionary'))
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
154
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
155 for source, dest in mapping.iteritems():
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
156 if not isinstance(source, unicode) or not isinstance(dest, unicode):
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
157 raise exceptions.DataError(_(u'keys and values of mapping must be sources and destinations ticket fields'))
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
158 if source in ticket_data:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
159 value = ticket_data.pop(source)
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
160 if dest in FIELDS_LIST:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
161 values = ticket_data[dest] = ticket_data.get(dest, [])
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
162 values.append(value)
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
163 else:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
164 if dest in ticket_data:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
165 ticket_data[dest] = ticket_data[dest] + u'\n' + value
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
166 else:
66baa687c682 plugins tickets import, jp (ticket/import): implemented mapping:
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
167 ticket_data[dest] = value