comparison sat/plugins/plugin_tickets_import_bugzilla.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SàT plugin for import external blogs 4 # SàT plugin for import external blogs
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
39 C.PI_MAIN: "BugzillaImport", 39 C.PI_MAIN: "BugzillaImport",
40 C.PI_HANDLER: "no", 40 C.PI_HANDLER: "no",
41 C.PI_DESCRIPTION: _("""Tickets importer for Bugzilla"""), 41 C.PI_DESCRIPTION: _("""Tickets importer for Bugzilla"""),
42 } 42 }
43 43
44 SHORT_DESC = D_(u"import tickets from Bugzilla xml export file") 44 SHORT_DESC = D_("import tickets from Bugzilla xml export file")
45 45
46 LONG_DESC = D_( 46 LONG_DESC = D_(
47 u"""This importer handle Bugzilla xml export file. 47 """This importer handle Bugzilla xml export file.
48 48
49 To use it, you'll need to export tickets using XML. 49 To use it, you'll need to export tickets using XML.
50 Tickets will be uploaded with the same ID as for Bugzilla, any existing ticket with this ID will be replaced. 50 Tickets will be uploaded with the same ID as for Bugzilla, any existing ticket with this ID will be replaced.
51 51
52 location: you must use the absolute path to your .xml file 52 location: you must use the absolute path to your .xml file
81 if "@" in reporter_elt.text: 81 if "@" in reporter_elt.text:
82 ticket["author"] = reporter_elt.text[ 82 ticket["author"] = reporter_elt.text[
83 : reporter_elt.text.find("@") 83 : reporter_elt.text.find("@")
84 ].title() 84 ].title()
85 else: 85 else:
86 ticket["author"] = u"no name" 86 ticket["author"] = "no name"
87 ticket["author_email"] = reporter_elt.text 87 ticket["author_email"] = reporter_elt.text
88 assigned_to_elt = bug.find("assigned_to") 88 assigned_to_elt = bug.find("assigned_to")
89 ticket["assigned_to_name"] = assigned_to_elt.get("name") 89 ticket["assigned_to_name"] = assigned_to_elt.get("name")
90 ticket["assigned_to_email"] = assigned_to_elt.text 90 ticket["assigned_to_email"] = assigned_to_elt.text
91 ticket["cc_emails"] = [e.text for e in bug.findall("cc")] 91 ticket["cc_emails"] = [e.text for e in bug.findall("cc")]
123 return (tickets, len(tickets)) 123 return (tickets, len(tickets))
124 124
125 125
126 class BugzillaImport(object): 126 class BugzillaImport(object):
127 def __init__(self, host): 127 def __init__(self, host):
128 log.info(_(u"Bugilla Import plugin initialization")) 128 log.info(_("Bugilla Import plugin initialization"))
129 self.host = host 129 self.host = host
130 host.plugins["TICKETS_IMPORT"].register( 130 host.plugins["TICKETS_IMPORT"].register(
131 "bugzilla", self.Import, SHORT_DESC, LONG_DESC 131 "bugzilla", self.Import, SHORT_DESC, LONG_DESC
132 ) 132 )
133 133
134 def Import(self, client, location, options=None): 134 def Import(self, client, location, options=None):
135 if not os.path.isabs(location): 135 if not os.path.isabs(location):
136 raise exceptions.DataError( 136 raise exceptions.DataError(
137 u"An absolute path to XML data need to be given as location" 137 "An absolute path to XML data need to be given as location"
138 ) 138 )
139 bugzilla_parser = BugzillaParser() 139 bugzilla_parser = BugzillaParser()
140 # d = threads.deferToThread(bugzilla_parser.parse, location) 140 # d = threads.deferToThread(bugzilla_parser.parse, location)
141 d = defer.maybeDeferred(bugzilla_parser.parse, location) 141 d = defer.maybeDeferred(bugzilla_parser.parse, location)
142 return d 142 return d