1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2026-01-22 06:37:17 +00:00

Removed data modules and moved their functionalities to core_*.app.

This commit is contained in:
Virgil Dupras
2011-09-21 10:26:58 -04:00
parent 60462698ac
commit 70689ce057
18 changed files with 417 additions and 447 deletions

View File

@@ -8,17 +8,17 @@
from hscommon.testutil import TestApp as TestAppBase, eq_, with_app
from hscommon.path import Path
from hscommon.util import get_file_ext
from hscommon.util import get_file_ext, format_size
from jobprogress.job import nulljob, JobCancelled
from .. import engine
from .. import prioritize
from ..engine import getwords
from ..app import DupeGuru as DupeGuruBase
from ..app import DupeGuru as DupeGuruBase, Column, cmp_value
from ..gui.details_panel import DetailsPanel
from ..gui.directory_tree import DirectoryTree
from ..gui.result_table import ResultTable
from ..gui.prioritize_dialog import PrioritizeDialog
from . import data
class DupeGuruView:
JOB = nulljob
@@ -37,8 +37,42 @@ class DupeGuruView:
class DupeGuru(DupeGuruBase):
COLUMNS = [
Column('name', 'Filename'),
Column('folder_path', 'Directory'),
Column('size', 'Size (KB)'),
Column('extension', 'Kind'),
]
DELTA_COLUMNS = {2,}
METADATA_TO_READ = ['size']
def __init__(self):
DupeGuruBase.__init__(self, DupeGuruView(), data, '/tmp')
DupeGuruBase.__init__(self, DupeGuruView(), '/tmp')
def _get_display_info(self, dupe, group, delta):
size = dupe.size
m = group.get_match_of(dupe)
if m and delta:
r = group.ref
size -= r.size
return [
dupe.name,
str(dupe.folder_path),
format_size(size, 0, 1, False),
dupe.extension if hasattr(dupe, 'extension') else '---',
]
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
r = cmp_value(getattr(dupe, self.COLUMNS[key].attr))
if delta and (key in self.DELTA_COLUMNS):
r -= cmp_value(getattr(get_group().ref, self.COLUMNS[key].attr))
return r
def _get_group_sort_key(self, group, key):
return cmp_value(getattr(group.ref, self.COLUMNS[key].attr))
def _prioritization_categories(self):
return prioritize.all_categories()
class NamedObject:
def __init__(self, name="foobar", with_words=False, size=1, folder=None):

View File

@@ -1,48 +0,0 @@
# Created By: Virgil Dupras
# Created On: 2009-10-23
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
# data module for tests
from hscommon.util import format_size
from ..data import cmp_value, Column
from .. import prioritize
COLUMNS = [
Column('name', 'Filename'),
Column('folder_path', 'Directory'),
Column('size', 'Size (KB)'),
Column('extension', 'Kind'),
]
METADATA_TO_READ = ['size']
DELTA_COLUMNS = {2,}
def GetDisplayInfo(dupe, group, delta):
size = dupe.size
m = group.get_match_of(dupe)
if m and delta:
r = group.ref
size -= r.size
return [
dupe.name,
str(dupe.folder_path),
format_size(size, 0, 1, False),
dupe.extension if hasattr(dupe, 'extension') else '---',
]
def GetDupeSortKey(dupe, get_group, key, delta):
r = cmp_value(getattr(dupe, COLUMNS[key].attr))
if delta and (key in DELTA_COLUMNS):
r -= cmp_value(getattr(get_group().ref, COLUMNS[key].attr))
return r
def GetGroupSortKey(group, key):
return cmp_value(getattr(group.ref, COLUMNS[key].attr))
def prioritization_categories():
return prioritize.all_categories()

View File

