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.

117 lines
3.0KB

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