mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-02-03 20:01:38 +00:00
dg se: Moved se-specific code from dupeguru to dupeguru_se.
--HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40199
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
# Created By: Virgil Dupras
|
||||
# Created On: 2009-05-24
|
||||
# $Id$
|
||||
# Copyright 2009 Hardcoded Software (http://www.hardcoded.net)
|
||||
#
|
||||
# This software is licensed under the "HS" 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/hs_license
|
||||
|
||||
import logging
|
||||
|
||||
from AppKit import *
|
||||
|
||||
from hsfs.phys import Directory as DirectoryBase
|
||||
from hsfs.phys.bundle import Bundle
|
||||
from hsutil.path import Path
|
||||
from hsutil.misc import extract
|
||||
from hsutil.str import get_file_ext
|
||||
|
||||
from . import app_cocoa, data
|
||||
from .directories import Directories as DirectoriesBase, STATE_EXCLUDED
|
||||
|
||||
if NSWorkspace.sharedWorkspace().respondsToSelector_('typeOfFile:error:'): # Only from 10.5
|
||||
def is_bundle(str_path):
|
||||
sw = NSWorkspace.sharedWorkspace()
|
||||
uti, error = sw.typeOfFile_error_(str_path)
|
||||
if error is not None:
|
||||
logging.warning(u'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')
|
||||
else: # Tiger
|
||||
def is_bundle(str_path): # just return a list of a few known bundle extensions.
|
||||
return get_file_ext(str_path) in ('app', 'pages', 'numbers')
|
||||
|
||||
class DGDirectory(DirectoryBase):
|
||||
def _create_sub_file(self, name, with_parent=True):
|
||||
if is_bundle(unicode(self.path + name)):
|
||||
parent = self if with_parent else None
|
||||
return Bundle(parent, name)
|
||||
else:
|
||||
return super(DGDirectory, self)._create_sub_file(name, with_parent)
|
||||
|
||||
def _fetch_subitems(self):
|
||||
subdirs, subfiles = super(DGDirectory, self)._fetch_subitems()
|
||||
apps, normal_dirs = extract(lambda name: is_bundle(unicode(self.path + name)), subdirs)
|
||||
subfiles += apps
|
||||
return normal_dirs, subfiles
|
||||
|
||||
|
||||
class Directories(DirectoriesBase):
|
||||
ROOT_PATH_TO_EXCLUDE = map(Path, ['/Library', '/Volumes', '/System', '/bin', '/sbin', '/opt', '/private', '/dev'])
|
||||
HOME_PATH_TO_EXCLUDE = [Path('Library')]
|
||||
def __init__(self):
|
||||
DirectoriesBase.__init__(self)
|
||||
self.dirclass = DGDirectory
|
||||
|
||||
def _default_state_for_path(self, path):
|
||||
result = DirectoriesBase._default_state_for_path(self, path)
|
||||
if result is not None:
|
||||
return result
|
||||
if path in self.ROOT_PATH_TO_EXCLUDE:
|
||||
return STATE_EXCLUDED
|
||||
if path[:2] == Path('/Users') and path[3:] in self.HOME_PATH_TO_EXCLUDE:
|
||||
return STATE_EXCLUDED
|
||||
|
||||
|
||||
class DupeGuru(app_cocoa.DupeGuru):
|
||||
def __init__(self):
|
||||
app_cocoa.DupeGuru.__init__(self, data, 'dupeGuru', appid=4)
|
||||
self.directories = Directories()
|
||||
|
||||
@@ -40,63 +40,3 @@ def format_dupe_count(c):
|
||||
|
||||
def cmp_value(value):
|
||||
return value.lower() if isinstance(value, basestring) else value
|
||||
|
||||
COLUMNS = [
|
||||
{'attr':'name','display':'Filename'},
|
||||
{'attr':'path','display':'Directory'},
|
||||
{'attr':'size','display':'Size (KB)'},
|
||||
{'attr':'extension','display':'Kind'},
|
||||
{'attr':'ctime','display':'Creation'},
|
||||
{'attr':'mtime','display':'Modification'},
|
||||
{'attr':'percentage','display':'Match %'},
|
||||
{'attr':'words','display':'Words Used'},
|
||||
{'attr':'dupe_count','display':'Dupe Count'},
|
||||
]
|
||||
|
||||
METADATA_TO_READ = ['size', 'ctime', 'mtime']
|
||||
|
||||
def GetDisplayInfo(dupe, group, delta):
|
||||
size = dupe.size
|
||||
ctime = dupe.ctime
|
||||
mtime = dupe.mtime
|
||||
m = group.get_match_of(dupe)
|
||||
if m:
|
||||
percentage = m.percentage
|
||||
dupe_count = 0
|
||||
if delta:
|
||||
r = group.ref
|
||||
size -= r.size
|
||||
ctime -= r.ctime
|
||||
mtime -= r.mtime
|
||||
else:
|
||||
percentage = group.percentage
|
||||
dupe_count = len(group.dupes)
|
||||
return [
|
||||
dupe.name,
|
||||
format_path(dupe.path),
|
||||
format_size(size, 0, 1, False),
|
||||
dupe.extension,
|
||||
format_timestamp(ctime, delta and m),
|
||||
format_timestamp(mtime, delta and m),
|
||||
format_perc(percentage),
|
||||
format_words(dupe.words) if hasattr(dupe, 'words') else '',
|
||||
format_dupe_count(dupe_count)
|
||||
]
|
||||
|
||||
def GetDupeSortKey(dupe, get_group, key, delta):
|
||||
if key == 6:
|
||||
m = get_group().get_match_of(dupe)
|
||||
return m.percentage
|
||||
if key == 8:
|
||||
return 0
|
||||
r = cmp_value(getattr(dupe, COLUMNS[key]['attr']))
|
||||
if delta and (key in (2, 4, 5)):
|
||||
r -= cmp_value(getattr(get_group().ref, COLUMNS[key]['attr']))
|
||||
return r
|
||||
|
||||
def GetGroupSortKey(group, key):
|
||||
if key == 6:
|
||||
return group.percentage
|
||||
if key == 8:
|
||||
return len(group)
|
||||
return cmp_value(getattr(group.ref, COLUMNS[key]['attr']))
|
||||
|
||||
@@ -145,6 +145,7 @@ class DupeGuru(DupeGuruBase, QObject):
|
||||
|
||||
def ask_for_reg_code(self):
|
||||
if self.reg.ask_for_code():
|
||||
#XXX bug???
|
||||
self._setup_ui_as_registered()
|
||||
|
||||
@demo_method
|
||||
|
||||
Reference in New Issue
Block a user