2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2011-04-12 08:04:01 +00:00
|
|
|
# Copyright 2011 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-01-11 10:59:53 +00:00
|
|
|
from hscommon import io
|
|
|
|
from hscommon.path import Path
|
2010-07-13 06:08:18 +00:00
|
|
|
from hscommon.cocoa.objcmin import NSWorkspace
|
2009-06-09 15:35:17 +00:00
|
|
|
|
2009-12-30 10:37:57 +00:00
|
|
|
from core import fs
|
|
|
|
from core.app_cocoa import DupeGuru as DupeGuruBase
|
2011-04-12 11:22:29 +00:00
|
|
|
from core.directories import Directories as DirectoriesBase, DirectoryState
|
2009-10-23 08:19:48 +00:00
|
|
|
from . import data
|
2009-06-09 15:35:17 +00:00
|
|
|
|
2009-10-30 16:24:34 +00:00
|
|
|
def is_bundle(str_path):
|
|
|
|
sw = NSWorkspace.sharedWorkspace()
|
2010-02-04 16:12:58 +00:00
|
|
|
uti, error = sw.typeOfFile_error_(str_path, None)
|
2009-10-30 16:24:34 +00:00
|
|
|
if error is not None:
|
2010-08-11 14:39:06 +00:00
|
|
|
logging.warning('There was an error trying to detect the UTI of %s', str_path)
|
2009-10-30 16:24:34 +00:00
|
|
|
return sw.type_conformsToType_(uti, 'com.apple.bundle') or sw.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
|
|
|
|
def can_handle(cls, path):
|
2010-08-11 14:39:06 +00:00
|
|
|
return not io.islink(path) and io.isdir(path) 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):
|
2009-10-23 12:56:52 +00:00
|
|
|
DirectoriesBase.__init__(self, fileclasses=[Bundle, fs.File])
|
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
|
|
|
|
|
|
|
|
def _get_folders(self, from_folder):
|
|
|
|
# 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)
|
|
|
|
from_folder.is_ref = state == DirectoryState.Reference
|
|
|
|
yield from_folder
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
for folder in DirectoriesBase._get_folders(self, from_folder):
|
|
|
|
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):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self):
|
2010-09-29 14:49:50 +00:00
|
|
|
DupeGuruBase.__init__(self, data, 'dupeGuru')
|
2009-06-09 15:35:17 +00:00
|
|
|
self.directories = Directories()
|
2009-06-01 09:55:11 +00:00
|
|
|
|