[#161 state:fixed] Fixed folder sorting.

This commit is contained in:
Virgil Dupras 2011-06-15 11:58:33 -04:00
parent cd9fd3a10b
commit 56207f4dbb
10 changed files with 46 additions and 33 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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.

View File

@ -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

View File

@ -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 '---',
]

View File

@ -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)

View File

@ -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),

View File

@ -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):

View File

@ -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, ''))

View File

@ -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),