def _do_trash_files(parent, paths): dialog = TrashDialog.for_files(parent, paths) resp = dialog.run() if resp != TrashDialog.RESPONSE_TRASH: return window_title = _("Moving %(current)d/%(total)d.") w = WaitLoadWindow(parent, len(paths), window_title) w.show() ok = [] failed = [] for path in paths: try: trash.trash(path) except trash.TrashError: failed.append(path) else: ok.append(path) w.step() w.destroy() if failed: ErrorMessage(parent, _("Unable to move to trash"), _("Moving one or more files to the trash failed.") ).run()
def test_trash_removes_file(self): filename = mkstemp()[1] with open(filename, "w") as f: f.write("\n") self.failUnless(os.path.exists(filename)) trash(filename) self.failIf(os.path.exists(filename))
def _do_trash_songs(parent, songs, librarian): dialog = TrashDialog.for_songs(parent, songs) resp = dialog.run() if resp != TrashDialog.RESPONSE_TRASH: return window_title = _("Moving %(current)d/%(total)d.") w = WaitLoadWindow(parent, len(songs), window_title) w.show() ok = [] failed = [] for song in songs: filename = song("~filename") try: trash.trash(filename) except trash.TrashError: failed.append(song) else: ok.append(song) w.step() w.destroy() if failed: ErrorMessage(parent, _("Unable to move to trash"), _("Moving one or more files to the trash failed.") ).run() if ok: librarian.remove(ok)
def run(self): resp = super(DeleteDialog, self).run() if self.__askonly: self.destroy() return resp if resp == 1 or resp == gtk.RESPONSE_DELETE_EVENT: return [] elif resp == 0: s = _("Moving %(current)d/%(total)d.") elif resp == 2: s = _("Deleting %(current)d/%(total)d.") else: return [] files = self.__files w = WaitLoadWindow(self, len(files), s) removed = [] if resp == 0: for filename in files: try: trash.trash(filename) except trash.TrashError: fn = util.escape(util.fsdecode(util.unexpand(filename))) ErrorMessage(self, _("Unable to move to trash"), (_("Moving <b>%s</b> to the trash failed.") % fn)).run() break removed.append(filename) w.step() else: for filename in files: try: os.unlink(filename) except EnvironmentError, s: try: s = unicode(s.strerror, const.ENCODING, 'replace') except TypeError: s = unicode(s.strerror[1], const.ENCODING, 'replace') s = "\n\n" + s fn = util.escape(util.fsdecode(util.unexpand(filename))) ErrorMessage( self, _("Unable to delete file"), (_("Deleting <b>%s</b> failed.") % fn) + s).run() break removed.append(filename) w.step()