Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
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.

168 lines
4.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # mumble-django contributed by withgod@sourceforge.net
  3. import dbus
  4. #zope.interface is good but don't standard interface library
  5. #abc is better but 2.6 higher.
  6. #import abc
  7. #from django.conf import settings
  8. class MumbleCtlBase ():
  9. ''' abstract Ctrol Object '''
  10. def setConf(self, srvid, key, value):
  11. pass
  12. def getValue(self, srvid, key):
  13. pass
  14. def newServer(self):
  15. pass
  16. def setSuperUserPassword(self, srvid, value):
  17. pass
  18. def start(self, srvid):
  19. pass
  20. def stop(self, srvid):
  21. pass
  22. def isBooted(self, srvid):
  23. pass
  24. def deleteServer(self, srvid):
  25. pass
  26. def getUsers(self, srvid):
  27. pass
  28. def getPlayers(self, srvid):
  29. pass
  30. def getChannels(self, srvid):
  31. pass
  32. def registerPlayer(self, srvid, name):
  33. pass
  34. def setRegistration(self, srvid, mumbleid, name, email, password):
  35. pass
  36. def unregisterPlayer(self, srvid, mumbleid):
  37. pass
  38. def getBootedServers(self):
  39. pass
  40. def getACL(self, srvid, identifier):
  41. pass
  42. def setACL(self, srvid, acl):
  43. pass
  44. @staticmethod
  45. def newInstance():
  46. # if dbus
  47. #if settings.DAOTYPE == 'dbus':
  48. ret = MumbleCtlDbus()
  49. #else:
  50. # ret = MumbleCtlIce()
  51. return ret
  52. class MumbleCtlDbus(MumbleCtlBase):
  53. meta = None
  54. dbus_base='net.sourceforge.mumble.murmur'
  55. def __init__(self):
  56. # Prior to saving the model, connect to murmur via dbus and update its settings.
  57. self.meta = self._getDbusMeta();
  58. def _getDbusMeta( self ):
  59. return dbus.Interface( dbus.SystemBus().get_object( self.dbus_base, '/' ), 'net.sourceforge.mumble.Meta' );
  60. def _getDbusServerObject( self, srvid):
  61. "Connects to DBus and returns an mmServer object representing this Murmur instance."
  62. if srvid not in self.getBootedServers():
  63. raise Exception, 'No murmur process with the given server ID (%d) is running and attached to system dbus under %s.' % ( srvid, self.meta );
  64. return dbus.Interface( dbus.SystemBus().get_object( self.dbus_base, '/%d' % srvid ), 'net.sourceforge.mumble.Murmur' );
  65. def setConf(self, srvid, key, value):
  66. self.meta.setConf(dbus.Int32( srvid ), key, value)
  67. def deleteServer( self, srvid ):
  68. srvid = dbus.Int32( srvid )
  69. if self.meta.isBooted( srvid ):
  70. self.meta.stop( srvid )
  71. self.meta.deleteServer( srvid )
  72. def newServer(self):
  73. return self.meta.newServer()
  74. def registerPlayer(self, srvid, name):
  75. return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).registerPlayer(name))
  76. def unregisterPlayer(self, srvid, mumbleid):
  77. self._getDbusServerObject(srvid).unregisterPlayer(dbus.Int32( mumbleid ))
  78. def getChannels(self, srvid):
  79. return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getChannels())
  80. def getPlayers(self, srvid):
  81. return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getPlayers())
  82. def getACL(self, srvid, identifier):
  83. return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).getACL(identifier))
  84. def setACL(self, srvid, acl):
  85. self._getDbusServerObject(srvid).setACL(*acl.pack())
  86. def getBootedServers(self):
  87. return MumbleCtlDbus.converDbusTypeToNative(self.meta.getBootedServers())
  88. def setSuperUserPassword(self, srvid, value):
  89. self.meta.setSuperUserPassword(dbus.Int32(srvid), value)
  90. def setRegistration(self, srvid, mumbleid, name, email, password):
  91. return MumbleCtlDbus.converDbusTypeToNative(self._getDbusServerObject(srvid).setRegistration(dbus.Int32(mumbleid), dbus.String(name), dbus.String(email), dbus.String(password)))
  92. @staticmethod
  93. def converDbusTypeToNative(data):
  94. #i know dbus.* type is extends python native type.
  95. #but dbus.* type is not native type. it's not good transparent for using Ice/Dbus.
  96. ret = None
  97. if isinstance(data, tuple) or type(data) is data.__class__ is dbus.Array or data.__class__ is dbus.Struct :
  98. ret = []
  99. for x in data:
  100. ret.append(MumbleCtlDbus.converDbusTypeToNative(x))
  101. else:
  102. if data.__class__ is dbus.Boolean:
  103. ret = bool(data)
  104. elif data.__class__ is dbus.String:
  105. ret = str(data)
  106. elif data.__class__ is dbus.Int32 or data.__class__ is dbus.UInt32:
  107. ret = int(data)
  108. return ret
  109. if __name__ == "__main__":
  110. print "--- test start"
  111. #ctl = MumbleCtlBase.newInstance()
  112. ctl = MumbleCtlDbus()
  113. print ctl
  114. print ctl.meta
  115. print "booted server", ctl.getBootedServers()
  116. print "chans"
  117. print ctl.getChannels(1)
  118. print "users"
  119. print ctl.getPlayers(1)
  120. print "getACL", ctl.getACL(1, 0)
  121. print ctl.getACL(1, 0)[0].__class__ is dbus.Array
  122. print "--- test end"