1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-03-10 05:34:36 +00:00

Use the send2trash lib in _do_delete_dupe().

This commit is contained in:
Virgil Dupras 2010-04-07 09:11:36 +02:00
parent 3b510389fc
commit 5be76d7c0f
6 changed files with 13 additions and 45 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Created By: Virgil Dupras # Created By: Virgil Dupras
# Created On: 2006/11/11 # Created On: 2006/11/11
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net) # Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
@ -13,6 +12,7 @@ import os
import os.path as op import os.path as op
import logging import logging
from send2trash import send2trash
from hsutil import io, files from hsutil import io, files
from hsutil.path import Path from hsutil.path import Path
from hsutil.reg import RegistrableApplication, RegistrationRequired from hsutil.reg import RegistrableApplication, RegistrationRequired
@ -75,12 +75,14 @@ class DupeGuru(RegistrableApplication, Broadcaster):
def _do_delete_dupe(self, dupe): def _do_delete_dupe(self, dupe):
if not io.exists(dupe.path): if not io.exists(dupe.path):
return True 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]) self.clean_empty_dirs(dupe.path[:-1])
if not io.exists(dupe.path): return True
return True
logging.warning("Could not send {0} to trash.".format(unicode(dupe.path)))
return False
def _do_load(self, j): def _do_load(self, j):
self.directories.load_from_file(op.join(self.appdata, 'last_directories.xml')) self.directories.load_from_file(op.join(self.appdata, 'last_directories.xml'))
@ -113,10 +115,6 @@ class DupeGuru(RegistrableApplication, Broadcaster):
def _open_path(path): def _open_path(path):
raise NotImplementedError() raise NotImplementedError()
@staticmethod
def _recycle_dupe(dupe):
raise NotImplementedError()
@staticmethod @staticmethod
def _reveal_path(path): def _reveal_path(path):
raise NotImplementedError() raise NotImplementedError()

View File

@ -13,10 +13,10 @@ from hsutil import cocoa, job
from hsutil.cocoa import install_exception_hook from hsutil.cocoa import install_exception_hook
from hsutil.cocoa.objcmin import (NSNotificationCenter, NSUserDefaults, from hsutil.cocoa.objcmin import (NSNotificationCenter, NSUserDefaults,
NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask, NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSUserDomainMask,
NSWorkspace, NSWorkspaceRecycleOperation) NSWorkspace)
from hsutil.reg import RegistrationRequired from hsutil.reg import RegistrationRequired
from . import app, fs from . import app
JOBID2TITLE = { JOBID2TITLE = {
app.JOB_SCAN: "Scanning for duplicates", app.JOB_SCAN: "Scanning for duplicates",
@ -51,14 +51,6 @@ class DupeGuru(app.DupeGuru):
def _open_path(path): def _open_path(path):
NSWorkspace.sharedWorkspace().openFile_(unicode(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 @staticmethod
def _reveal_path(path): def _reveal_path(path):
NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(unicode(path), '') NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(unicode(path), '')

View File

@ -121,10 +121,6 @@ class DupeGuru(DupeGuruBase, QObject):
url = QUrl.fromLocalFile(unicode(path)) url = QUrl.fromLocalFile(unicode(path))
QDesktopServices.openUrl(url) QDesktopServices.openUrl(url)
@staticmethod
def _recycle_dupe(dupe):
platform.recycle_file(dupe.path)
@staticmethod @staticmethod
def _reveal_path(path): def _reveal_path(path):
DupeGuru._open_path(path[:-1]) DupeGuru._open_path(path[:-1])

View File

@ -7,7 +7,4 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/hs_license # http://www.hardcoded.net/licenses/hs_license
INITIAL_FOLDER_IN_DIALOGS = '/' INITIAL_FOLDER_IN_DIALOGS = u'/'
def recycle_file(path):
pass

View File

@ -9,7 +9,4 @@
# dummy unit to allow the app to run under OSX during development # dummy unit to allow the app to run under OSX during development
INITIAL_FOLDER_IN_DIALOGS = '/' INITIAL_FOLDER_IN_DIALOGS = u'/'
def recycle_file(path):
pass

View File

@ -7,16 +7,4 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/hs_license # http://www.hardcoded.net/licenses/hs_license
from __future__ import unicode_literals INITIAL_FOLDER_IN_DIALOGS = u'C:\\'
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)