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.

77 lines
1.8KB

  1. from xml.dom.minidom import getDOMImplementation, parse, Element
  2. impl = getDOMImplementation()
  3. class SessionDom( object ):
  4. def __init__( self, filename=None ):
  5. if filename:
  6. self.dom = parse( 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.toprettyxml()
  25. def get_client_names(self):
  26. retval = []
  27. doc = self.dom.documentElement
  28. for c in doc.getElementsByTagName( "jackclient" ):
  29. retval.append( c.getAttribute( "jackname" ) )
  30. return retval
  31. def get_port_names(self):
  32. retval = []
  33. doc = self.dom.documentElement
  34. for c in doc.getElementsByTagName( "port" ):
  35. retval.append( c.getAttribute( "name" ) )
  36. return retval
  37. def get_connections_for_port( self, portname ):
  38. retval = []
  39. doc = self.dom.documentElement
  40. for c in doc.getElementsByTagName( "port" ):
  41. if c.getAttribute( "name" ) == portname:
  42. for i in c.getElementsByTagName( "conn" ):
  43. retval.append( i.getAttribute( "dst" ) )
  44. return retval
  45. def get_commandline_for_client( self, name ):
  46. doc = self.dom.documentElement
  47. for c in doc.getElementsByTagName( "jackclient" ):
  48. if c.getAttribute( "jackname" ) == name:
  49. return c.getAttribute( "cmdline" )