mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 14:41:39 +00:00
[#89 state:fixed] Added a Folders scan type in dgse.
--HG-- rename : core_se/tests/fs_test.py => core/tests/fs_test.py
This commit is contained in:
@@ -14,9 +14,8 @@ from hscommon.cocoa.objcmin import NSWorkspace
|
||||
|
||||
from core import fs
|
||||
from core.app_cocoa import DupeGuru as DupeGuruBase
|
||||
from core.directories import Directories as DirectoriesBase, STATE_EXCLUDED
|
||||
from core.directories import Directories as DirectoriesBase, DirectoryState
|
||||
from . import data
|
||||
from .fs import Bundle as BundleBase
|
||||
|
||||
def is_bundle(str_path):
|
||||
sw = NSWorkspace.sharedWorkspace()
|
||||
@@ -25,7 +24,7 @@ def is_bundle(str_path):
|
||||
logging.warning('There was an error trying to detect the UTI of %s', str_path)
|
||||
return sw.type_conformsToType_(uti, 'com.apple.bundle') or sw.type_conformsToType_(uti, 'com.apple.package')
|
||||
|
||||
class Bundle(BundleBase):
|
||||
class Bundle(fs.Folder):
|
||||
@classmethod
|
||||
def can_handle(cls, path):
|
||||
return not io.islink(path) and io.isdir(path) and is_bundle(str(path))
|
||||
@@ -42,9 +41,22 @@ class Directories(DirectoriesBase):
|
||||
if result is not None:
|
||||
return result
|
||||
if path in self.ROOT_PATH_TO_EXCLUDE:
|
||||
return STATE_EXCLUDED
|
||||
return DirectoryState.Excluded
|
||||
if path[:2] == Path('/Users') and path[3:] in self.HOME_PATH_TO_EXCLUDE:
|
||||
return STATE_EXCLUDED
|
||||
return DirectoryState.Excluded
|
||||
|
||||
def _get_folders(self, from_folder):
|
||||
# We don't want to scan bundle's subfolder even in Folders mode. Bundle's integrity has to
|
||||
# stay intact.
|
||||
if is_bundle(str(from_folder.path)):
|
||||
# just yield the current folder and bail
|
||||
state = self.get_state(from_folder.path)
|
||||
from_folder.is_ref = state == DirectoryState.Reference
|
||||
yield from_folder
|
||||
return
|
||||
else:
|
||||
for folder in DirectoriesBase._get_folders(self, from_folder):
|
||||
yield folder
|
||||
|
||||
@staticmethod
|
||||
def get_subfolders(path):
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
|
||||
import hashlib
|
||||
|
||||
from hscommon import io
|
||||
from hscommon.util import nonone
|
||||
|
||||
from core import fs
|
||||
|
||||
class Bundle(fs.File):
|
||||
"""This class is for Mac OSX bundles (.app). Bundles are seen by the OS as
|
||||
normal directories, but I don't want that in dupeGuru. I want dupeGuru
|
||||
to see them as files.
|
||||
"""
|
||||
def _read_info(self, field):
|
||||
if field in ('size', 'mtime'):
|
||||
files = fs.get_all_files(self.path)
|
||||
size = sum((file.size for file in files), 0)
|
||||
self.size = size
|
||||
stats = io.stat(self.path)
|
||||
self.mtime = nonone(stats.st_mtime, 0)
|
||||
elif field in ('md5', 'md5partial'):
|
||||
# What's sensitive here is that we must make sure that subfiles'
|
||||
# md5 are always added up in the same order, but we also want a
|
||||
# different md5 if a file gets moved in a different subdirectory.
|
||||
def get_dir_md5_concat():
|
||||
files = fs.get_all_files(self.path)
|
||||
files.sort(key=lambda f:f.path)
|
||||
md5s = [getattr(f, field) for f in files]
|
||||
return b''.join(md5s)
|
||||
|
||||
md5 = hashlib.md5(get_dir_md5_concat())
|
||||
digest = md5.digest()
|
||||
setattr(self, field, digest)
|
||||
@@ -1,43 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
|
||||
import hashlib
|
||||
|
||||
from hscommon.path import Path
|
||||
from hscommon.testutil import eq_
|
||||
from core.fs import File
|
||||
from core.tests.directories_test import create_fake_fs
|
||||
|
||||
from .. import fs
|
||||
|
||||
def test_size_aggregates_subfiles(tmpdir):
|
||||
p = create_fake_fs(Path(str(tmpdir)))
|
||||
b = fs.Bundle(p)
|
||||
eq_(b.size, 12)
|
||||
|
||||
def test_md5_aggregate_subfiles_sorted(tmpdir):
|
||||
#dir.allfiles can return child in any order. Thus, bundle.md5 must aggregate
|
||||
#all files' md5 it contains, but it must make sure that it does so in the
|
||||
#same order everytime.
|
||||
p = create_fake_fs(Path(str(tmpdir)))
|
||||
b = fs.Bundle(p)
|
||||
md5s = File(p + ('dir1', 'file1.test')).md5
|
||||
md5s += File(p + ('dir2', 'file2.test')).md5
|
||||
md5s += File(p + ('dir3', 'file3.test')).md5
|
||||
md5s += File(p + 'file1.test').md5
|
||||
md5s += File(p + 'file2.test').md5
|
||||
md5s += File(p + 'file3.test').md5
|
||||
md5 = hashlib.md5(md5s)
|
||||
eq_(b.md5, md5.digest())
|
||||
|
||||
def test_has_file_attrs(tmpdir):
|
||||
#a Bundle must behave like a file, so it must have mtime attributes
|
||||
b = fs.Bundle(Path(str(tmpdir)))
|
||||
assert b.mtime > 0
|
||||
eq_(b.extension, '')
|
||||
Reference in New Issue
Block a user