comparison src/plugins/plugin_misc_radiocol.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents c6d8fc63b1db
children 83ed877541e3
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _, D_
21 from logging import debug, info, warning, error 21 from sat.core.log import getLogger
22 log = getLogger(__name__)
22 from twisted.words.xish import domish 23 from twisted.words.xish import domish
23 from twisted.internet import reactor 24 from twisted.internet import reactor
24 from twisted.words.protocols.jabber import jid 25 from twisted.words.protocols.jabber import jid
25 from twisted.internet import defer 26 from twisted.internet import defer
26 from sat.core import exceptions 27 from sat.core import exceptions
61 global RoomGame 62 global RoomGame
62 RoomGame = host.plugins["ROOM-GAME"].__class__ 63 RoomGame = host.plugins["ROOM-GAME"].__class__
63 self.__class__ = type(self.__class__.__name__, (self.__class__, RoomGame, object), {}) 64 self.__class__ = type(self.__class__.__name__, (self.__class__, RoomGame, object), {})
64 65
65 def __init__(self, host): 66 def __init__(self, host):
66 info(_("Radio collective initialization")) 67 log.info(_("Radio collective initialization"))
67 self.inheritFromRoomGame(host) 68 self.inheritFromRoomGame(host)
68 RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG), 69 RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
69 game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}}) 70 game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
70 self.host = host 71 self.host = host
71 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom) 72 host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom)
133 which trigger after the song has been played to play next one""" 134 which trigger after the song has been played to play next one"""
134 #TODO: songs need to be erased once played or found invalids 135 #TODO: songs need to be erased once played or found invalids
135 # ==> unlink done the Q&D way with the same host trick (see above) 136 # ==> unlink done the Q&D way with the same host trick (see above)
136 radio_data = self.games[room_jid.userhost()] 137 radio_data = self.games[room_jid.userhost()]
137 if len(radio_data['players']) == 0: 138 if len(radio_data['players']) == 0:
138 debug(_('No more participants in the radiocol: cleaning data')) 139 log.debug(_('No more participants in the radiocol: cleaning data'))
139 radio_data['queue'] = [] 140 radio_data['queue'] = []
140 for filename in radio_data['to_delete']: 141 for filename in radio_data['to_delete']:
141 self.deleteFile(filename, radio_data) 142 self.deleteFile(filename, radio_data)
142 radio_data['to_delete'] = {} 143 radio_data['to_delete'] = {}
143 queue = radio_data['queue'] 144 queue = radio_data['queue']
169 """ 170 """
170 if radio_data: 171 if radio_data:
171 try: 172 try:
172 file_to_delete = radio_data['to_delete'][filename] 173 file_to_delete = radio_data['to_delete'][filename]
173 except KeyError: 174 except KeyError:
174 error(_("INTERNAL ERROR: can't find full path of the song to delete")) 175 log.error(_("INTERNAL ERROR: can't find full path of the song to delete"))
175 return False 176 return False
176 else: 177 else:
177 file_to_delete = filename 178 file_to_delete = filename
178 try: 179 try:
179 unlink(file_to_delete) 180 unlink(file_to_delete)
180 except OSError: 181 except OSError:
181 error(_("INTERNAL ERROR: can't find %s on the file system" % file_to_delete)) 182 log.error(_("INTERNAL ERROR: can't find %s on the file system" % file_to_delete))
182 return False 183 return False
183 return True 184 return True
184 185
185 def room_game_cmd(self, mess_elt, profile): 186 def room_game_cmd(self, mess_elt, profile):
186 from_jid = jid.JID(mess_elt['from']) 187 from_jid = jid.JID(mess_elt['from'])
239 if not radio_data['playing'] and len(queue) == QUEUE_TO_START: 240 if not radio_data['playing'] and len(queue) == QUEUE_TO_START:
240 # We have not started playing yet, and we have QUEUE_TO_START 241 # We have not started playing yet, and we have QUEUE_TO_START
241 # songs in queue. We can now start the party :) 242 # songs in queue. We can now start the party :)
242 self.playNext(room_jid, profile) 243 self.playNext(room_jid, profile)
243 else: 244 else:
244 error(_('Unmanaged game element: %s') % elt.name) 245 log.error(_('Unmanaged game element: %s') % elt.name)
245 246
246 def getSyncDataForPlayer(self, room_jid_s, nick): 247 def getSyncDataForPlayer(self, room_jid_s, nick):
247 game_data = self.games[room_jid_s] 248 game_data = self.games[room_jid_s]
248 elements = [] 249 elements = []
249 if game_data['playing']: 250 if game_data['playing']: