From 5be76d7c0f84b9d77a8c3f6d7d8c9a5b8bd98017 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Wed, 7 Apr 2010 09:11:36 +0200 Subject: [PATCH] Use the send2trash lib in _do_delete_dupe(). --- core/app.py | 18 ++++++++---------- core/app_cocoa.py | 12 ++---------- qt/base/app.py | 4 ---- qt/base/platform_lnx.py | 5 +---- qt/base/platform_osx.py | 5 +---- qt/base/platform_win.py | 14 +------------- 6 files changed, 13 insertions(+), 45 deletions(-) diff --git a/core/app.py b/core/app.py index 98bdab02..59ea72ae 100644 --- a/core/app.py +++ b/core/app.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # Created By: Virgil Dupras # Created On: 2006/11/11 # Copyright 2010 Hardcoded Software (http://www.hardcoded.net) @@ -13,6 +12,7 @@ import os import os.path as op import logging +from send2trash import send2trash from hsutil import io, files from hsutil.path import Path from hsutil.reg import RegistrableApplication, RegistrationRequired @@ -75,12 +75,14 @@ class DupeGuru(RegistrableApplication, Broadcaster): def _do_delete_dupe(self, dupe): if not io.exists(dupe.path): return True - self._recycle_dupe(dupe) + try: + send2trash(unicode(dupe.path)) + except OSError as e: + msg = "Could not send {0} to trash: {1}" + logging.warning(msg.format(unicode(dupe.path), unicode(e))) + return False self.clean_empty_dirs(dupe.path[:-1]) - if not io.exists(dupe.path): - return True - logging.warning("Could not send {0} to trash.".format(unicode(dupe.path))) - return False + return True def _do_load(self, j): self.directories.load_from_file(op.join(self.appdata, 'last_directories.xml')) @@ -113,10 +115,6 @@ class DupeGuru(RegistrableApplication, Broadcaster): def _open_path(path): raise NotImplementedError() - @staticmethod - def _recycle_dupe(dupe): - raise NotImplementedError() - @staticmethod def _reveal_path(path): raise NotImplementedError() diff --git a/core/app_cocoa.py b/core/app_cocoa.py index 48821f62..d1ea28b9 100644 --- a/core/app_cocoa.py +++ b/core/app_cocoa.py @@ -13,10 +13,10 @@ from hsutil import cocoa, job from hsutil.cocoa import install_exception_hook from hsutil.cocoa.objcmin import (NSNotificationCenter, NSUserDefaults, NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask, - NSWorkspace, NSWorkspaceRecycleOperation) + NSWorkspace) from hsutil.reg import RegistrationRequired -from . import app, fs +from . import app JOBID2TITLE = { app.JOB_SCAN: "Scanning for duplicates", @@ -51,14 +51,6 @@ class DupeGuru(app.DupeGuru): def _open_path(path): NSWorkspace.sharedWorkspace().openFile_(unicode(path)) - @staticmethod - def _recycle_dupe(dupe): - # local import because first appkit import takes a lot of memory. we want to avoid it. - directory = unicode(dupe.path[:-1]) - filename = dupe.name - result, tag = NSWorkspace.sharedWorkspace().performFileOperation_source_destination_files_tag_( - NSWorkspaceRecycleOperation, directory, '', [filename], None) - @staticmethod def _reveal_path(path): NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(unicode(path), '') diff --git a/qt/base/app.py b/qt/base/app.py index b15006b0..279d824d 100644 --- a/qt/base/app.py +++ b/qt/base/app.py @@ -121,10 +121,6 @@ class DupeGuru(DupeGuruBase, QObject): url = QUrl.fromLocalFile(unicode(path)) QDesktopServices.openUrl(url) - @staticmethod - def _recycle_dupe(dupe): - platform.recycle_file(dupe.path) - @staticmethod def _reveal_path(path): DupeGuru._open_path(path[:-1]) diff --git a/qt/base/platform_lnx.py b/qt/base/platform_lnx.py index 4f97c1fa..07dd08ef 100644 --- a/qt/base/platform_lnx.py +++ b/qt/base/platform_lnx.py @@ -7,7 +7,4 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/hs_license -INITIAL_FOLDER_IN_DIALOGS = '/' - -def recycle_file(path): - pass +INITIAL_FOLDER_IN_DIALOGS = u'/' \ No newline at end of file diff --git a/qt/base/platform_osx.py b/qt/base/platform_osx.py index b662ca8e..0379656e 100644 --- a/qt/base/platform_osx.py +++ b/qt/base/platform_osx.py @@ -9,7 +9,4 @@ # dummy unit to allow the app to run under OSX during development -INITIAL_FOLDER_IN_DIALOGS = '/' - -def recycle_file(path): - pass +INITIAL_FOLDER_IN_DIALOGS = u'/' \ No newline at end of file diff --git a/qt/base/platform_win.py b/qt/base/platform_win.py index b22d2dbe..1e2aefe3 100644 --- a/qt/base/platform_win.py +++ b/qt/base/platform_win.py @@ -7,16 +7,4 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/hs_license -from __future__ import unicode_literals - -import logging - -import winshell - -INITIAL_FOLDER_IN_DIALOGS = 'C:\\' - -def recycle_file(path): - try: - winshell.delete_file(unicode(path), no_confirm=True, silent=True) - except winshell.x_winshell as e: - logging.warning("winshell error: %s", e) +INITIAL_FOLDER_IN_DIALOGS = u'C:\\' \ No newline at end of file