def createSimpleType(self, item): 'Erzeugt aus einem XML Element einen einfachen Datentypen' t = item.getAttribute('name') if t == 'String': type = StringType() elif t == 'Float': type = FloatType() elif t == 'Integer': type = IntegerType() elif t == 'DateTime': type = DateTimeType() elif t == 'Boolean': type = BooleanType() elif t == 'binary': type = BinaryType() else: raise SchnittstellenXMLException('Unknown type: %s' % t) if type.identifier in self.types: raise SchnittstellenXMLException('Already defined: %s' % type.identifier) self.types[type.identifier] = type type.description = domGetText(item.getElementsByTagName('description')[0]) type.example = domGetText(item.getElementsByTagName('example')[0]) todo = item.getElementsByTagName('todo') if len(todo) > 0: type.todo = domGetText(todo[0])
def createComplexType(self, item): 'Erzeugt aus einem XML Element einen komplexten Datentypen' type = ComplexType(item.getAttribute('type'), item.getAttribute('name')) if type.identifier in self.types: raise SchnittstellenXMLException('Already defined: %s' % type.identifier) self.types[type.identifier] = type type.description = domGetText(item.getElementsByTagName('description')[0]) todo = item.getElementsByTagName('todo') if len(todo) > 0: type.todo = domGetText(todo[0]) type.properties = self.getProperties(item)
def getGroupedActions(self): 'Erzeugt ein Dictionary mit den gruppierten Actions' self._groupedActions = {} for ag in self.dom.getElementsByTagName('group'): actionGroup = ActionGroup(ag.getAttribute('name')) actionGroup.description = domGetText(ag.getElementsByTagName('description')[0]) todo = ag.getElementsByTagName('todo') if len(todo) > 0: actionGroup.todo = domGetText(todo[0]) actionGroup.actions = self.getActions(actionGroup, ag) if actionGroup.identifier in self._groupedActions: raise SchnittstellenXMLException("Action group already defined: %s\n%s" % (actionGroup.identifier, item.toxml())) self._groupedActions[actionGroup.identifier] = actionGroup return self._groupedActions
def createEnumType(self, item): 'Erzeugt aus einem XML Element einen Enum' type = EnumType(item.getAttribute('name')) if type.identifier in self.types: raise SchnittstellenXMLException('Already defined: %s' % type.identifier) self.types[type.identifier] = type type.description = domGetText(item.getElementsByTagName('description')[0]) type.example = domGetText(item.getElementsByTagName('example')[0]) todo = item.getElementsByTagName('todo') if len(todo) > 0: type.todo = domGetText(todo[0]) items = item.getElementsByTagName('items')[0] for item in items.getElementsByTagName('item'): type.addValue(item.getAttribute('value'), domGetText(item.getElementsByTagName('description')[0]))
def getProperty(self, item): 'Erzeugt aus einem XML Element eine Property' property = Property(item.getAttribute('name')) property.type = self.types[item.getAttribute('type')] property.description = item.getAttribute('description') multiple = item.getAttribute('multiple') if multiple == "true": property.islist = True optional = item.getAttribute('optional') if optional == "true": property.isoptional = True example = item.getElementsByTagName('example') if len(example) > 0: property.example = domGetText(example[0]) else: # Standardbeispiel des Basis-Typen nehmen if not isinstance(property.type, ComplexType): property.example = property.type.example todo = item.getElementsByTagName('todo') if len(todo) > 0: property.todo = domGetText(todo[0]) return property
def getActions(self, group, item): 'Erzeugt ein Dictionary mit den Actions, die in item definiert sind' actions = {} for actionItem in item.getElementsByTagName('action'): action = Action(actionItem.getAttribute('name'), group) action.description = domGetText(actionItem.getElementsByTagName('description')[0]) action.inServer = actionItem.getAttribute("inServer") == "true" action.inClient = actionItem.getAttribute("inClient") == "true" action.messageType = actionItem.getAttribute("messageType") todo = actionItem.getElementsByTagName('todo') if len(todo) > 0: action.todo = domGetText(todo[0]) if action.identifier in actions: raise SchnittstellenXMLException("Action already defined: %s\n%s" % (action.identifier, item.toxml())) actions[action.identifier] = action action.request = self.getProperties(actionItem.getElementsByTagName('request')[0]) action.response = self.getProperties(actionItem.getElementsByTagName('response')[0]) notification = actionItem.getElementsByTagName('notification') if notification: action.notification = self.getProperties(notification[0]) else: action.notification = None return actions
def addIssue(self, issueNode): 'Creates an issue from the given node' issue = RedmineIssue() for key in ['project', 'tracker', 'status', 'priority', 'author', 'assigned_to', 'category', 'fixed_version', 'parent']: nodes = issueNode.getElementsByTagName(key) v = None if len(nodes): el = nodes[0] v = {'id': int(el.getAttribute('id')), 'name': el.getAttribute('name')} setattr(issue, key, v) for key in ['id', 'subject', 'description', 'start_date', 'due_date', 'done_ratio', 'estimated_hours', 'created_on', 'updated_on']: setattr(issue, key, domGetText(issueNode.getElementsByTagName(key)[0])) self.redmineIssues.append(issue) self.githubIssues.append(self.toGithubIssue(issue))
def __init__(self, ticket, url, realm): m = re.match('(https?://)([^:]+):([^@]+)@(.+)', url) if m == None: raise Exception("Failed to match username and password from url") proto, username, password, path = m.groups() auth_handler = urllib.request.HTTPBasicAuthHandler() auth_handler.add_password(realm=realm,uri=proto + path,user=username,passwd=password) opener = urllib.request.build_opener(auth_handler) urllib.request.install_opener(opener) ticket_feed_xml = urllib.request.urlopen(proto + path + ("ticket/%d?format=rss" % ticket.id)) dom = parseString(ticket_feed_xml.read()) self._comments = [] for item in dom.getElementsByTagName('item'): comment = {}; for child in item.childNodes: if child.nodeType == child.TEXT_NODE: continue comment[child.nodeName] = domGetText(child) self._comments.append(comment)
def addIssue(self, issueNode): "Creates an issue from the given node" issue = RedmineIssue() for key in [ "project", "tracker", "status", "priority", "author", "assigned_to", "category", "fixed_version", "parent", ]: nodes = issueNode.getElementsByTagName(key) v = None if len(nodes): el = nodes[0] v = {"id": int(el.getAttribute("id")), "name": el.getAttribute("name")} setattr(issue, key, v) for key in [ "id", "subject", "description", "start_date", "due_date", "done_ratio", "estimated_hours", "created_on", "updated_on", ]: setattr(issue, key, domGetText(issueNode.getElementsByTagName(key)[0])) self.redmineIssues.append(issue) self.githubIssues.append(self.toGithubIssue(issue))