2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-09-02 13:05:17 +00:00
|
|
|
import logging
|
2011-09-20 22:40:27 +00:00
|
|
|
import os.path as op
|
2009-09-02 13:05:17 +00:00
|
|
|
|
2013-11-16 17:06:16 +00:00
|
|
|
from hscommon.path import Path, pathify
|
2012-01-05 21:57:31 +00:00
|
|
|
from cocoa import proxy
|
2009-06-09 15:35:17 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
from core.scanner import ScanType
|
2011-04-12 11:22:29 +00:00
|
|
|
from core.directories import Directories as DirectoriesBase, DirectoryState
|
2011-09-21 20:02:13 +00:00
|
|
|
from core_se.app import DupeGuru as DupeGuruBase
|
2013-08-19 00:50:31 +00:00
|
|
|
from core_se import fs
|
2012-01-13 19:43:43 +00:00
|
|
|
from .app import PyDupeGuruBase
|
2009-06-09 15:35:17 +00:00
|
|
|
|
2009-10-30 16:24:34 +00:00
|
|
|
def is_bundle(str_path):
|
2011-12-28 19:51:33 +00:00
|
|
|
uti = proxy.getUTI_(str_path)
|
|
|
|
if uti is None:
|
2010-08-11 14:39:06 +00:00
|
|
|
logging.warning('There was an error trying to detect the UTI of %s', str_path)
|
2011-12-28 19:51:33 +00:00
|
|
|
return proxy.type_conformsToType_(uti, 'com.apple.bundle') or proxy.type_conformsToType_(uti, 'com.apple.package')
|
2009-09-02 13:05:17 +00:00
|
|
|
|
2011-04-12 11:22:29 +00:00
|
|
|
class Bundle(fs.Folder):
|
2009-10-23 12:56:52 +00:00
|
|
|
@classmethod
|
2013-11-16 17:06:16 +00:00
|
|
|
@pathify
|
|
|
|
def can_handle(cls, path: Path):
|
|
|
|
return not path.islink() and path.isdir() and is_bundle(str(path))
|
2009-06-09 15:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Directories(DirectoriesBase):
|
2010-08-11 14:39:06 +00:00
|
|
|
ROOT_PATH_TO_EXCLUDE = list(map(Path, ['/Library', '/Volumes', '/System', '/bin', '/sbin', '/opt', '/private', '/dev']))
|
2009-06-09 15:35:17 +00:00
|
|
|
HOME_PATH_TO_EXCLUDE = [Path('Library')]
|
|
|
|
def __init__(self):
|
2016-06-02 01:56:18 +00:00
|
|
|
DirectoriesBase.__init__(self)
|
2013-08-19 01:07:33 +00:00
|
|
|
self.folderclass = fs.Folder
|
2009-06-09 15:35:17 +00:00
|
|
|
|
|
|
|
def _default_state_for_path(self, path):
|
|
|
|
result = DirectoriesBase._default_state_for_path(self, path)
|
|
|
|
if result is not None:
|
|
|
|
return result
|
|
|
|
if path in self.ROOT_PATH_TO_EXCLUDE:
|
2011-04-12 11:22:29 +00:00
|
|
|
return DirectoryState.Excluded
|
2009-06-09 15:35:17 +00:00
|
|
|
if path[:2] == Path('/Users') and path[3:] in self.HOME_PATH_TO_EXCLUDE:
|
2011-04-12 11:22:29 +00:00
|
|
|
return DirectoryState.Excluded
|
|
|
|
|
2011-08-25 13:37:30 +00:00
|
|
|
def _get_folders(self, from_folder, j):
|
2011-04-12 11:22:29 +00:00
|
|
|
# We don't want to scan bundle's subfolder even in Folders mode. Bundle's integrity has to
|
|
|
|
# stay intact.
|
|
|
|
if is_bundle(str(from_folder.path)):
|
|
|
|
# just yield the current folder and bail
|
|
|
|
state = self.get_state(from_folder.path)
|
2011-04-14 13:37:12 +00:00
|
|
|
if state != DirectoryState.Excluded:
|
|
|
|
from_folder.is_ref = state == DirectoryState.Reference
|
|
|
|
yield from_folder
|
2011-04-12 11:22:29 +00:00
|
|
|
return
|
|
|
|
else:
|
2011-08-25 13:37:30 +00:00
|
|
|
for folder in DirectoriesBase._get_folders(self, from_folder, j):
|
2011-04-12 11:22:29 +00:00
|
|
|
yield folder
|
2009-06-09 15:35:17 +00:00
|
|
|
|
2011-01-24 11:35:07 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_subfolders(path):
|
|
|
|
result = DirectoriesBase.get_subfolders(path)
|
|
|
|
return [p for p in result if not is_bundle(str(p))]
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-10-23 08:19:48 +00:00
|
|
|
class DupeGuru(DupeGuruBase):
|
2013-11-10 16:05:03 +00:00
|
|
|
def __init__(self, view):
|
|
|
|
# appdata = op.join(appdata, 'dupeGuru')
|
|
|
|
# print(repr(appdata))
|
|
|
|
DupeGuruBase.__init__(self, view)
|
2016-06-02 01:56:18 +00:00
|
|
|
self.fileclasses = [Bundle, fs.File]
|
2009-06-09 15:35:17 +00:00
|
|
|
self.directories = Directories()
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
|
|
|
|
class PyDupeGuru(PyDupeGuruBase):
|
|
|
|
def __init__(self):
|
|
|
|
self._init(DupeGuru)
|
|
|
|
|
|
|
|
#---Properties
|
|
|
|
def setMinMatchPercentage_(self, percentage: int):
|
2016-06-02 01:56:18 +00:00
|
|
|
self.model.options['min_match_percentage'] = int(percentage)
|
2012-01-13 19:43:43 +00:00
|
|
|
|
|
|
|
def setScanType_(self, scan_type: int):
|
|
|
|
try:
|
2016-06-02 01:56:18 +00:00
|
|
|
self.model.options['scan_type'] = [
|
2012-01-13 19:43:43 +00:00
|
|
|
ScanType.Filename,
|
|
|
|
ScanType.Contents,
|
|
|
|
ScanType.Folders,
|
|
|
|
][scan_type]
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setWordWeighting_(self, words_are_weighted: bool):
|
2016-06-02 01:56:18 +00:00
|
|
|
self.model.options['word_weighting'] = words_are_weighted
|
2012-01-13 19:43:43 +00:00
|
|
|
|
|
|
|
def setMatchSimilarWords_(self, match_similar_words: bool):
|
2016-06-02 01:56:18 +00:00
|
|
|
self.model.options['match_similar_words'] = match_similar_words
|
2012-01-13 19:43:43 +00:00
|
|
|
|
|
|
|
def setSizeThreshold_(self, size_threshold: int):
|
2016-06-02 01:56:18 +00:00
|
|
|
self.model.options['size_threshold'] = size_threshold
|
2012-01-13 19:43:43 +00:00
|
|
|
|