2016-05-29 19:02:39 +00:00
|
|
|
# Copyright 2016 Hardcoded Software (http://www.hardcoded.net)
|
2014-10-05 20:31:16 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-05 20:31:16 +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
|
2011-09-07 19:46:41 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
from hscommon.testutil import TestApp as TestAppBase, CallLogger, eq_, with_app # noqa
|
2011-09-07 19:46:41 +00:00
|
|
|
from hscommon.path import Path
|
2011-09-21 14:26:58 +00:00
|
|
|
from hscommon.util import get_file_ext, format_size
|
2011-11-27 21:49:12 +00:00
|
|
|
from hscommon.gui.column import Column
|
2014-10-05 20:31:16 +00:00
|
|
|
from hscommon.jobprogress.job import nulljob, JobCancelled
|
2011-09-07 19:46:41 +00:00
|
|
|
|
|
|
|
from .. import engine
|
2011-09-21 14:26:58 +00:00
|
|
|
from .. import prioritize
|
2011-09-07 19:46:41 +00:00
|
|
|
from ..engine import getwords
|
2016-05-29 19:02:39 +00:00
|
|
|
from ..app import DupeGuru as DupeGuruBase
|
2011-11-27 21:49:12 +00:00
|
|
|
from ..gui.result_table import ResultTable as ResultTableBase
|
2011-09-07 19:46:41 +00:00
|
|
|
from ..gui.prioritize_dialog import PrioritizeDialog
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-09-21 13:17:22 +00:00
|
|
|
class DupeGuruView:
|
2011-09-07 19:46:41 +00:00
|
|
|
JOB = nulljob
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2012-08-09 14:22:04 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.messages = []
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-21 13:17:22 +00:00
|
|
|
def start_job(self, jobid, func, args=()):
|
2011-09-07 19:46:41 +00:00
|
|
|
try:
|
|
|
|
func(self.JOB, *args)
|
|
|
|
except JobCancelled:
|
|
|
|
return
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-21 13:17:22 +00:00
|
|
|
def get_default(self, key_name):
|
2011-09-07 19:46:41 +00:00
|
|
|
return None
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-21 13:17:22 +00:00
|
|
|
def set_default(self, key_name, value):
|
2011-09-07 19:46:41 +00:00
|
|
|
pass
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2012-03-13 18:27:08 +00:00
|
|
|
def show_message(self, msg):
|
2012-08-09 14:22:04 +00:00
|
|
|
self.messages.append(msg)
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2012-03-10 15:58:08 +00:00
|
|
|
def ask_yes_no(self, prompt):
|
2020-01-01 02:16:27 +00:00
|
|
|
return True # always answer yes
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2016-05-30 02:37:38 +00:00
|
|
|
def create_results_window(self):
|
|
|
|
pass
|
2011-09-21 13:17:22 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-11-27 21:49:12 +00:00
|
|
|
class ResultTable(ResultTableBase):
|
2011-09-21 14:26:58 +00:00
|
|
|
COLUMNS = [
|
2020-01-01 02:16:27 +00:00
|
|
|
Column("marked", ""),
|
|
|
|
Column("name", "Filename"),
|
|
|
|
Column("folder_path", "Directory"),
|
|
|
|
Column("size", "Size (KB)"),
|
|
|
|
Column("extension", "Kind"),
|
2011-09-21 14:26:58 +00:00
|
|
|
]
|
2020-01-01 02:16:27 +00:00
|
|
|
DELTA_COLUMNS = {
|
|
|
|
"size",
|
|
|
|
}
|
|
|
|
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-11-27 21:49:12 +00:00
|
|
|
class DupeGuru(DupeGuruBase):
|
2020-01-01 02:16:27 +00:00
|
|
|
NAME = "dupeGuru"
|
|
|
|
METADATA_TO_READ = ["size"]
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-21 13:17:22 +00:00
|
|
|
def __init__(self):
|
2013-11-08 21:45:14 +00:00
|
|
|
DupeGuruBase.__init__(self, DupeGuruView())
|
2020-01-01 02:16:27 +00:00
|
|
|
self.appdata = "/tmp"
|
2016-06-08 01:32:30 +00:00
|
|
|
self._recreate_result_table()
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-21 14:26:58 +00:00
|
|
|
def _prioritization_categories(self):
|
|
|
|
return prioritize.all_categories()
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2016-06-08 01:32:30 +00:00
|
|
|
def _recreate_result_table(self):
|
|
|
|
if self.result_table is not None:
|
|
|
|
self.result_table.disconnect()
|
|
|
|
self.result_table = ResultTable(self)
|
|
|
|
self.result_table.view = CallLogger()
|
|
|
|
self.result_table.connect()
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
|
|
|
|
class NamedObject:
|
|
|
|
def __init__(self, name="foobar", with_words=False, size=1, folder=None):
|
|
|
|
self.name = name
|
|
|
|
if folder is None:
|
2020-01-01 02:16:27 +00:00
|
|
|
folder = "basepath"
|
2011-09-08 17:28:19 +00:00
|
|
|
self._folder = Path(folder)
|
2011-09-07 19:46:41 +00:00
|
|
|
self.size = size
|
|
|
|
self.md5partial = name
|
|
|
|
self.md5 = name
|
|
|
|
if with_words:
|
|
|
|
self.words = getwords(name)
|
|
|
|
self.is_ref = False
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
def __bool__(self):
|
2020-01-01 02:16:27 +00:00
|
|
|
return False # Make sure that operations are made correctly when the bool value of files is false.
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2013-07-14 21:43:58 +00:00
|
|
|
def get_display_info(self, group, delta):
|
|
|
|
size = self.size
|
|
|
|
m = group.get_match_of(self)
|
|
|
|
if m and delta:
|
|
|
|
r = group.ref
|
|
|
|
size -= r.size
|
|
|
|
return {
|
2020-01-01 02:16:27 +00:00
|
|
|
"name": self.name,
|
|
|
|
"folder_path": str(self.folder_path),
|
|
|
|
"size": format_size(size, 0, 1, False),
|
|
|
|
"extension": self.extension if hasattr(self, "extension") else "---",
|
2013-07-14 21:43:58 +00:00
|
|
|
}
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
@property
|
|
|
|
def path(self):
|
2013-11-16 17:06:16 +00:00
|
|
|
return self._folder[self.name]
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
@property
|
|
|
|
def folder_path(self):
|
2013-11-16 17:06:16 +00:00
|
|
|
return self.path.parent()
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
@property
|
|
|
|
def extension(self):
|
|
|
|
return get_file_ext(self.name)
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
# Returns a group set that looks like that:
|
|
|
|
# "foo bar" (1)
|
|
|
|
# "bar bleh" (1024)
|
|
|
|
# "foo bleh" (1)
|
|
|
|
# "ibabtu" (1)
|
|
|
|
# "ibabtu" (1)
|
|
|
|
def GetTestGroups():
|
2016-05-29 19:02:39 +00:00
|
|
|
objects = [
|
|
|
|
NamedObject("foo bar"),
|
|
|
|
NamedObject("bar bleh"),
|
|
|
|
NamedObject("foo bleh"),
|
|
|
|
NamedObject("ibabtu"),
|
2020-01-01 02:16:27 +00:00
|
|
|
NamedObject("ibabtu"),
|
2016-05-29 19:02:39 +00:00
|
|
|
]
|
2011-09-07 19:46:41 +00:00
|
|
|
objects[1].size = 1024
|
2020-01-01 02:16:27 +00:00
|
|
|
matches = engine.getmatches(objects) # we should have 5 matches
|
|
|
|
groups = engine.get_groups(matches) # We should have 2 groups
|
2011-09-07 19:46:41 +00:00
|
|
|
for g in groups:
|
2020-01-01 02:16:27 +00:00
|
|
|
g.prioritize(
|
|
|
|
lambda x: objects.index(x)
|
|
|
|
) # We want the dupes to be in the same order as the list is
|
|
|
|
groups.sort(key=len, reverse=True) # We want the group with 3 members to be first.
|
2016-05-29 19:02:39 +00:00
|
|
|
return (objects, matches, groups)
|
2011-09-07 19:46:41 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
class TestApp(TestAppBase):
|
2020-06-27 06:08:12 +00:00
|
|
|
__test__ = False
|
|
|
|
|
2011-09-07 19:46:41 +00:00
|
|
|
def __init__(self):
|
2011-11-27 21:49:12 +00:00
|
|
|
def link_gui(gui):
|
|
|
|
gui.view = self.make_logger()
|
2020-01-01 02:16:27 +00:00
|
|
|
if hasattr(gui, "columns"): # tables
|
2011-11-27 21:49:12 +00:00
|
|
|
gui.columns.view = self.make_logger()
|
|
|
|
return gui
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-11-27 21:49:12 +00:00
|
|
|
TestAppBase.__init__(self)
|
2011-09-07 19:46:41 +00:00
|
|
|
self.app = DupeGuru()
|
2011-11-27 21:49:12 +00:00
|
|
|
self.default_parent = self.app
|
2012-01-23 20:09:13 +00:00
|
|
|
self.dtree = link_gui(self.app.directory_tree)
|
|
|
|
self.dpanel = link_gui(self.app.details_panel)
|
2012-03-13 18:27:08 +00:00
|
|
|
self.slabel = link_gui(self.app.stats_label)
|
2012-01-23 20:09:13 +00:00
|
|
|
self.pdialog = PrioritizeDialog(self.app)
|
2012-03-13 18:27:08 +00:00
|
|
|
link_gui(self.pdialog.category_list)
|
|
|
|
link_gui(self.pdialog.criteria_list)
|
|
|
|
link_gui(self.pdialog.prioritization_list)
|
2012-03-14 16:47:21 +00:00
|
|
|
link_gui(self.app.ignore_list_dialog)
|
|
|
|
link_gui(self.app.ignore_list_dialog.ignore_list_table)
|
2013-08-04 13:26:18 +00:00
|
|
|
link_gui(self.app.progress_window)
|
|
|
|
link_gui(self.app.progress_window.jobdesc_textfield)
|
|
|
|
link_gui(self.app.progress_window.progressdesc_textfield)
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2016-05-30 02:37:38 +00:00
|
|
|
@property
|
|
|
|
def rtable(self):
|
|
|
|
# rtable is a property because its instance can be replaced during execution
|
|
|
|
return self.app.result_table
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Helpers
|
2011-09-07 19:46:41 +00:00
|
|
|
def select_pri_criterion(self, name):
|
|
|
|
# Select a main prioritize criterion by name instead of by index. Makes tests more
|
|
|
|
# maintainable.
|
|
|
|
index = self.pdialog.category_list.index(name)
|
|
|
|
self.pdialog.category_list.select(index)
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2011-09-09 22:24:17 +00:00
|
|
|
def add_pri_criterion(self, name, index):
|
2011-09-12 14:33:17 +00:00
|
|
|
self.select_pri_criterion(name)
|
2011-09-09 22:24:17 +00:00
|
|
|
self.pdialog.criteria_list.select([index])
|
|
|
|
self.pdialog.add_selected()
|