diff --git a/core/app.py b/core/app.py index 0345622a..91a83745 100644 --- a/core/app.py +++ b/core/app.py @@ -92,10 +92,13 @@ class DupeGuru(RegistrableApplication, Broadcaster): logging.warning("Exception on GetDisplayInfo for %s: %s", str(dupe.path), str(e)) return ['---'] * len(self.data.COLUMNS) + def _create_file(self, path): + # We add fs.Folder to fileclasses in case the file we're loading contains folder paths. + return fs.get_file(path, self.directories.fileclasses + [fs.Folder]) + def _get_file(self, str_path): path = Path(str_path) - # We add fs.Folder to fileclasses in case the file we're loading contains folder paths. - f = fs.get_file(path, self.directories.fileclasses + [fs.Folder]) + f = self._create_file(path) if f is None: return None try: diff --git a/core/data.py b/core/data.py index cae3e1aa..3d7eb5c5 100644 --- a/core/data.py +++ b/core/data.py @@ -14,9 +14,6 @@ import time Column = namedtuple('Column', 'attr display') -def format_path(p): - return str(p[:-1]) - def format_timestamp(t, delta): if delta: return format_time_decimal(t) diff --git a/core/fs.py b/core/fs.py index 35830f49..c1b73d7b 100644 --- a/core/fs.py +++ b/core/fs.py @@ -149,6 +149,10 @@ class File: def name(self): return self.path[-1] + @property + def folder_path(self): + return self.path[:-1] + class Folder(File): """A wrapper around a folder path. diff --git a/core/results.py b/core/results.py index 545af95c..2dd116e4 100644 --- a/core/results.py +++ b/core/results.py @@ -328,15 +328,13 @@ class Results(Markable): def sort_dupes(self, key, asc=True, delta=False): if not self.__dupes: self.__get_dupe_list() - self.__dupes.sort(key=lambda d: self.data.GetDupeSortKey(d, lambda: self.get_group_of_duplicate(d), key, delta)) - if not asc: - self.__dupes.reverse() + keyfunc = lambda d: self.data.GetDupeSortKey(d, lambda: self.get_group_of_duplicate(d), key, delta) + self.__dupes.sort(key=keyfunc, reverse=not asc) self.__dupes_sort_descriptor = (key,asc,delta) def sort_groups(self,key,asc=True): - self.groups.sort(key=lambda g: self.data.GetGroupSortKey(g, key)) - if not asc: - self.groups.reverse() + keyfunc = lambda g: self.data.GetGroupSortKey(g, key) + self.groups.sort(key=keyfunc, reverse=not asc) self.__groups_sort_descriptor = (key,asc) #---Properties diff --git a/core/tests/data.py b/core/tests/data.py index eca6c75c..ee0e4b36 100644 --- a/core/tests/data.py +++ b/core/tests/data.py @@ -9,11 +9,11 @@ # data module for tests from hscommon.util import format_size -from ..data import format_path, cmp_value, Column +from ..data import cmp_value, Column COLUMNS = [ Column('name', 'Filename'), - Column('path', 'Directory'), + Column('folder_path', 'Directory'), Column('size', 'Size (KB)'), Column('extension', 'Kind'), ] @@ -29,7 +29,7 @@ def GetDisplayInfo(dupe, group, delta): size -= r.size return [ dupe.name, - format_path(dupe.path), + str(dupe.folder_path), format_size(size, 0, 1, False), dupe.extension if hasattr(dupe, 'extension') else '---', ] diff --git a/core/tests/results_test.py b/core/tests/results_test.py index f66698e9..d726dbec 100644 --- a/core/tests/results_test.py +++ b/core/tests/results_test.py @@ -26,6 +26,11 @@ class NamedObject(engine_test.NamedObject): def __bool__(self): return False #Make sure that operations are made correctly when the bool value of files is false. + + @property + def folder_path(self): + return self.path[:-1] + # Returns a group set that looks like that: # "foo bar" (1) diff --git a/core_me/data.py b/core_me/data.py index 3c3bbce8..82b3a04e 100644 --- a/core_me/data.py +++ b/core_me/data.py @@ -8,14 +8,14 @@ from hscommon.util import format_time, format_size from hscommon.trans import tr as trbase -from core.data import (format_path, format_timestamp, format_words, format_perc, - format_dupe_count, cmp_value, Column) +from core.data import (format_timestamp, format_words, format_perc, format_dupe_count, cmp_value, + Column) tr = lambda s: trbase(s, 'columns') COLUMNS = [ Column('name', tr("Filename")), - Column('path', tr("Folder")), + Column('folder_path', tr("Folder")), Column('size', tr("Size (MB)")), Column('duration', tr("Time")), Column('bitrate', tr("Bitrate")), @@ -63,7 +63,7 @@ def GetDisplayInfo(dupe, group, delta): dupe_count = len(group.dupes) return [ dupe.name, - format_path(dupe.path), + str(dupe.folder_path), format_size(size, 2, 2, False), format_time(duration, with_hours=False), str(bitrate), diff --git a/core_pe/app_cocoa.py b/core_pe/app_cocoa.py index b22ab1e0..0e2d5d01 100644 --- a/core_pe/app_cocoa.py +++ b/core_pe/app_cocoa.py @@ -45,8 +45,8 @@ class Photo(PhotoBase): class IPhoto(Photo): @property - def display_path(self): - return Path(('iPhoto Library', self.name)) + def display_folder_path(self): + return IPHOTO_PATH def get_iphoto_database_path(): ud = NSUserDefaults.standardUserDefaults() @@ -166,11 +166,10 @@ class DupeGuruPE(app_cocoa.DupeGuru): else: app_cocoa.DupeGuru._do_delete_dupe(self, dupe, replace_with_hardlinks) - def _get_file(self, str_path): - p = Path(str_path) - if (self.directories.iphoto_libpath is not None) and (p in self.directories.iphoto_libpath[:-1]): - return IPhoto(p) - return app_cocoa.DupeGuru._get_file(self, str_path) + def _create_file(self, path): + if (self.directories.iphoto_libpath is not None) and (path in self.directories.iphoto_libpath[:-1]): + return IPhoto(path) + return app_cocoa.DupeGuru._create_file(self, path) def copy_or_move(self, dupe, copy, destination, dest_type): if isinstance(dupe, IPhoto): diff --git a/core_pe/data.py b/core_pe/data.py index be0a3488..f1df3d9d 100644 --- a/core_pe/data.py +++ b/core_pe/data.py @@ -8,7 +8,7 @@ from hscommon.util import format_size from hscommon.trans import tr as trbase -from core.data import format_path, format_timestamp, format_perc, format_dupe_count, cmp_value, Column +from core.data import format_timestamp, format_perc, format_dupe_count, cmp_value, Column tr = lambda s: trbase(s, 'columns') @@ -17,7 +17,7 @@ def format_dimensions(dimensions): COLUMNS = [ Column('name', tr("Filename")), - Column('path', tr("Folder")), + Column('folder_path', tr("Folder")), Column('size', tr("Size (KB)")), Column('extension', tr("Kind")), Column('dimensions', tr("Dimensions")), @@ -26,6 +26,7 @@ COLUMNS = [ Column('dupe_count', tr("Dupe Count")), ] +FOLDER_COL = 1 MATCHPERC_COL = 6 DUPECOUNT_COL = 7 DELTA_COLUMNS = {2, 4, 5} @@ -53,10 +54,10 @@ def GetDisplayInfo(dupe,group,delta=False): else: percentage = group.percentage dupe_count = len(group.dupes) - dupe_path = getattr(dupe, 'display_path', dupe.path) + dupe_folder_path = getattr(dupe, 'display_folder_path', dupe.folder_path) return [ dupe.name, - format_path(dupe_path), + str(dupe_folder_path), format_size(size, 0, 1, False), dupe.extension, format_dimensions(dimensions), @@ -71,6 +72,9 @@ def GetDupeSortKey(dupe, get_group, key, delta): return m.percentage if key == DUPECOUNT_COL: return 0 + if key == FOLDER_COL: + dupe_folder_path = getattr(dupe, 'display_folder_path', dupe.folder_path) + return cmp_value(str(dupe_folder_path)) r = cmp_value(getattr(dupe, COLUMNS[key].attr, '')) if delta and (key in DELTA_COLUMNS): ref_value = cmp_value(getattr(get_group().ref, COLUMNS[key].attr, '')) @@ -85,5 +89,8 @@ def GetGroupSortKey(group, key): return group.percentage if key == DUPECOUNT_COL: return len(group) + if key == FOLDER_COL: + dupe_folder_path = getattr(group.ref, 'display_folder_path', group.ref.folder_path) + return cmp_value(str(dupe_folder_path)) return cmp_value(getattr(group.ref, COLUMNS[key].attr, '')) diff --git a/core_se/data.py b/core_se/data.py index 1d42faa2..57cccd45 100644 --- a/core_se/data.py +++ b/core_se/data.py @@ -8,14 +8,14 @@ from hscommon.util import format_size from hscommon.trans import tr as trbase -from core.data import (format_path, format_timestamp, format_words, format_perc, - format_dupe_count, cmp_value, Column) +from core.data import (format_timestamp, format_words, format_perc, format_dupe_count, cmp_value, + Column) tr = lambda s: trbase(s, 'columns') COLUMNS = [ Column('name', tr("Filename")), - Column('path', tr("Folder")), + Column('folder_path', tr("Folder")), Column('size', tr("Size (KB)")), Column('extension', tr("Kind")), Column('mtime', tr("Modification")), @@ -46,7 +46,7 @@ def GetDisplayInfo(dupe, group, delta): dupe_count = len(group.dupes) return [ dupe.name, - format_path(dupe.path), + str(dupe.folder_path), format_size(size, 0, 1, False), dupe.extension, format_timestamp(mtime, delta and m),