[MIN] Remove unused template
[cds-indico.git] / indico / MaKaC / plugins / Collaboration / Hermes / Implementation / McuApi.py
blobd867725c8bf2be97713bc75ccd50ec31634a7754
1 import xmlrpclib
3 mcuAddress = "ccmcu40.in2p3.fr"
4 mcuProxy = xmlrpclib.ServerProxy("http://%s/RPC2" % mcuAddress)
5 mcuUser = "indico-support@cern.ch"
6 mcuPassword = "xK!34(25"
8 # RmsApi should be used to create conference
9 def CreateConference(**params):
10 return invokeMethod("conference.create", params)
12 # RmsApi should be used to destroy conference
13 def DestroyConference(**params):
14 return invokeMethod("conference.destroy", params)
16 def EnumerateConferences(**params):
17 return invokeMethod("conference.enumerate", params)
19 def EnumerateAllConferences(**params):
20 return enumerateAll(EnumerateConferences, "conferences", **params)
22 def SelectConferences(**params):
23 return selectDictionaries(EnumerateAllConferences(**params), params)
25 def QueryConferenceStreaming(**params):
26 return invokeMethod("conference.query", params)
28 def ModifyConference(**params):
29 return invokeMethod("conference.modify", params)
31 def AddParticipant(**params):
32 return invokeMethod("participant.add", params)
34 def RemoveParticipant(**params):
35 return invokeMethod("participant.remove", params)
37 def EnumerateParticipants(**params):
38 return invokeMethod("participant.enumerate", params)
40 def EnumerateAllParticipants(**params):
41 return enumerateAll(EnumerateParticipants, "participants", **params)
43 def SelectParticipants(params, **filter):
44 return selectDictionaries(EnumerateAllParticipants(**params), filter)
46 def ModifyParticipant(**params):
47 return invokeMethod("participant.modify", params)
49 def ConnectParticipant(**params):
50 return invokeMethod("participant.connect", params)
52 def DisconnectParticipant(**params):
53 return invokeMethod("participant.disconnect", params)
55 def invokeMethod(name, params):
56 args = {
57 "authenticationUser": mcuUser,
58 "authenticationPassword": mcuPassword
60 args.update(params)
61 return getattr(mcuProxy, name)(args)
63 def enumerateAll(method, key, **params):
64 id = None
65 while True:
66 if id == None:
67 ret = method(**params)
68 else:
69 params["enumerateID"] = id
70 ret = method(**params)
71 for item in ret.get(key, []):
72 yield item
73 id = ret.get("enumerateID", None)
74 if id == None:
75 break
77 def selectDictionaries(dictionaries, pairs):
78 return [dictionary for dictionary in dictionaries if hasAllPairs(dictionary, pairs)]
80 def hasAllPairs(target, source):
81 for key, value in source.iteritems():
82 if key not in target:
83 return False
84 if target[key] != value:
85 return False
86 return True
88 def first(list):
89 if len(list) > 0:
90 return list[0]
91 else:
92 return None