# python import import sys import logging import os from xml.dom.minidom import Document logger = logging.getLogger("RoundupExport") logger.setLevel(level=logging.DEBUG) hdlr = logging.FileHandler('logging.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) # our import from issue import MaloneIssue from user import MaloneUser from validate import ValidateXML # import config from config import ROUNDUP_LIB, ROUNDUP_INSTANCE, XML_INDENT, XML_NEWLINE # roundup import sys.path.insert(1, ROUNDUP_LIB) from roundup import instance class RoundupExport(object): """ Tool to export Roundup Bug """ def __init__(self, instanceLocation=None): if instanceLocation is not None: self.instanceLocation = instanceLocation self._roundupIssues = [] def getInstanceLocation(self): return self._instanceLocation def setInstanceLocation(self, instanceLocation): if(not os.path.exists(instanceLocation)): raise ValueError("Wrong instance location") self._instanceLocation = instanceLocation instanceLocation = property(getInstanceLocation, setInstanceLocation) def getExportedRoundupIssues(self): return self._roundupIssues roundupIssues = property(getExportedRoundupIssues) def exportAsXML(self, exportList): doc = Document() bugs = doc.createElement("launchpad-bugs") bugs.setAttribute('xmlns', "https://launchpad.net/xmlns/2006/bugs") doc.appendChild(bugs) self.tracker = instance.open(self.instanceLocation) self.db = self.tracker.open('admin') for issueId in exportList: if self.db.issue.hasnode(str(issueId)): logger.debug('Exporting bug %s' % issueId) bug = doc.createElement("bug") bug.setAttribute('id',str(issueId)) bugs.appendChild(bug) issue = MaloneIssue(id=issueId) roundupIssue = self.db.getnode('issue', str(issueId)) issue.importRoundupIssue(self.db, roundupIssue) issue.toXML(doc, bug) else: logger.debug('Issue %s not found!' % issueId) return doc.toprettyxml(newl=XML_NEWLINE, indent=XML_INDENT) def fetchKnownUsers(self, exportList): users = [] for issueId in exportList: roundupIssue = self.db.getnode('issue', str(issueId)) creatorId = roundupIssue.get('creator') maloneUser = MaloneUser() maloneUser.importRoundupUser(self.db, creatorId) users.append(maloneUser) return users if __name__ == '__main__': rdup = RoundupExport(ROUNDUP_INSTANCE) # roundupExportXML = rdup.exportAsXML([66]) roundupExportXML = rdup.exportAsXML(range(1,600)) f = open('export.xml', 'w') f.write(roundupExportXML) f.close() validator = ValidateXML(roundupExportXML) e = validator.validate() if e.errors: for err in e.errors: logger.debug("Validation error: %s" % err)