Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_radiocol.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT plugin for managing Radiocol | 4 # SAT plugin for managing Radiocol |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
37 from mutagen.mp3 import MP3, HeaderNotFoundError | 37 from mutagen.mp3 import MP3, HeaderNotFoundError |
38 from mutagen.easyid3 import EasyID3 | 38 from mutagen.easyid3 import EasyID3 |
39 from mutagen.id3 import ID3NoHeaderError | 39 from mutagen.id3 import ID3NoHeaderError |
40 except ImportError: | 40 except ImportError: |
41 raise exceptions.MissingModule( | 41 raise exceptions.MissingModule( |
42 u"Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen" | 42 "Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen" |
43 ) | 43 ) |
44 | 44 |
45 | 45 |
46 NC_RADIOCOL = "http://www.goffi.org/protocol/radiocol" | 46 NC_RADIOCOL = "http://www.goffi.org/protocol/radiocol" |
47 RADIOC_TAG = "radiocol" | 47 RADIOC_TAG = "radiocol" |
93 "radiocolLaunch", | 93 "radiocolLaunch", |
94 ".plugin", | 94 ".plugin", |
95 in_sign="asss", | 95 in_sign="asss", |
96 out_sign="", | 96 out_sign="", |
97 method=self._prepareRoom, | 97 method=self._prepareRoom, |
98 async=True, | 98 async_=True, |
99 ) | 99 ) |
100 host.bridge.addMethod( | 100 host.bridge.addMethod( |
101 "radiocolCreate", | 101 "radiocolCreate", |
102 ".plugin", | 102 ".plugin", |
103 in_sign="sass", | 103 in_sign="sass", |
108 "radiocolSongAdded", | 108 "radiocolSongAdded", |
109 ".plugin", | 109 ".plugin", |
110 in_sign="sss", | 110 in_sign="sss", |
111 out_sign="", | 111 out_sign="", |
112 method=self._radiocolSongAdded, | 112 method=self._radiocolSongAdded, |
113 async=True, | 113 async_=True, |
114 ) | 114 ) |
115 host.bridge.addSignal( | 115 host.bridge.addSignal( |
116 "radiocolPlayers", ".plugin", signature="ssass" | 116 "radiocolPlayers", ".plugin", signature="ssass" |
117 ) # room_jid, referee, players, profile | 117 ) # room_jid, referee, players, profile |
118 host.bridge.addSignal( | 118 host.bridge.addSignal( |
205 which trigger after the song has been played to play next one""" | 205 which trigger after the song has been played to play next one""" |
206 # TODO: songs need to be erased once played or found invalids | 206 # TODO: songs need to be erased once played or found invalids |
207 # ==> unlink done the Q&D way with the same host trick (see above) | 207 # ==> unlink done the Q&D way with the same host trick (see above) |
208 radio_data = self.games[room_jid] | 208 radio_data = self.games[room_jid] |
209 if len(radio_data["players"]) == 0: | 209 if len(radio_data["players"]) == 0: |
210 log.debug(_(u"No more participants in the radiocol: cleaning data")) | 210 log.debug(_("No more participants in the radiocol: cleaning data")) |
211 radio_data["queue"] = [] | 211 radio_data["queue"] = [] |
212 for filename in radio_data["to_delete"]: | 212 for filename in radio_data["to_delete"]: |
213 self.deleteFile(filename, radio_data) | 213 self.deleteFile(filename, radio_data) |
214 radio_data["to_delete"] = {} | 214 radio_data["to_delete"] = {} |
215 queue = radio_data["queue"] | 215 queue = radio_data["queue"] |
244 if radio_data: | 244 if radio_data: |
245 try: | 245 try: |
246 file_to_delete = radio_data["to_delete"][filename] | 246 file_to_delete = radio_data["to_delete"][filename] |
247 except KeyError: | 247 except KeyError: |
248 log.error( | 248 log.error( |
249 _(u"INTERNAL ERROR: can't find full path of the song to delete") | 249 _("INTERNAL ERROR: can't find full path of the song to delete") |
250 ) | 250 ) |
251 return False | 251 return False |
252 else: | 252 else: |
253 file_to_delete = filename | 253 file_to_delete = filename |
254 try: | 254 try: |
255 unlink(file_to_delete) | 255 unlink(file_to_delete) |
256 except OSError: | 256 except OSError: |
257 log.error( | 257 log.error( |
258 _(u"INTERNAL ERROR: can't find %s on the file system" % file_to_delete) | 258 _("INTERNAL ERROR: can't find %s on the file system" % file_to_delete) |
259 ) | 259 ) |
260 return False | 260 return False |
261 return True | 261 return True |
262 | 262 |
263 def room_game_cmd(self, mess_elt, profile): | 263 def room_game_cmd(self, mess_elt, profile): |
283 "started", | 283 "started", |
284 "players", | 284 "players", |
285 ): # new game created and/or players list updated | 285 ): # new game created and/or players list updated |
286 players = [] | 286 players = [] |
287 for player in elt.elements(): | 287 for player in elt.elements(): |
288 players.append(unicode(player)) | 288 players.append(str(player)) |
289 signal = ( | 289 signal = ( |
290 self.host.bridge.radiocolStarted | 290 self.host.bridge.radiocolStarted |
291 if elt.name == "started" | 291 if elt.name == "started" |
292 else self.host.bridge.radiocolPlayers | 292 else self.host.bridge.radiocolPlayers |
293 ) | 293 ) |
348 if not radio_data["playing"] and len(queue) == QUEUE_TO_START: | 348 if not radio_data["playing"] and len(queue) == QUEUE_TO_START: |
349 # We have not started playing yet, and we have QUEUE_TO_START | 349 # We have not started playing yet, and we have QUEUE_TO_START |
350 # songs in queue. We can now start the party :) | 350 # songs in queue. We can now start the party :) |
351 self.playNext(room_jid, profile) | 351 self.playNext(room_jid, profile) |
352 else: | 352 else: |
353 log.error(_(u"Unmanaged game element: %s") % elt.name) | 353 log.error(_("Unmanaged game element: %s") % elt.name) |
354 | 354 |
355 def getSyncDataForPlayer(self, room_jid, nick): | 355 def getSyncDataForPlayer(self, room_jid, nick): |
356 game_data = self.games[room_jid] | 356 game_data = self.games[room_jid] |
357 elements = [] | 357 elements = [] |
358 if game_data["playing"]: | 358 if game_data["playing"]: |