changeset 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 2268df8c99bf
children d2476dc2d55d
files src/plugins/plugin_tickets_import.py
diffstat 1 files changed, 94 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins/plugin_tickets_import.py	Fri Oct 06 10:55:54 2017 +0200
@@ -0,0 +1,94 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# SàT plugin for import external ticketss
+# Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from sat.core.i18n import _
+from sat.core.constants import Const as C
+from sat.core.log import getLogger
+log = getLogger(__name__)
+from twisted.internet import defer
+
+
+PLUGIN_INFO = {
+    C.PI_NAME: "tickets import",
+    C.PI_IMPORT_NAME: "TICKETS_IMPORT",
+    C.PI_TYPE: C.PLUG_TYPE_IMPORT,
+    C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "PUBSUB_SCHEMA"],
+    C.PI_MAIN: "TicketsImportPlugin",
+    C.PI_HANDLER: "no",
+    C.PI_DESCRIPTION: _(u"""Tickets import management:
+This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""")
+}
+
+NS_TICKETS = 'org.salut-a-toi.tickets:0'
+
+
+class TicketsImportPlugin(object):
+    BOOL_OPTIONS = ()
+    OPT_DEFAULTS = {}
+
+    def __init__(self, host):
+        log.info(_("plugin Tickets Import initialization"))
+        self.host = host
+        self._importers = {}
+        self._p = host.plugins['XEP-0060']
+        self._s = host.plugins['PUBSUB_SCHEMA']
+        host.plugins['IMPORT'].initialize(self, u'tickets')
+
+    @defer.inlineCallbacks
+    def importItem(self, client, item_import_data, session, options, return_data, service, node):
+        """
+
+        @param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored.
+            Following names are recommendations which should be used where suitable in importers.
+            'id': unique id (must be unique in the node) of the ticket
+            'title': title (or short description/summary) of the ticket
+            'body': main description of the ticket
+            'creation': date of creation
+            'update': date of last update
+            'reporter_name': full name of reporter
+            'reporter_email': email of reporter
+            'assigned_to_name': full name of person working on it
+            'assigned_to_email': email of person working on it
+            'cc_emails': iterable of emails subscribed to the ticket
+            'priority': priority of the ticket
+            'severity': severity of the ticket
+            'product': product concerned by this ticket
+            'component': part of the product concerned by this ticket
+            'version': version of the product/component concerned by this ticket
+            'platform': platform converned by this ticket
+            'os': operating system concerned by this ticket
+            'status': current status of the ticket
+            'milestone': target milestone for this ticket
+        """
+        if not 'schema' in session:
+            session['schema'] = yield self._s.getSchemaForm(client, service, node or NS_TICKETS)
+        defer.returnValue(item_import_data)
+
+    def importSubItems(self, client, item_import_data, ticket_data, session, options):
+        return None
+
+    def publishItem(self, client, ticket_data, service, node, session):
+        if node is None:
+            node = NS_TICKETS
+        id_ = ticket_data.pop('id', None)
+        log.debug(u"uploading item [{id}]: {title}".format(id=id_, title=ticket_data.get('title','')))
+        return self._s.sendDataFormItem(client, service, node, ticket_data, session['schema'], id_)
+
+    def itemFilters(self, client, ticket_data, session, options):
+        return None