2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2013-04-28 14:35:51 +00:00
|
|
|
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" 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
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
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):
|
2013-08-19 00:50:31 +00:00
|
|
|
DirectoriesBase.__init__(self, fileclasses=[Bundle, fs.File])
|
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)
|
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):
|
|
|
|
self.model.scanner.min_match_percentage = int(percentage)
|
|
|
|
|
|
|
|
def setScanType_(self, scan_type: int):
|
|
|
|
try:
|
|
|
|
self.model.scanner.scan_type = [
|
|
|
|
ScanType.Filename,
|
|
|
|
ScanType.Contents,
|
|
|
|
ScanType.Folders,
|
|
|
|
][scan_type]
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setWordWeighting_(self, words_are_weighted: bool):
|
|
|
|
self.model.scanner.word_weighting = words_are_weighted
|
|
|
|
|
|
|
|
def setMatchSimilarWords_(self, match_similar_words: bool):
|
|
|
|
self.model.scanner.match_similar_words = match_similar_words
|
|
|
|
|
|
|
|
def setSizeThreshold_(self, size_threshold: int):
|
|
|
|
self.model.scanner.size_threshold = size_threshold
|
|
|
|
|