2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
|
|
|
# $Id$
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "HS" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
|
|
|
# http://www.hardcoded.net/licenses/hs_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-10-30 16:24:34 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2009-09-02 13:05:17 +00:00
|
|
|
import logging
|
|
|
|
|
2009-12-16 14:48:18 +00:00
|
|
|
import objc
|
2009-09-02 13:05:17 +00:00
|
|
|
from AppKit import *
|
|
|
|
|
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
|
|
|
|
from hsutil.str import get_file_ext
|
|
|
|
|
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()
|
2009-12-16 14:48:18 +00:00
|
|
|
if objc.__version__ == '1.4': # For a while, we have to support this.
|
|
|
|
uti, error = sw.typeOfFile_error_(str_path)
|
|
|
|
else:
|
|
|
|
uti, error = sw.typeOfFile_error_(str_path, None)
|
2009-10-30 16:24:34 +00:00
|
|
|
if error is not None:
|
|
|
|
logging.warning(u'There was an error trying to detect the UTI of %s', str_path)
|
|
|
|
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):
|
|
|
|
return not io.islink(path) and io.isdir(path) and is_bundle(unicode(path))
|
2009-06-09 15:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Directories(DirectoriesBase):
|
2009-09-28 16:19:27 +00:00
|
|
|
ROOT_PATH_TO_EXCLUDE = 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):
|
2009-10-23 13:46:18 +00:00
|
|
|
DupeGuruBase.__init__(self, data, 'dupeGuru', appid=4)
|
2009-06-09 15:35:17 +00:00
|
|
|
self.directories = Directories()
|
2009-06-01 09:55:11 +00:00
|
|
|
|