diff src/plugins/plugin_misc_radiocol.py @ 1359:83127a4c89ce frontends_multi_profiles

plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:36:22 +0100
parents 83ed877541e3
children 069ad98b360d
line wrap: on
line diff
--- a/src/plugins/plugin_misc_radiocol.py	Wed Mar 11 12:35:21 2015 +0100
+++ b/src/plugins/plugin_misc_radiocol.py	Wed Mar 11 12:36:22 2015 +0100
@@ -67,10 +67,10 @@
         log.info(_("Radio collective initialization"))
         self.inheritFromRoomGame(host)
         RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
-                          game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
+                        game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
         self.host = host
-        host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom, async=True)
-        host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame)
+        host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self._prepareRoom, async=True)
+        host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self._createGame)
         host.bridge.addMethod("radiocolSongAdded", ".plugin", in_sign='sss', out_sign='', method=self.radiocolSongAdded, async=True)
         host.bridge.addSignal("radiocolPlayers", ".plugin", signature='ssass')  # room_jid, referee, players, profile
         host.bridge.addSignal("radiocolStarted", ".plugin", signature='ssasais')  # room_jid, referee, players, [QUEUE_TO_START, QUEUE_LIMIT], profile
@@ -96,7 +96,7 @@
         @param profile_key: %(doc_profile_key)s
         @return: a Deferred instance
         """
-        #XXX: this is a Q&D way for the proof of concept. In the future, the song should
+        # XXX: this is a Q&D way for the proof of concept. In the future, the song should
         #     be streamed to the backend using XMPP file copy
         #     Here we cheat because we know we are on the same host, and we don't
         #     check data. Referee will have to parse the song himself to check it
@@ -115,7 +115,7 @@
             else:
                 song = OggVorbis(song_path)
         except (OggVorbisHeaderError, HeaderNotFoundError):
-            #this file is not ogg vorbis nor mp3, we reject it
+            # this file is not ogg vorbis nor mp3, we reject it
             self.deleteFile(song_path)  # FIXME: same host trick (see note above)
             return defer.fail(exceptions.DataError(D_("The uploaded file has been rejected, only Ogg Vorbis and MP3 songs are accepted.")))
 
@@ -125,16 +125,16 @@
                  'album': song.get("album", ["Unknown"])[0],
                  'length': str(song.info.length)
                  }
-        radio_data = self.games[jid.JID(referee).userhost()]  # FIXME: referee comes from Libervia's client side, it's unsecure
+        radio_data = self.games[jid.JID(referee).userhostJID()]  # FIXME: referee comes from Libervia's client side, it's unsecure
         radio_data['to_delete'][attrs['filename']] = song_path  # FIXME: works only because of the same host trick, see the note under the docstring
         return self.send(jid.JID(referee), ('', 'song_added'), attrs, profile=profile)
 
     def playNext(self, room_jid, profile):
         """"Play next song in queue if exists, and put a timer
         which trigger after the song has been played to play next one"""
-        #TODO: songs need to be erased once played or found invalids
+        # TODO: songs need to be erased once played or found invalids
         #      ==> unlink done the Q&D way with the same host trick (see above)
-        radio_data = self.games[room_jid.userhost()]
+        radio_data = self.games[room_jid]
         if len(radio_data['players']) == 0:
             log.debug(_('No more participants in the radiocol: cleaning data'))
             radio_data['queue'] = []
@@ -143,7 +143,7 @@
             radio_data['to_delete'] = {}
         queue = radio_data['queue']
         if not queue:
-            #nothing left to play, we need to wait for uploads
+            # nothing left to play, we need to wait for uploads
             radio_data['playing'] = None
             return
         song = queue.pop(0)
@@ -153,12 +153,12 @@
         radio_data['playing_time'] = time.time()
 
         if not radio_data['upload'] and len(queue) < QUEUE_LIMIT:
-            #upload is blocked and we now have resources to get more, we reactivate it
+            # upload is blocked and we now have resources to get more, we reactivate it
             self.send(room_jid, ('', 'upload_ok'), profile=profile)
             radio_data['upload'] = True
 
         reactor.callLater(length, self.playNext, room_jid, profile)
-        #we wait more than the song length to delete the file, to manage poorly reactive networks/clients
+        # we wait more than the song length to delete the file, to manage poorly reactive networks/clients
         reactor.callLater(length + 90, self.deleteFile, filename, radio_data)  # FIXME: same host trick (see above)
 
     def deleteFile(self, filename, radio_data=None):
@@ -185,17 +185,17 @@
 
     def room_game_cmd(self, mess_elt, profile):
         from_jid = jid.JID(mess_elt['from'])
-        room_jid = jid.JID(from_jid.userhost())
-        nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid.userhost(), profile)
+        room_jid = from_jid.userhostJID()
+        nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile)
 
         radio_elt = mess_elt.firstChildElement()
-        radio_data = self.games[room_jid.userhost()]
+        radio_data = self.games[room_jid]
         if 'queue' in radio_data:
             queue = radio_data['queue']
 
-        from_referee = self.isReferee(room_jid.userhost(), from_jid.resource)
-        to_referee = self.isReferee(room_jid.userhost(), jid.JID(mess_elt['to']).user)
-        is_player = self.isPlayer(room_jid.userhost(), nick)
+        from_referee = self.isReferee(room_jid, from_jid.resource)
+        to_referee = self.isReferee(room_jid, jid.JID(mess_elt['to']).user)
+        is_player = self.isPlayer(room_jid, nick)
         for elt in radio_elt.elements():
             if not from_referee and not (to_referee and elt.name == 'song_added'):
                 continue  # sender must be referee, expect when a song is submitted
@@ -219,20 +219,20 @@
             elif elt.name == 'upload_ok':
                 self.host.bridge.radiocolUploadOk(room_jid.userhost(), profile)
             elif elt.name == 'song_added':  # a song has been added
-                #FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue.
+                # FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue.
                 #       Need to manage some sort of rules to allow peoples to send songs
                 if len(queue) >= QUEUE_LIMIT:
-                    #there are already too many songs in queue, we reject this one
-                    #FIXME: add an error code
+                    # there are already too many songs in queue, we reject this one
+                    # FIXME: add an error code
                     self.send(from_jid, ('', 'song_rejected'), {'reason': "Too many songs in queue"}, profile=profile)
                     return
 
-                #The song is accepted and added in queue
+                # The song is accepted and added in queue
                 preload_elt = self.__create_preload_elt(from_jid.resource, elt)
                 queue.append(preload_elt)
 
                 if len(queue) >= QUEUE_LIMIT:
-                    #We are at the limit, we refuse new upload until next play
+                    # We are at the limit, we refuse new upload until next play
                     self.send(room_jid, ('', 'no_upload'), profile=profile)
                     radio_data['upload'] = False
 
@@ -244,8 +244,8 @@
             else:
                 log.error(_('Unmanaged game element: %s') % elt.name)
 
-    def getSyncDataForPlayer(self, room_jid_s, nick):
-        game_data = self.games[room_jid_s]
+    def getSyncDataForPlayer(self, room_jid, nick):
+        game_data = self.games[room_jid]
         elements = []
         if game_data['playing']:
             preload = copy.deepcopy(game_data['playing'])