diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_misc_radiocol.py	Tue Dec 24 15:43:52 2013 +0100
+++ b/src/plugins/plugin_misc_radiocol.py	Tue Dec 17 11:35:41 2013 +0100
@@ -131,7 +131,7 @@
             debug(_('No more participants in the radiocol: cleaning data'))
             radio_data['queue'] = []
             for filename in radio_data['to_delete']:
-                self.deleteFile(radio_data, filename)
+                self.deleteFile(filename, radio_data)
             radio_data['to_delete'] = {}
         queue = radio_data['queue']
         if not queue:
@@ -150,14 +150,23 @@
 
         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
-        reactor.callLater(length + 90, self.deleteFile, radio_data, filename)  # FIXME: same host trick (see above)
+        reactor.callLater(length + 90, self.deleteFile, filename, radio_data)  # FIXME: same host trick (see above)
 
-    def deleteFile(self, radio_data, filename):
-        try:
-            file_to_delete = radio_data['to_delete'][filename]
-        except KeyError:
-            error(_("INTERNAL ERROR: can't find full path of the song to delete"))
-            return False
+    def deleteFile(self, filename, radio_data=None):
+        """
+        Delete a previously uploaded file.
+        @param filename: filename to delete, or full filepath if radio_data is None
+        @param radio_data: current game data
+        @return: True if the file has been deleted
+        """
+        if radio_data:
+            try:
+                file_to_delete = radio_data['to_delete'][filename]
+            except KeyError:
+                error(_("INTERNAL ERROR: can't find full path of the song to delete"))
+                return False
+        else:
+            file_to_delete = filename
         try:
             unlink(file_to_delete)
         except OSError: