2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 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
|
|
|
|
2010-08-11 14:39:06 +00:00
|
|
|
|
2009-10-30 16:24:34 +00:00
|
|
|
|
2009-09-02 13:05:17 +00:00
|
|
|
import logging
|
|
|
|
|
2009-10-23 12:56:52 +00:00
|
|
|
from hsutil import io
|
2009-06-09 15:35:17 +00:00
|
|
|
from hsutil.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
|
|
|
|
from core.directories import Directories as DirectoriesBase, STATE_EXCLUDED
|
2009-10-23 08:19:48 +00:00
|
|
|
from . import data
|
2009-10-23 13:46:18 +00:00
|
|
|
from .fs import Bundle as BundleBase
|
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
|
|
|
|
2009-10-23 12:56:52 +00:00
|
|
|
class Bundle(BundleBase):
|
|
|
|
@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:
|
|
|
|
return STATE_EXCLUDED
|
|
|
|
if path[:2] == Path('/Users') and path[3:] in self.HOME_PATH_TO_EXCLUDE:
|
|
|
|
return STATE_EXCLUDED
|
|
|
|
|
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
|
|
|
|