comparison src/plugins/plugin_misc_radiocol.py @ 849:c5a8f602662b

plugin room_game, radiocol: RoomGame.send returns a Deferred.
author souliane <souliane@mailoo.org>
date Tue, 18 Feb 2014 17:49:33 +0100
parents 8f335c03eebb
children c238d2c02237
comparison
equal deleted inserted replaced
848:d40306d1da70 849:c5a8f602662b
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, info, warning, error 21 from logging import debug, info, warning, error
22 from twisted.words.xish import domish 22 from twisted.words.xish import domish
23 from twisted.internet import reactor 23 from twisted.internet import reactor
24 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
25 from twisted.internet import threads, defer 25 from twisted.internet import defer
26 from sat.core import exceptions 26 from sat.core import exceptions
27 import os.path 27 import os.path
28 import copy 28 import copy
29 import time 29 import time
30 from os import unlink 30 from os import unlink
87 87
88 def radiocolSongAdded(self, referee, song_path, profile): 88 def radiocolSongAdded(self, referee, song_path, profile):
89 """This method is called by libervia when a song has been uploaded 89 """This method is called by libervia when a song has been uploaded
90 @param referee: JID of the referee in the room (room userhost + '/' + nick) 90 @param referee: JID of the referee in the room (room userhost + '/' + nick)
91 @song_path: absolute path of the song added 91 @song_path: absolute path of the song added
92 @param profile_key: %(doc_profile_key)s""" 92 @param profile_key: %(doc_profile_key)s
93 @return: a Deferred instance
94 """
93 #XXX: this is a Q&D way for the proof of concept. In the future, the song should 95 #XXX: this is a Q&D way for the proof of concept. In the future, the song should
94 # be streamed to the backend using XMPP file copy 96 # be streamed to the backend using XMPP file copy
95 # Here we cheat because we know we are on the same host, and we don't 97 # Here we cheat because we know we are on the same host, and we don't
96 # check data. Referee will have to parse the song himself to check it 98 # check data. Referee will have to parse the song himself to check it
97 client = self.host.getClient(profile) 99 client = self.host.getClient(profile)
109 'album': song.get("album", ["Unknown"])[0], 111 'album': song.get("album", ["Unknown"])[0],
110 'length': str(song.info.length) 112 'length': str(song.info.length)
111 } 113 }
112 radio_data = self.games[jid.JID(referee).userhost()] # FIXME: referee comes from Libervia's client side, it's unsecure 114 radio_data = self.games[jid.JID(referee).userhost()] # FIXME: referee comes from Libervia's client side, it's unsecure
113 radio_data['to_delete'][attrs['filename']] = song_path # FIXME: works only because of the same host trick, see the note under the docstring 115 radio_data['to_delete'][attrs['filename']] = song_path # FIXME: works only because of the same host trick, see the note under the docstring
114 116 return self.send(jid.JID(referee), ('', 'song_added'), attrs, profile=profile)
115 # XXX: avoid deferToThread which is causing testing troubles. When using deferToThread,
116 # the callbacks that are added (by the test) to the Deferred instance returned by this
117 # method are not run. And if you run d.callback again, you get a AlreadyCalledError.
118 d = defer.Deferred()
119 d.addCallback(self.send, ('', 'song_added'), attrs, profile=profile)
120 d.callback(jid.JID(referee))
121 return d
122 117
123 def playNext(self, room_jid, profile): 118 def playNext(self, room_jid, profile):
124 """"Play next song in queue if exists, and put a timer 119 """"Play next song in queue if exists, and put a timer
125 which trigger after the song has been played to play next one""" 120 which trigger after the song has been played to play next one"""
126 #TODO: songs need to be erased once played or found invalids 121 #TODO: songs need to be erased once played or found invalids