2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
|
|
|
# $Id$
|
|
|
|
# Copyright 2009 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-06-09 15:35:17 +00:00
|
|
|
from hsfs.phys import Directory as DirectoryBase
|
|
|
|
from hsfs.phys.bundle import Bundle
|
|
|
|
from hsutil.path import Path
|
2009-06-09 17:39:42 +00:00
|
|
|
from hsutil.misc import extract
|
2009-06-09 15:35:17 +00:00
|
|
|
from hsutil.str import get_file_ext
|
|
|
|
|
|
|
|
|
|
|
|
from . import app_cocoa, data
|
|
|
|
from .directories import Directories as DirectoriesBase, STATE_EXCLUDED
|
|
|
|
|
|
|
|
class DGDirectory(DirectoryBase):
|
2009-06-09 17:39:42 +00:00
|
|
|
def _create_sub_file(self, name, with_parent=True):
|
2009-06-09 15:35:17 +00:00
|
|
|
ext = get_file_ext(name)
|
|
|
|
if ext == 'app':
|
|
|
|
parent = self if with_parent else None
|
|
|
|
return Bundle(parent, name)
|
|
|
|
else:
|
2009-06-09 17:39:42 +00:00
|
|
|
return super(DGDirectory, self)._create_sub_file(name, with_parent)
|
|
|
|
|
|
|
|
def _fetch_subitems(self):
|
|
|
|
subdirs, subfiles = super(DGDirectory, self)._fetch_subitems()
|
|
|
|
apps, normal_dirs = extract(lambda name: get_file_ext(name) == 'app', subdirs)
|
|
|
|
subfiles += apps
|
|
|
|
return normal_dirs, subfiles
|
2009-06-09 15:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Directories(DirectoriesBase):
|
|
|
|
ROOT_PATH_TO_EXCLUDE = map(Path, ['/Library', '/Volumes', '/System', '/bin', '/sbin', '/opt', '/private'])
|
|
|
|
HOME_PATH_TO_EXCLUDE = [Path('Library')]
|
|
|
|
def __init__(self):
|
|
|
|
DirectoriesBase.__init__(self)
|
|
|
|
self.dirclass = DGDirectory
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
class DupeGuru(app_cocoa.DupeGuru):
|
|
|
|
def __init__(self):
|
|
|
|
app_cocoa.DupeGuru.__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
|
|
|
|