1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-03-10 05:34:36 +00:00

Replaced dependencies from hsutil to hscommon.

This commit is contained in:
Virgil Dupras 2011-01-11 13:36:05 +01:00
parent 33c0ba808c
commit eefe464fba
28 changed files with 71 additions and 73 deletions

1
README
View File

@ -26,7 +26,6 @@ General dependencies
- Python 3.1 (http://www.python.org) - Python 3.1 (http://www.python.org)
- Send2Trash3k (http://hg.hardcoded.net/send2trash) - Send2Trash3k (http://hg.hardcoded.net/send2trash)
- hsutil3k (http://hg.hardcoded.net/hsutil)
- hsaudiotag3k 1.1.0 (for ME) (http://hg.hardcoded.net/hsaudiotag) - hsaudiotag3k 1.1.0 (for ME) (http://hg.hardcoded.net/hsaudiotag)
- jobprogress (http://hg.hardcoded.net/jobprogress) - jobprogress (http://hg.hardcoded.net/jobprogress)
- Markdown, to generate help files. (http://pypi.python.org/pypi/Markdown) - Markdown, to generate help files. (http://pypi.python.org/pypi/Markdown)

View File

@ -15,7 +15,7 @@ import core_me.app_cocoa, core_me.data, core_me.fs, core_me.scanner
import hsaudiotag.aiff, hsaudiotag.flac, hsaudiotag.genres, hsaudiotag.id3v1,\ import hsaudiotag.aiff, hsaudiotag.flac, hsaudiotag.genres, hsaudiotag.id3v1,\
hsaudiotag.id3v2, hsaudiotag.mp4, hsaudiotag.mpeg, hsaudiotag.ogg, hsaudiotag.wma hsaudiotag.id3v2, hsaudiotag.mp4, hsaudiotag.mpeg, hsaudiotag.ogg, hsaudiotag.wma
from hsaudiotag import aiff, flac, genres, id3v1, id3v2, mp4, mpeg, ogg, wma from hsaudiotag import aiff, flac, genres, id3v1, id3v2, mp4, mpeg, ogg, wma
import hsutil.conflict import hscommon.conflict
import core.engine, core.fs, core.app import core.engine, core.fs, core.app
import xml.etree.ElementPath import xml.etree.ElementPath
import gzip import gzip

View File

@ -8,7 +8,7 @@ from core.app_cocoa_inter import PyDupeGuruBase, PyDetailsPanel
from core_pe import app_cocoa as app_pe_cocoa from core_pe import app_cocoa as app_pe_cocoa
# Fix py2app imports which chokes on relative imports and other stuff # Fix py2app imports which chokes on relative imports and other stuff
import hsutil.conflict import hscommon.conflict
import core.engine, core.fs, core.app import core.engine, core.fs, core.app
import core_pe.block, core_pe.cache, core_pe.matchbase, core_pe.data, core_pe._block_osx import core_pe.block, core_pe.cache, core_pe.matchbase, core_pe.data, core_pe._block_osx
import xml.etree.ElementPath import xml.etree.ElementPath

View File

@ -11,7 +11,7 @@ from core.app_cocoa_inter import PyDupeGuruBase, PyDetailsPanel
from core_se.app_cocoa import DupeGuru from core_se.app_cocoa import DupeGuru
# Fix py2app imports with chokes on relative imports and other stuff # Fix py2app imports with chokes on relative imports and other stuff
import hsutil.conflict import hscommon.conflict
import core.engine, core.fs, core.app import core.engine, core.fs, core.app
import core_se.fs, core_se.data import core_se.fs, core_se.data
import xml.etree.ElementPath import xml.etree.ElementPath

View File

@ -17,9 +17,8 @@ from hscommon import io
from hscommon.reg import RegistrableApplication from hscommon.reg import RegistrableApplication
from hscommon.notify import Broadcaster from hscommon.notify import Broadcaster
from hscommon.path import Path from hscommon.path import Path
from hsutil import files from hscommon.conflict import smart_move, smart_copy
from hsutil.misc import flatten, first from hscommon.util import delete_if_empty, first, escape
from hsutil.str import escape
from . import directories, results, scanner, export, fs from . import directories, results, scanner, export, fs
@ -156,14 +155,14 @@ class DupeGuru(RegistrableApplication, Broadcaster):
def apply_filter(self, filter): def apply_filter(self, filter):
self.results.apply_filter(None) self.results.apply_filter(None)
if self.options['escape_filter_regexp']: if self.options['escape_filter_regexp']:
filter = escape(filter, '()[]\\.|+?^') filter = escape(filter, set('()[]\\.|+?^'))
filter = escape(filter, '*', '.') filter = escape(filter, '*', '.')
self.results.apply_filter(filter) self.results.apply_filter(filter)
self.notify('results_changed') self.notify('results_changed')
def clean_empty_dirs(self, path): def clean_empty_dirs(self, path):
if self.options['clean_empty_dirs']: if self.options['clean_empty_dirs']:
while files.delete_if_empty(path, ['.DS_Store']): while delete_if_empty(path, ['.DS_Store']):
path = path[:-1] path = path[:-1]
def copy_or_move(self, dupe, copy, destination, dest_type): def copy_or_move(self, dupe, copy, destination, dest_type):
@ -185,9 +184,9 @@ class DupeGuru(RegistrableApplication, Broadcaster):
io.makedirs(dest_path) io.makedirs(dest_path)
# Raises an EnvironmentError if there's a problem # Raises an EnvironmentError if there's a problem
if copy: if copy:
files.copy(source_path, dest_path) smart_copy(source_path, dest_path)
else: else:
files.move(source_path, dest_path) smart_move(source_path, dest_path)
self.clean_empty_dirs(source_path[:-1]) self.clean_empty_dirs(source_path[:-1])
def copy_or_move_marked(self, copy, destination, recreate_path): def copy_or_move_marked(self, copy, destination, recreate_path):

View File

@ -20,7 +20,7 @@ from .gui.stats_label import StatsLabel
# Fix py2app's problems on relative imports # Fix py2app's problems on relative imports
from core import app, app_cocoa, data, directories, engine, export, ignore, results, fs, scanner from core import app, app_cocoa, data, directories, engine, export, ignore, results, fs, scanner
from hsutil import conflict from hscommon import conflict
class PyDupeGuruBase(PyFairware): class PyDupeGuruBase(PyFairware):
#---Directories #---Directories

View File

@ -6,7 +6,7 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license # http://www.hardcoded.net/licenses/bsd_license
from hsutil.str import format_time, FT_DECIMAL, format_size from hscommon.util import format_time_decimal, format_size
import time import time
@ -15,7 +15,7 @@ def format_path(p):
def format_timestamp(t, delta): def format_timestamp(t, delta):
if delta: if delta:
return format_time(t, FT_DECIMAL) return format_time_decimal(t)
else: else:
if t > 0: if t > 0:
return time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(t)) return time.strftime('%Y/%m/%d %H:%M:%S', time.localtime(t))

View File

@ -10,7 +10,7 @@ from xml.etree import ElementTree as ET
from hscommon import io from hscommon import io
from hscommon.path import Path from hscommon.path import Path
from hsutil.files import FileOrPath from hscommon.util import FileOrPath
from . import fs from . import fs

View File

@ -14,8 +14,7 @@ import string
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from unicodedata import normalize from unicodedata import normalize
from hsutil.misc import flatten from hscommon.util import flatten, multi_replace
from hsutil.str import multi_replace
from jobprogress import job from jobprogress import job
(WEIGHT_WORDS, (WEIGHT_WORDS,

View File

@ -15,8 +15,7 @@ import hashlib
import logging import logging
from hscommon import io from hscommon import io
from hsutil.misc import nonone, flatten from hscommon.util import nonone, flatten, get_file_ext
from hsutil.str import get_file_ext
class FSError(Exception): class FSError(Exception):
cls_message = "An error has occured on '{name}' in '{parent}'" cls_message = "An error has occured on '{name}' in '{parent}'"

View File

@ -8,9 +8,9 @@
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from hsutil.files import FileOrPath from hscommon.util import FileOrPath
class IgnoreList(object): class IgnoreList:
"""An ignore list implementation that is iterable, filterable and exportable to XML. """An ignore list implementation that is iterable, filterable and exportable to XML.
Call Ignore to add an ignore list entry, and AreIgnore to check if 2 items are in the list. Call Ignore to add an ignore list entry, and AreIgnore to check if 2 items are in the list.

View File

@ -13,9 +13,7 @@ from xml.etree import ElementTree as ET
from . import engine from . import engine
from jobprogress.job import nulljob from jobprogress.job import nulljob
from hscommon.markable import Markable from hscommon.markable import Markable
from hsutil.misc import flatten, nonone from hscommon.util import flatten, nonone, FileOrPath, format_size
from hsutil.str import format_size
from hsutil.files import FileOrPath
class Results(Markable): class Results(Markable):
#---Override #---Override

View File

@ -11,8 +11,7 @@ import re
from jobprogress import job from jobprogress import job
from hscommon import io from hscommon import io
from hsutil.misc import dedupe from hscommon.util import dedupe, rem_file_ext, get_file_ext
from hsutil.str import get_file_ext, rem_file_ext
from . import engine from . import engine
from .ignore import IgnoreList from .ignore import IgnoreList

View File

@ -13,9 +13,9 @@ import logging
from pytest import mark from pytest import mark
from hscommon import io from hscommon import io
from hscommon.path import Path from hscommon.path import Path
from hsutil.decorators import log_calls import hscommon.conflict
import hsutil.files import hscommon.util
from hscommon.testutil import CallLogger, eq_ from hscommon.testutil import CallLogger, eq_, log_calls
from jobprogress.job import nulljob, Job, JobCancelled from jobprogress.job import nulljob, Job, JobCancelled
from . import data from . import data
@ -46,27 +46,27 @@ def add_fake_files_to_directories(directories, files):
class TestCaseDupeGuru: class TestCaseDupeGuru:
def test_apply_filter_calls_results_apply_filter(self, monkeypatch): def test_apply_filter_calls_results_apply_filter(self, monkeypatch):
app = DupeGuru() dgapp = DupeGuru()
monkeypatch.setattr(app.results, 'apply_filter', log_calls(app.results.apply_filter)) monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
app.apply_filter('foo') dgapp.apply_filter('foo')
eq_(2, len(app.results.apply_filter.calls)) eq_(2, len(dgapp.results.apply_filter.calls))
call = app.results.apply_filter.calls[0] call = dgapp.results.apply_filter.calls[0]
assert call['filter_str'] is None assert call['filter_str'] is None
call = app.results.apply_filter.calls[1] call = dgapp.results.apply_filter.calls[1]
eq_('foo', call['filter_str']) eq_('foo', call['filter_str'])
def test_apply_filter_escapes_regexp(self, monkeypatch): def test_apply_filter_escapes_regexp(self, monkeypatch):
app = DupeGuru() dgapp = DupeGuru()
monkeypatch.setattr(app.results, 'apply_filter', log_calls(app.results.apply_filter)) monkeypatch.setattr(dgapp.results, 'apply_filter', log_calls(dgapp.results.apply_filter))
app.apply_filter('()[]\\.|+?^abc') dgapp.apply_filter('()[]\\.|+?^abc')
call = app.results.apply_filter.calls[1] call = dgapp.results.apply_filter.calls[1]
eq_('\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc', call['filter_str']) eq_('\\(\\)\\[\\]\\\\\\.\\|\\+\\?\\^abc', call['filter_str'])
app.apply_filter('(*)') # In "simple mode", we want the * to behave as a wilcard dgapp.apply_filter('(*)') # In "simple mode", we want the * to behave as a wilcard
call = app.results.apply_filter.calls[3] call = dgapp.results.apply_filter.calls[3]
eq_('\(.*\)', call['filter_str']) eq_('\(.*\)', call['filter_str'])
app.options['escape_filter_regexp'] = False dgapp.options['escape_filter_regexp'] = False
app.apply_filter('(abc)') dgapp.apply_filter('(abc)')
call = app.results.apply_filter.calls[5] call = dgapp.results.apply_filter.calls[5]
eq_('(abc)', call['filter_str']) eq_('(abc)', call['filter_str'])
def test_copy_or_move(self, tmpdir, monkeypatch): def test_copy_or_move(self, tmpdir, monkeypatch):
@ -75,14 +75,16 @@ class TestCaseDupeGuru:
# every change I want to make. The blowup was caused by a missing import. # every change I want to make. The blowup was caused by a missing import.
p = Path(str(tmpdir)) p = Path(str(tmpdir))
io.open(p + 'foo', 'w').close() io.open(p + 'foo', 'w').close()
monkeypatch.setattr(hsutil.files, 'copy', log_calls(lambda source_path, dest_path: None)) monkeypatch.setattr(hscommon.conflict, 'smart_copy', log_calls(lambda source_path, dest_path: None))
# XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
monkeypatch.setattr(app, 'smart_copy', hscommon.conflict.smart_copy)
monkeypatch.setattr(os, 'makedirs', lambda path: None) # We don't want the test to create that fake directory monkeypatch.setattr(os, 'makedirs', lambda path: None) # We don't want the test to create that fake directory
app = DupeGuru() dgapp = DupeGuru()
app.directories.add_path(p) dgapp.directories.add_path(p)
[f] = app.directories.get_files() [f] = dgapp.directories.get_files()
app.copy_or_move(f, True, 'some_destination', 0) dgapp.copy_or_move(f, True, 'some_destination', 0)
eq_(1, len(hsutil.files.copy.calls)) eq_(1, len(hscommon.conflict.smart_copy.calls))
call = hsutil.files.copy.calls[0] call = hscommon.conflict.smart_copy.calls[0]
eq_('some_destination', call['dest_path']) eq_('some_destination', call['dest_path'])
eq_(f.path, call['source_path']) eq_(f.path, call['source_path'])
@ -132,17 +134,19 @@ class TestCaseDupeGuru:
class TestCaseDupeGuru_clean_empty_dirs: class TestCaseDupeGuru_clean_empty_dirs:
def pytest_funcarg__do_setup(self, request): def pytest_funcarg__do_setup(self, request):
monkeypatch = request.getfuncargvalue('monkeypatch') monkeypatch = request.getfuncargvalue('monkeypatch')
monkeypatch.setattr(hsutil.files, 'delete_if_empty', log_calls(lambda path, files_to_delete=[]: None)) monkeypatch.setattr(hscommon.util, 'delete_if_empty', log_calls(lambda path, files_to_delete=[]: None))
# XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
monkeypatch.setattr(app, 'delete_if_empty', hscommon.util.delete_if_empty)
self.app = DupeGuru() self.app = DupeGuru()
def test_option_off(self, do_setup): def test_option_off(self, do_setup):
self.app.clean_empty_dirs(Path('/foo/bar')) self.app.clean_empty_dirs(Path('/foo/bar'))
eq_(0, len(hsutil.files.delete_if_empty.calls)) eq_(0, len(hscommon.util.delete_if_empty.calls))
def test_option_on(self, do_setup): def test_option_on(self, do_setup):
self.app.options['clean_empty_dirs'] = True self.app.options['clean_empty_dirs'] = True
self.app.clean_empty_dirs(Path('/foo/bar')) self.app.clean_empty_dirs(Path('/foo/bar'))
calls = hsutil.files.delete_if_empty.calls calls = hscommon.util.delete_if_empty.calls
eq_(1, len(calls)) eq_(1, len(calls))
eq_(Path('/foo/bar'), calls[0]['path']) eq_(Path('/foo/bar'), calls[0]['path'])
eq_(['.DS_Store'], calls[0]['files_to_delete']) eq_(['.DS_Store'], calls[0]['files_to_delete'])
@ -153,10 +157,12 @@ class TestCaseDupeGuru_clean_empty_dirs:
def mock_delete_if_empty(path, files_to_delete=[]): def mock_delete_if_empty(path, files_to_delete=[]):
return len(path) > 1 return len(path) > 1
monkeypatch.setattr(hsutil.files, 'delete_if_empty', mock_delete_if_empty) monkeypatch.setattr(hscommon.util, 'delete_if_empty', mock_delete_if_empty)
# XXX This monkeypatch is temporary. will be fixed in a better monkeypatcher.
monkeypatch.setattr(app, 'delete_if_empty', mock_delete_if_empty)
self.app.options['clean_empty_dirs'] = True self.app.options['clean_empty_dirs'] = True
self.app.clean_empty_dirs(Path('not-empty/empty/empty')) self.app.clean_empty_dirs(Path('not-empty/empty/empty'))
calls = hsutil.files.delete_if_empty.calls calls = hscommon.util.delete_if_empty.calls
eq_(3, len(calls)) eq_(3, len(calls))
eq_(Path('not-empty/empty/empty'), calls[0]['path']) eq_(Path('not-empty/empty/empty'), calls[0]['path'])
eq_(Path('not-empty/empty'), calls[1]['path']) eq_(Path('not-empty/empty'), calls[1]['path'])

View File

@ -9,7 +9,7 @@
# data module for tests # data module for tests
from hsutil.str import format_size from hscommon.util import format_size
from ..data import format_path, cmp_value from ..data import format_path, cmp_value
COLUMNS = [ COLUMNS = [

View File

@ -9,9 +9,8 @@
import sys import sys
from jobprogress import job from jobprogress import job
from hsutil.decorators import log_calls from hscommon.util import first
from hsutil.misc import first from hscommon.testutil import eq_, log_calls
from hscommon.testutil import eq_
from .. import engine from .. import engine
from ..engine import * from ..engine import *

View File

@ -14,7 +14,7 @@ from xml.etree import ElementTree as ET
from hscommon.path import Path from hscommon.path import Path
from hscommon.testutil import eq_ from hscommon.testutil import eq_
from hsutil.misc import first from hscommon.util import first
from . import engine_test, data from . import engine_test, data
from .. import engine from .. import engine

View File

@ -6,7 +6,7 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license # http://www.hardcoded.net/licenses/bsd_license
from hsutil.str import format_time, FT_MINUTES, format_size from hscommon.util import format_time, format_size
from core.data import (format_path, format_timestamp, format_words, format_perc, from core.data import (format_path, format_timestamp, format_words, format_perc,
format_dupe_count, cmp_value) format_dupe_count, cmp_value)
@ -61,7 +61,7 @@ def GetDisplayInfo(dupe, group, delta):
dupe.name, dupe.name,
format_path(dupe.path), format_path(dupe.path),
format_size(size, 2, 2, False), format_size(size, 2, 2, False),
format_time(duration, FT_MINUTES), format_time(duration, with_hours=False),
str(bitrate), str(bitrate),
str(samplerate), str(samplerate),
dupe.extension, dupe.extension,

View File

@ -7,7 +7,7 @@
# http://www.hardcoded.net/licenses/bsd_license # http://www.hardcoded.net/licenses/bsd_license
from hsaudiotag import auto from hsaudiotag import auto
from hsutil.str import get_file_ext from hscommon.util import get_file_ext
from core import fs from core import fs
TAG_FIELDS = {'audiosize', 'duration', 'bitrate', 'samplerate', 'title', 'artist', TAG_FIELDS = {'audiosize', 'duration', 'bitrate', 'samplerate', 'title', 'artist',

View File

@ -14,7 +14,7 @@ import re
from appscript import app, k, CommandError, ApplicationNotFoundError from appscript import app, k, CommandError, ApplicationNotFoundError
from hscommon import io from hscommon import io
from hsutil.str import get_file_ext, remove_invalid_xml from hscommon.util import get_file_ext, remove_invalid_xml
from hscommon.path import Path from hscommon.path import Path
from hscommon.cocoa import as_fetch from hscommon.cocoa import as_fetch
from hscommon.cocoa.objcmin import NSUserDefaults, NSURL from hscommon.cocoa.objcmin import NSUserDefaults, NSURL

View File

@ -6,7 +6,7 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license # http://www.hardcoded.net/licenses/bsd_license
from hsutil.str import format_size from hscommon.util import format_size
from core.data import format_path, format_timestamp, format_perc, format_dupe_count, cmp_value from core.data import format_path, format_timestamp, format_perc, format_dupe_count, cmp_value
def format_dimensions(dimensions): def format_dimensions(dimensions):

View File

@ -6,7 +6,7 @@
# which should be included with this package. The terms are also available at # which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license # http://www.hardcoded.net/licenses/bsd_license
from hsutil.str import format_size from hscommon.util import format_size
from core.data import (format_path, format_timestamp, format_words, format_perc, from core.data import (format_path, format_timestamp, format_words, format_perc,
format_dupe_count, cmp_value) format_dupe_count, cmp_value)

View File

@ -10,7 +10,7 @@
import hashlib import hashlib
from hscommon import io from hscommon import io
from hsutil.misc import nonone from hscommon.util import nonone
from core import fs from core import fs

View File

@ -9,7 +9,7 @@
import hashlib import hashlib
from hsutil.path import Path from hscommon.path import Path
from hscommon.testutil import eq_ from hscommon.testutil import eq_
from core.fs import File from core.fs import File
from core.tests.directories_test import create_fake_fs from core.tests.directories_test import create_fake_fs

View File

@ -86,7 +86,7 @@ def package_debian(edition):
os.makedirs(destpath) os.makedirs(destpath)
os.makedirs(srcpath) os.makedirs(srcpath)
shutil.copy('run.py', op.join(srcpath, 'run.py')) shutil.copy('run.py', op.join(srcpath, 'run.py'))
packages = ['hscommon', 'core', ed('core_{0}'), 'qtlib', 'qt', 'hsutil', 'send2trash', 'jobprogress'] packages = ['hscommon', 'core', ed('core_{0}'), 'qtlib', 'qt', 'send2trash', 'jobprogress']
if edition == 'me': if edition == 'me':
packages.append('hsaudiotag') packages.append('hsaudiotag')
copy_packages(packages, srcpath) copy_packages(packages, srcpath)

View File

@ -13,7 +13,7 @@ from PyQt4.QtGui import (QMainWindow, QMenu, QPixmap, QIcon, QToolButton, QLabel
QMessageBox, QInputDialog, QLineEdit, QDesktopServices, QFileDialog, QAction, QMenuBar, QMessageBox, QInputDialog, QLineEdit, QDesktopServices, QFileDialog, QAction, QMenuBar,
QToolBar, QWidget, QVBoxLayout, QAbstractItemView, QStatusBar) QToolBar, QWidget, QVBoxLayout, QAbstractItemView, QStatusBar)
from hsutil.misc import nonone from hscommon.util import nonone
from core.app import NoScannableFileError from core.app import NoScannableFileError

View File

@ -11,7 +11,7 @@ import logging
from PyQt4.QtGui import QImage, QImageReader from PyQt4.QtGui import QImage, QImageReader
from hsutil.str import get_file_ext from hscommon.util import get_file_ext
from core import fs from core import fs
from core_pe import data as data_pe from core_pe import data as data_pe

View File

@ -11,7 +11,7 @@ from PyQt4.QtCore import SIGNAL, Qt, QSize
from PyQt4.QtGui import (QDialog, QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, from PyQt4.QtGui import (QDialog, QDialogButtonBox, QVBoxLayout, QHBoxLayout, QLabel, QComboBox,
QSlider, QSizePolicy, QSpacerItem, QWidget, QCheckBox, QLineEdit, QDialogButtonBox, QApplication) QSlider, QSizePolicy, QSpacerItem, QWidget, QCheckBox, QLineEdit, QDialogButtonBox, QApplication)
from hsutil.misc import tryint from hscommon.util import tryint
from core.scanner import ScanType from core.scanner import ScanType