2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-24
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" 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
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
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
|
|
|
|
2011-04-12 11:22:29 +00:00
|
|
|
from core.directories import Directories as DirectoriesBase, DirectoryState
|
2016-06-06 01:18:48 +00:00
|
|
|
import core.pe.photo
|
|
|
|
from core.pe import _block_osx
|
|
|
|
from core.pe.photo import Photo as PhotoBase
|
|
|
|
from core.app import DupeGuru as DupeGuruBase, AppMode
|
|
|
|
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
|
|
|
|
|
|
|
|
2016-06-06 01:18:48 +00:00
|
|
|
class Photo(PhotoBase):
|
|
|
|
HANDLED_EXTS = PhotoBase.HANDLED_EXTS.copy()
|
|
|
|
HANDLED_EXTS.update({'psd', 'nef', 'cr2', 'orf'})
|
|
|
|
|
|
|
|
def _plat_get_dimensions(self):
|
|
|
|
return _block_osx.get_image_size(str(self.path))
|
|
|
|
|
|
|
|
def _plat_get_blocks(self, block_count_per_side, orientation):
|
|
|
|
try:
|
|
|
|
blocks = _block_osx.getblocks(str(self.path), block_count_per_side, orientation)
|
|
|
|
except Exception as e:
|
|
|
|
raise IOError('The reading of "%s" failed with "%s"' % (str(self.path), str(e)))
|
|
|
|
if not blocks:
|
|
|
|
raise IOError('The picture %s could not be read' % str(self.path))
|
|
|
|
return blocks
|
|
|
|
|
|
|
|
def _get_exif_timestamp(self):
|
|
|
|
exifdata = proxy.readExifData_(str(self.path))
|
|
|
|
if exifdata:
|
|
|
|
try:
|
|
|
|
return exifdata['{Exif}']['DateTimeOriginal']
|
|
|
|
except KeyError:
|
|
|
|
return ''
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
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')]
|
2016-06-06 01:18:48 +00:00
|
|
|
|
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:
|
2016-06-06 01:18:48 +00:00
|
|
|
yield from DirectoriesBase._get_folders(self, from_folder, j)
|
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):
|
|
|
|
DupeGuruBase.__init__(self, view)
|
2009-06-09 15:35:17 +00:00
|
|
|
self.directories = Directories()
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2016-06-06 01:18:48 +00:00
|
|
|
def selected_dupe_path(self):
|
|
|
|
if not self.selected_dupes:
|
|
|
|
return None
|
|
|
|
return self.selected_dupes[0].path
|
|
|
|
|
|
|
|
def selected_dupe_ref_path(self):
|
|
|
|
if not self.selected_dupes:
|
|
|
|
return None
|
|
|
|
ref = self.results.get_group_of_duplicate(self.selected_dupes[0]).ref
|
|
|
|
if ref is self.selected_dupes[0]: # we don't want the same pic to be displayed on both sides
|
|
|
|
return None
|
|
|
|
return ref.path
|
|
|
|
|
|
|
|
def _get_fileclasses(self):
|
|
|
|
result = DupeGuruBase._get_fileclasses(self)
|
|
|
|
if self.app_mode == AppMode.Standard:
|
|
|
|
result = [Bundle] + result
|
|
|
|
return result
|
2012-01-13 19:43:43 +00:00
|
|
|
|
|
|
|
class PyDupeGuru(PyDupeGuruBase):
|
|
|
|
def __init__(self):
|
2016-06-06 01:18:48 +00:00
|
|
|
core.pe.photo.PLAT_SPECIFIC_PHOTO_CLASS = Photo
|
2012-01-13 19:43:43 +00:00
|
|
|
self._init(DupeGuru)
|
2016-06-06 01:18:48 +00:00
|
|
|
|
2012-01-13 19:43:43 +00:00
|
|
|
|