Mercurial > libervia-backend
comparison src/plugins/plugin_misc_radiocol.py @ 764:d0e809014ea2
plugin radiocol: fix wrong call of deleteFile
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 17 Dec 2013 11:35:41 +0100 |
parents | 539f278bc265 |
children | 787ee59dba9c |
comparison
equal
deleted
inserted
replaced
763:ab851b46009c | 764:d0e809014ea2 |
---|---|
129 radio_data = self.games[room_jid.userhost()] | 129 radio_data = self.games[room_jid.userhost()] |
130 if len(radio_data['players']) == 0: | 130 if len(radio_data['players']) == 0: |
131 debug(_('No more participants in the radiocol: cleaning data')) | 131 debug(_('No more participants in the radiocol: cleaning data')) |
132 radio_data['queue'] = [] | 132 radio_data['queue'] = [] |
133 for filename in radio_data['to_delete']: | 133 for filename in radio_data['to_delete']: |
134 self.deleteFile(radio_data, filename) | 134 self.deleteFile(filename, radio_data) |
135 radio_data['to_delete'] = {} | 135 radio_data['to_delete'] = {} |
136 queue = radio_data['queue'] | 136 queue = radio_data['queue'] |
137 if not queue: | 137 if not queue: |
138 #nothing left to play, we need to wait for uploads | 138 #nothing left to play, we need to wait for uploads |
139 radio_data['playing'] = False | 139 radio_data['playing'] = False |
148 self.send(room_jid, ('', 'upload_ok'), profile=profile) | 148 self.send(room_jid, ('', 'upload_ok'), profile=profile) |
149 radio_data['upload'] = True | 149 radio_data['upload'] = True |
150 | 150 |
151 reactor.callLater(length, self.playNext, room_jid, profile) | 151 reactor.callLater(length, self.playNext, room_jid, profile) |
152 #we wait more than the song length to delete the file, to manage poorly reactive networks/clients | 152 #we wait more than the song length to delete the file, to manage poorly reactive networks/clients |
153 reactor.callLater(length + 90, self.deleteFile, radio_data, filename) # FIXME: same host trick (see above) | 153 reactor.callLater(length + 90, self.deleteFile, filename, radio_data) # FIXME: same host trick (see above) |
154 | 154 |
155 def deleteFile(self, radio_data, filename): | 155 def deleteFile(self, filename, radio_data=None): |
156 try: | 156 """ |
157 file_to_delete = radio_data['to_delete'][filename] | 157 Delete a previously uploaded file. |
158 except KeyError: | 158 @param filename: filename to delete, or full filepath if radio_data is None |
159 error(_("INTERNAL ERROR: can't find full path of the song to delete")) | 159 @param radio_data: current game data |
160 return False | 160 @return: True if the file has been deleted |
161 """ | |
162 if radio_data: | |
163 try: | |
164 file_to_delete = radio_data['to_delete'][filename] | |
165 except KeyError: | |
166 error(_("INTERNAL ERROR: can't find full path of the song to delete")) | |
167 return False | |
168 else: | |
169 file_to_delete = filename | |
161 try: | 170 try: |
162 unlink(file_to_delete) | 171 unlink(file_to_delete) |
163 except OSError: | 172 except OSError: |
164 error(_("INTERNAL ERROR: can't find %s on the file system" % file_to_delete)) | 173 error(_("INTERNAL ERROR: can't find %s on the file system" % file_to_delete)) |
165 return False | 174 return False |