#!/usr/bin/env python # -*- coding: utf-8 -*- from xml.etree.cElementTree import ElementTree, Element, SubElement, dump import sys, urn import psyco psyco.full() print "TSL to FreeMind converter, pawel.krawczyk@hewitt.com, 2009" filename='PL_TSL.xml' ns = 'http://uri.etsi.org/02231/v2#' xmlns = 'http://www.w3.org/XML/1998/namespace' # input tree - TSL TSLtree = ElementTree(file=filename) TSLroot = TSLtree.getroot() # Output tree - Freemind MMroot = Element("map") MMroot.set('version','0.9.0') tspOperatorFull = TSLroot.find('.//{%s}SchemeInformation/{%s}SchemeOperatorName/{%s}Name' % (ns,ns,ns)) tspOperator = tspOperatorFull.text MMlist = SubElement(MMroot, 'node', text=tspOperator) TSPList = TSLroot.find('{%s}TrustServiceProviderList' % ns) for TrustServiceProvider in TSPList.getiterator('{%s}TrustServiceProvider' % ns): # Determine Provider name name = '' Name = TrustServiceProvider.find(".//{%s}TSPName/{%s}Name"%(ns,ns)) #if Name.attrib.get('{%s}lang'%xmlns) == 'pl': MMprovider = SubElement(MMlist, 'node', text=Name.text) SubElement(MMprovider, 'font', bold='true', name='Verdana', size='12') # Build services tree for Service in TrustServiceProvider.findall(".//{%s}TSPService"%(ns,)): serviceNameFull = Service.find('.//{%s}ServiceInformation/{%s}ServiceName/{%s}Name'%(ns,ns,ns)) serviceName = serviceNameFull.text serviceTypeFull = Service.find('.//{%s}ServiceInformation/{%s}ServiceTypeIdentifier'%(ns,ns)) serviceType = serviceTypeFull.text.split('/')[-1] serviceStatusFull = Service.find('.//{%s}ServiceInformation/{%s}ServiceStatus'%(ns,ns,)) serviceStatus = serviceStatusFull.text.split('/')[-1] MMservice = SubElement(MMprovider, 'node') MMservice.attrib['text'] = "%s - %s (%s)" %(serviceType, serviceName, serviceStatus) if cmp(serviceStatus, 'undersupervision') == 0: MMservice.attrib['background_color'] = '#99ff33' else: MMservice.attrib['background_color'] = '#cccccc' print "Writing map..." dump(MMroot) ElementTree(MMroot).write('PL_TSL.mm','utf-8') print "Done."