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.

98 lines
2.4KB

  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. if client.isinfra:
  14. cl_elem.setAttribute( "infra", "True" )
  15. else:
  16. cl_elem.setAttribute( "infra", "False" )
  17. for p in client.ports:
  18. po_elem = Element( "port" )
  19. po_elem.setAttribute( "name", p.name )
  20. po_elem.setAttribute( "shortname", p.portname )
  21. for c in p.get_connections():
  22. c_elem = Element( "conn" )
  23. c_elem.setAttribute( "dst", c )
  24. po_elem.appendChild( c_elem )
  25. cl_elem.appendChild( po_elem )
  26. self.dom.documentElement.appendChild( cl_elem )
  27. def get_xml(self):
  28. return self.dom.toprettyxml()
  29. def get_client_names(self):
  30. retval = []
  31. doc = self.dom.documentElement
  32. for c in doc.getElementsByTagName( "jackclient" ):
  33. retval.append( c.getAttribute( "jackname" ) )
  34. return retval
  35. def get_reg_client_names(self):
  36. retval = []
  37. doc = self.dom.documentElement
  38. for c in doc.getElementsByTagName( "jackclient" ):
  39. if c.getAttribute( "infra" ) != "True":
  40. retval.append( c.getAttribute( "jackname" ) )
  41. return retval
  42. def get_infra_clients(self):
  43. retval = []
  44. doc = self.dom.documentElement
  45. for c in doc.getElementsByTagName( "jackclient" ):
  46. if c.getAttribute( "infra" ) == "True":
  47. retval.append( (c.getAttribute( "jackname" ), c.getAttribute( "cmdline" ) ) )
  48. return retval
  49. def get_port_names(self):
  50. retval = []
  51. doc = self.dom.documentElement
  52. for c in doc.getElementsByTagName( "port" ):
  53. retval.append( c.getAttribute( "name" ) )
  54. return retval
  55. def get_connections_for_port( self, portname ):
  56. retval = []
  57. doc = self.dom.documentElement
  58. for c in doc.getElementsByTagName( "port" ):
  59. if c.getAttribute( "name" ) == portname:
  60. for i in c.getElementsByTagName( "conn" ):
  61. retval.append( i.getAttribute( "dst" ) )
  62. return retval
  63. def get_commandline_for_client( self, name ):
  64. doc = self.dom.documentElement
  65. for c in doc.getElementsByTagName( "jackclient" ):
  66. if c.getAttribute( "jackname" ) == name:
  67. return c.getAttribute( "cmdline" )