def removeFiles(self): """ Remove the files associated with a torrent """ destination = self.getProcDest() if destination is None: return # Remove File ################################################## firsttime = True while 1: #Wait thread a little bit for returning resource ################################################## sleep(0.5) try: if self.isFile(): #remove file if os.access(destination, os.F_OK): os.remove(destination) else: # Only delete files from this torrent # (should be safer this way) subdirs = 0 for x in self.torrent.info['files']: filename = destination subdirs = max(subdirs, len(x['path']) - 1) for i in x['path']: filename = os.path.join(filename, i) if os.access(filename, os.F_OK) and os.path.isfile(filename): os.remove(filename) removeEmptyDir(destination, (subdirs > 0)) break except: #retry >_<; if firsttime: firsttime = False sleep(0.1) else: dialog = wx.MessageDialog(None, _('Error deleting file') + "\n" + format_exc(), _('Error'), wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() break
def moveDir(self, dest, name): if self.isFile(): self.moveSingleFile(dest, name) return destname = self.getProcDest() if destname is None: return filearray = {} movename = os.path.join(dest, name) for f in self.torrent.info['files']: for item in f['path']: size = int(f['length']) filearray[item] = [item, size] self.moveFiles(filearray, destname, movename) removeEmptyDir(destname, True)