@@ -14,14 +14,14 @@ from xml.etree import ElementTree as ET
from hscommon.testutil import eq_
from hscommon.util import first
from . import data
from .. import engine
from .base import NamedObject, GetTestGroups
from .base import NamedObject, GetTestGroups, DupeGuru
from ..results import Results
class TestCaseResultsEmpty:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
def test_apply_invalid_filter(self):
# If the applied filter is an invalid regexp, just ignore the filter.
@@ -68,7 +68,8 @@ class TestCaseResultsEmpty:
class TestCaseResultsWithSomeGroups:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects,self.matches,self.groups = GetTestGroups()
self.results.groups = self.groups
@@ -186,7 +187,8 @@ class TestCaseResultsWithSomeGroups:
def test_sort_empty_list(self):
#There was an infinite loop when sorting an empty list.
r = Results(data)
app = DupeGuru()
r = app.results
r.sort_dupes(0)
eq_([],r.dupes)
@@ -231,7 +233,8 @@ class TestCaseResultsWithSomeGroups:
class TestCaseResultsWithSavedResults:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects,self.matches,self.groups = GetTestGroups()
self.results.groups = self.groups
self.f = io.BytesIO()
@@ -264,7 +267,8 @@ class TestCaseResultsWithSavedResults:
class TestCaseResultsMarkings:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects,self.matches,self.groups = GetTestGroups()
self.results.groups = self.groups
@@ -407,7 +411,8 @@ class TestCaseResultsMarkings:
f = io.BytesIO()
self.results.save_to_xml(f)
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f,get_file)
assert not r.is_marked(self.objects[0])
assert not r.is_marked(self.objects[1])
@@ -418,7 +423,8 @@ class TestCaseResultsMarkings:
class TestCaseResultsXML:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects, self.matches, self.groups = GetTestGroups()
self.results.groups = self.groups
@@ -470,7 +476,8 @@ class TestCaseResultsXML:
f = io.BytesIO()
self.results.save_to_xml(f)
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f,get_file)
eq_(2,len(r.groups))
g1,g2 = r.groups
@@ -499,7 +506,8 @@ class TestCaseResultsXML:
filename = str(tmpdir.join('dupeguru_results.xml'))
self.objects[4].name = 'ibabtu 2' #we can't have 2 files with the same path
self.results.save_to_xml(filename)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(filename,get_file)
eq_(2,len(r.groups))
@@ -513,7 +521,8 @@ class TestCaseResultsXML:
f = io.BytesIO()
self.results.save_to_xml(f)
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f,get_file)
eq_(1,len(r.groups))
eq_(3,len(r.groups[0]))
@@ -553,7 +562,8 @@ class TestCaseResultsXML:
tree = ET.ElementTree(root)
tree.write(f, encoding='utf-8')
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f, get_file)
eq_(1,len(r.groups))
eq_(3,len(r.groups[0]))
@@ -570,12 +580,14 @@ class TestCaseResultsXML:
groups = engine.get_groups(matches) #We should have 2 groups
for g in groups:
g.prioritize(lambda x:objects.index(x)) #We want the dupes to be in the same order as the list is
results = Results(data)
app = DupeGuru()
results = Results(app)
results.groups = groups
f = io.BytesIO()
results.save_to_xml(f)
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f,get_file)
g = r.groups[0]
eq_("\xe9foo bar",g[0].name)
@@ -585,12 +597,14 @@ class TestCaseResultsXML:
f = io.BytesIO()
f.write(b'<this is invalid')
f.seek(0)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.load_from_xml(f,None)
eq_(0,len(r.groups))
def test_load_non_existant_xml(self):
r = Results(data)
app = DupeGuru()
r = Results(app)
try:
r.load_from_xml('does_not_exist.xml', None)
except IOError:
@@ -609,7 +623,8 @@ class TestCaseResultsXML:
results = self.results
results.save_to_xml(f)
f.seek(0)
results = Results(data)
app = DupeGuru()
results = Results(app)
results.load_from_xml(f, self.get_file)
group = results.groups[0]
d1, d2, d3 = group
@@ -642,7 +657,8 @@ class TestCaseResultsXML:
class TestCaseResultsFilter:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects, self.matches, self.groups = GetTestGroups()
self.results.groups = self.groups
self.results.apply_filter(r'foo')
@@ -729,7 +745,8 @@ class TestCaseResultsFilter:
filename = str(tmpdir.join('dupeguru_results.xml'))
self.objects[4].name = 'ibabtu 2' #we can't have 2 files with the same path
self.results.save_to_xml(filename)
r = Results(data)
app = DupeGuru()
r = Results(app)
r.apply_filter('foo')
r.load_from_xml(filename,get_file)
eq_(2,len(r.groups))
@@ -767,7 +784,8 @@ class TestCaseResultsFilter:
class TestCaseResultsRefFile:
def setup_method(self, method):
self.results = Results(data)
self.app = DupeGuru()
self.results = self.app.results
self.objects, self.matches, self.groups = GetTestGroups()
self.objects[0].is_ref = True
self.objects[1].is_ref = True