jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5KB

  1. from xml.dom.minidom import getDOMImplementation, parseString, Element
  2. impl = getDOMImplementation()
  3. class SessionDom( object ):
  4. def __init__( self, filename=None ):
  5. if filename:
  6. self.dom = parseString( filename )
  7. else:
  8. self.dom = impl.createDocument(None,"jacksession",None)
  9. def add_client( self, client ):
  10. cl_elem = Element( "jackclient" )
  11. cl_elem.setAttribute( "cmdline", client.get_commandline() )
  12. cl_elem.setAttribute( "jackname", client.name )
  13. for p in client.ports:
  14. po_elem = Element( "port" )
  15. po_elem.setAttribute( "name", p.name )
  16. po_elem.setAttribute( "shortname", p.portname )
  17. for c in p.get_connections():
  18. c_elem = Element( "conn" )
  19. c_elem.setAttribute( "dst", c )
  20. po_elem.appendChild( c_elem )
  21. cl_elem.appendChild( po_elem )
  22. self.dom.documentElement.appendChild( cl_elem )
  23. def get_xml(self):
  24. return self.dom.toxml()
  25. def get_client_names(self):
  26. doc = self.dom.documentElement
  27. for c in doc.getElementsByTagName( "jackclient" ):
  28. yield c.getAttribute( "jackname" ).value
  29. def get_port_names(self):
  30. doc = self.dom.documentElement
  31. for c in doc.getElementsByTagName( "port" ):
  32. yield c.getAttribute( "name" ).value
  33. def get_connections_for_port( self, portname ):
  34. doc = self.dom.documentElement
  35. for c in doc.getElementsByTagName( "port" ):
  36. if c.getAttribute( "name" ).value == portname:
  37. for i in c.getElementsByTagName( "conn" ):
  38. yield i.getAttribute( "dst" ).value