mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
[#161 state:fixed] Fixed folder sorting.
This commit is contained in:
parent
cd9fd3a10b
commit
56207f4dbb
@ -92,10 +92,13 @@ class DupeGuru(RegistrableApplication, Broadcaster):
|
|||||||
logging.warning("Exception on GetDisplayInfo for %s: %s", str(dupe.path), str(e))
|
logging.warning("Exception on GetDisplayInfo for %s: %s", str(dupe.path), str(e))
|
||||||
return ['---'] * len(self.data.COLUMNS)
|
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):
|
def _get_file(self, str_path):
|
||||||
path = Path(str_path)
|
path = Path(str_path)
|
||||||
# We add fs.Folder to fileclasses in case the file we're loading contains folder paths.
|
f = self._create_file(path)
|
||||||
f = fs.get_file(path, self.directories.fileclasses + [fs.Folder])
|
|
||||||
if f is None:
|
if f is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
|
@ -14,9 +14,6 @@ import time
|
|||||||
|
|
||||||
Column = namedtuple('Column', 'attr display')
|
Column = namedtuple('Column', 'attr display')
|
||||||
|
|
||||||
def format_path(p):
|
|
||||||
return str(p[:-1])
|
|
||||||
|
|
||||||
def format_timestamp(t, delta):
|
def format_timestamp(t, delta):
|
||||||
if delta:
|
if delta:
|
||||||
return format_time_decimal(t)
|
return format_time_decimal(t)
|
||||||
|
@ -149,6 +149,10 @@ class File:
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self.path[-1]
|
return self.path[-1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def folder_path(self):
|
||||||
|
return self.path[:-1]
|
||||||
|
|
||||||
|
|
||||||
class Folder(File):
|
class Folder(File):
|
||||||
"""A wrapper around a folder path.
|
"""A wrapper around a folder path.
|
||||||
|
@ -328,15 +328,13 @@ class Results(Markable):
|
|||||||
def sort_dupes(self, key, asc=True, delta=False):
|
def sort_dupes(self, key, asc=True, delta=False):
|
||||||
if not self.__dupes:
|
if not self.__dupes:
|
||||||
self.__get_dupe_list()
|
self.__get_dupe_list()
|
||||||
self.__dupes.sort(key=lambda d: self.data.GetDupeSortKey(d, lambda: self.get_group_of_duplicate(d), key, delta))
|
keyfunc = lambda d: self.data.GetDupeSortKey(d, lambda: self.get_group_of_duplicate(d), key, delta)
|
||||||
if not asc:
|
self.__dupes.sort(key=keyfunc, reverse=not asc)
|
||||||
self.__dupes.reverse()
|
|
||||||
self.__dupes_sort_descriptor = (key,asc,delta)
|
self.__dupes_sort_descriptor = (key,asc,delta)
|
||||||
|
|
||||||
def sort_groups(self,key,asc=True):
|
def sort_groups(self,key,asc=True):
|
||||||
self.groups.sort(key=lambda g: self.data.GetGroupSortKey(g, key))
|
keyfunc = lambda g: self.data.GetGroupSortKey(g, key)
|
||||||
if not asc:
|
self.groups.sort(key=keyfunc, reverse=not asc)
|
||||||
self.groups.reverse()
|
|
||||||
self.__groups_sort_descriptor = (key,asc)
|
self.__groups_sort_descriptor = (key,asc)
|
||||||
|
|
||||||
#---Properties
|
#---Properties
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
# data module for tests
|
# data module for tests
|
||||||
|
|
||||||
from hscommon.util import format_size
|
from hscommon.util import format_size
|
||||||
from ..data import format_path, cmp_value, Column
|
from ..data import cmp_value, Column
|
||||||
|
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
Column('name', 'Filename'),
|
Column('name', 'Filename'),
|
||||||
Column('path', 'Directory'),
|
Column('folder_path', 'Directory'),
|
||||||
Column('size', 'Size (KB)'),
|
Column('size', 'Size (KB)'),
|
||||||
Column('extension', 'Kind'),
|
Column('extension', 'Kind'),
|
||||||
]
|
]
|
||||||
@ -29,7 +29,7 @@ def GetDisplayInfo(dupe, group, delta):
|
|||||||
size -= r.size
|
size -= r.size
|
||||||
return [
|
return [
|
||||||
dupe.name,
|
dupe.name,
|
||||||
format_path(dupe.path),
|
str(dupe.folder_path),
|
||||||
format_size(size, 0, 1, False),
|
format_size(size, 0, 1, False),
|
||||||
dupe.extension if hasattr(dupe, 'extension') else '---',
|
dupe.extension if hasattr(dupe, 'extension') else '---',
|
||||||
]
|
]
|
||||||
|
@ -26,6 +26,11 @@ class NamedObject(engine_test.NamedObject):
|
|||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return False #Make sure that operations are made correctly when the bool value of files is false.
|
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:
|
# Returns a group set that looks like that:
|
||||||
# "foo bar" (1)
|
# "foo bar" (1)
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
from hscommon.util import format_time, format_size
|
from hscommon.util import format_time, format_size
|
||||||
from hscommon.trans import tr as trbase
|
from hscommon.trans import tr as trbase
|
||||||
from core.data import (format_path, format_timestamp, format_words, format_perc,
|
from core.data import (format_timestamp, format_words, format_perc, format_dupe_count, cmp_value,
|
||||||
format_dupe_count, cmp_value, Column)
|
Column)
|
||||||
|
|
||||||
tr = lambda s: trbase(s, 'columns')
|
tr = lambda s: trbase(s, 'columns')
|
||||||
|
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
Column('name', tr("Filename")),
|
Column('name', tr("Filename")),
|
||||||
Column('path', tr("Folder")),
|
Column('folder_path', tr("Folder")),
|
||||||
Column('size', tr("Size (MB)")),
|
Column('size', tr("Size (MB)")),
|
||||||
Column('duration', tr("Time")),
|
Column('duration', tr("Time")),
|
||||||
Column('bitrate', tr("Bitrate")),
|
Column('bitrate', tr("Bitrate")),
|
||||||
@ -63,7 +63,7 @@ def GetDisplayInfo(dupe, group, delta):
|
|||||||
dupe_count = len(group.dupes)
|
dupe_count = len(group.dupes)
|
||||||
return [
|
return [
|
||||||
dupe.name,
|
dupe.name,
|
||||||
format_path(dupe.path),
|
str(dupe.folder_path),
|
||||||
format_size(size, 2, 2, False),
|
format_size(size, 2, 2, False),
|
||||||
format_time(duration, with_hours=False),
|
format_time(duration, with_hours=False),
|
||||||
str(bitrate),
|
str(bitrate),
|
||||||
|
@ -45,8 +45,8 @@ class Photo(PhotoBase):
|
|||||||
|
|
||||||
class IPhoto(Photo):
|
class IPhoto(Photo):
|
||||||
@property
|
@property
|
||||||
def display_path(self):
|
def display_folder_path(self):
|
||||||
return Path(('iPhoto Library', self.name))
|
return IPHOTO_PATH
|
||||||
|
|
||||||
def get_iphoto_database_path():
|
def get_iphoto_database_path():
|
||||||
ud = NSUserDefaults.standardUserDefaults()
|
ud = NSUserDefaults.standardUserDefaults()
|
||||||
@ -166,11 +166,10 @@ class DupeGuruPE(app_cocoa.DupeGuru):
|
|||||||
else:
|
else:
|
||||||
app_cocoa.DupeGuru._do_delete_dupe(self, dupe, replace_with_hardlinks)
|
app_cocoa.DupeGuru._do_delete_dupe(self, dupe, replace_with_hardlinks)
|
||||||
|
|
||||||
def _get_file(self, str_path):
|
def _create_file(self, path):
|
||||||
p = Path(str_path)
|
if (self.directories.iphoto_libpath is not None) and (path in self.directories.iphoto_libpath[:-1]):
|
||||||
if (self.directories.iphoto_libpath is not None) and (p in self.directories.iphoto_libpath[:-1]):
|
return IPhoto(path)
|
||||||
return IPhoto(p)
|
return app_cocoa.DupeGuru._create_file(self, path)
|
||||||
return app_cocoa.DupeGuru._get_file(self, str_path)
|
|
||||||
|
|
||||||
def copy_or_move(self, dupe, copy, destination, dest_type):
|
def copy_or_move(self, dupe, copy, destination, dest_type):
|
||||||
if isinstance(dupe, IPhoto):
|
if isinstance(dupe, IPhoto):
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
from hscommon.util import format_size
|
from hscommon.util import format_size
|
||||||
from hscommon.trans import tr as trbase
|
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')
|
tr = lambda s: trbase(s, 'columns')
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ def format_dimensions(dimensions):
|
|||||||
|
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
Column('name', tr("Filename")),
|
Column('name', tr("Filename")),
|
||||||
Column('path', tr("Folder")),
|
Column('folder_path', tr("Folder")),
|
||||||
Column('size', tr("Size (KB)")),
|
Column('size', tr("Size (KB)")),
|
||||||
Column('extension', tr("Kind")),
|
Column('extension', tr("Kind")),
|
||||||
Column('dimensions', tr("Dimensions")),
|
Column('dimensions', tr("Dimensions")),
|
||||||
@ -26,6 +26,7 @@ COLUMNS = [
|
|||||||
Column('dupe_count', tr("Dupe Count")),
|
Column('dupe_count', tr("Dupe Count")),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
FOLDER_COL = 1
|
||||||
MATCHPERC_COL = 6
|
MATCHPERC_COL = 6
|
||||||
DUPECOUNT_COL = 7
|
DUPECOUNT_COL = 7
|
||||||
DELTA_COLUMNS = {2, 4, 5}
|
DELTA_COLUMNS = {2, 4, 5}
|
||||||
@ -53,10 +54,10 @@ def GetDisplayInfo(dupe,group,delta=False):
|
|||||||
else:
|
else:
|
||||||
percentage = group.percentage
|
percentage = group.percentage
|
||||||
dupe_count = len(group.dupes)
|
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 [
|
return [
|
||||||
dupe.name,
|
dupe.name,
|
||||||
format_path(dupe_path),
|
str(dupe_folder_path),
|
||||||
format_size(size, 0, 1, False),
|
format_size(size, 0, 1, False),
|
||||||
dupe.extension,
|
dupe.extension,
|
||||||
format_dimensions(dimensions),
|
format_dimensions(dimensions),
|
||||||
@ -71,6 +72,9 @@ def GetDupeSortKey(dupe, get_group, key, delta):
|
|||||||
return m.percentage
|
return m.percentage
|
||||||
if key == DUPECOUNT_COL:
|
if key == DUPECOUNT_COL:
|
||||||
return 0
|
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, ''))
|
r = cmp_value(getattr(dupe, COLUMNS[key].attr, ''))
|
||||||
if delta and (key in DELTA_COLUMNS):
|
if delta and (key in DELTA_COLUMNS):
|
||||||
ref_value = cmp_value(getattr(get_group().ref, COLUMNS[key].attr, ''))
|
ref_value = cmp_value(getattr(get_group().ref, COLUMNS[key].attr, ''))
|
||||||
@ -85,5 +89,8 @@ def GetGroupSortKey(group, key):
|
|||||||
return group.percentage
|
return group.percentage
|
||||||
if key == DUPECOUNT_COL:
|
if key == DUPECOUNT_COL:
|
||||||
return len(group)
|
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, ''))
|
return cmp_value(getattr(group.ref, COLUMNS[key].attr, ''))
|
||||||
|
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
from hscommon.util import format_size
|
from hscommon.util import format_size
|
||||||
from hscommon.trans import tr as trbase
|
from hscommon.trans import tr as trbase
|
||||||
from core.data import (format_path, format_timestamp, format_words, format_perc,
|
from core.data import (format_timestamp, format_words, format_perc, format_dupe_count, cmp_value,
|
||||||
format_dupe_count, cmp_value, Column)
|
Column)
|
||||||
|
|
||||||
tr = lambda s: trbase(s, 'columns')
|
tr = lambda s: trbase(s, 'columns')
|
||||||
|
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
Column('name', tr("Filename")),
|
Column('name', tr("Filename")),
|
||||||
Column('path', tr("Folder")),
|
Column('folder_path', tr("Folder")),
|
||||||
Column('size', tr("Size (KB)")),
|
Column('size', tr("Size (KB)")),
|
||||||
Column('extension', tr("Kind")),
|
Column('extension', tr("Kind")),
|
||||||
Column('mtime', tr("Modification")),
|
Column('mtime', tr("Modification")),
|
||||||
@ -46,7 +46,7 @@ def GetDisplayInfo(dupe, group, delta):
|
|||||||
dupe_count = len(group.dupes)
|
dupe_count = len(group.dupes)
|
||||||
return [
|
return [
|
||||||
dupe.name,
|
dupe.name,
|
||||||
format_path(dupe.path),
|
str(dupe.folder_path),
|
||||||
format_size(size, 0, 1, False),
|
format_size(size, 0, 1, False),
|
||||||
dupe.extension,
|
dupe.extension,
|
||||||
format_timestamp(mtime, delta and m),
|
format_timestamp(mtime, delta and m),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user