From 4d7f03288916352a1e8702b6ac92b3c34b5763bc Mon Sep 17 00:00:00 2001 From: hsoft Date: Fri, 23 Oct 2009 13:46:18 +0000 Subject: [PATCH] dgse cocoa: fixed quirks created by the hsfs move. --HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40203 --- base/py/app_cocoa.py | 10 +++++++--- base/py/directories.py | 12 ++++++++---- base/py/fs.py | 8 ++++++-- se/cocoa/py/dg_cocoa.py | 10 +++++----- se/py/app_cocoa.py | 3 ++- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/base/py/app_cocoa.py b/base/py/app_cocoa.py index 20ad41e8..780388bb 100644 --- a/base/py/app_cocoa.py +++ b/base/py/app_cocoa.py @@ -242,8 +242,11 @@ class DupeGuru(app.DupeGuru): return [len(g.dupes) for g in self.results.groups] elif tag == 1: #Directories try: - path = self.get_folder_path(node_path) - subfolders = self.directories.get_subfolders(path) + if node_path: + path = self.get_folder_path(node_path) + subfolders = self.directories.get_subfolders(path) + else: + subfolders = self.directories return [len(self.directories.get_subfolders(path)) for path in subfolders] except IndexError: # node_path out of range return [] @@ -269,7 +272,8 @@ class DupeGuru(app.DupeGuru): elif tag == 1: #Directories try: path = self.get_folder_path(node_path) - return [path[-1], self.directories.get_state(path)] + name = unicode(path) if len(node_path) == 1 else path[-1] + return [name, self.directories.get_state(path)] except IndexError: # node_path out of range return [] diff --git a/base/py/directories.py b/base/py/directories.py index 9a47b1ac..d61ff1a7 100644 --- a/base/py/directories.py +++ b/base/py/directories.py @@ -62,13 +62,17 @@ class Directories(object): if not any(p[:len(from_path)] == from_path for p in self.states): return try: - subdir_paths = [from_path + name for name in io.listdir(from_path) if io.isdir(from_path + name)] - for subdir_path in subdir_paths: - for file in self._get_files(subdir_path): - yield file + filepaths = set() if state != STATE_EXCLUDED: for file in fs.get_files(from_path, fileclasses=self.fileclasses): file.is_ref = state == STATE_REFERENCE + filepaths.add(file.path) + yield file + subpaths = [from_path + name for name in io.listdir(from_path)] + # it's possible that a folder (bundle) gets into the file list. in that case, we don't want to recurse into it + subfolders = [p for p in subpaths if not io.islink(p) and io.isdir(p) and p not in filepaths] + for subfolder in subfolders: + for file in self._get_files(subfolder): yield file except (EnvironmentError, fs.InvalidPath): pass diff --git a/base/py/fs.py b/base/py/fs.py index e962c38d..93bc1d4d 100644 --- a/base/py/fs.py +++ b/base/py/fs.py @@ -174,6 +174,10 @@ def get_files(path, fileclasses=[File]): raise InvalidPath(path) def get_all_files(path, fileclasses=[File]): - subfolders = [path + name for name in io.listdir(path) if not io.islink(path + name) and io.isdir(path + name)] + files = get_files(path, fileclasses=fileclasses) + filepaths = set(f.path for f in files) + subpaths = [path + name for name in io.listdir(path)] + # it's possible that a folder (bundle) gets into the file list. in that case, we don't want to recurse into it + subfolders = [p for p in subpaths if not io.islink(p) and io.isdir(p) and p not in filepaths] subfiles = flatten(get_all_files(subpath, fileclasses=fileclasses) for subpath in subfolders) - return subfiles + get_files(path, fileclasses=fileclasses) + return subfiles + files diff --git a/se/cocoa/py/dg_cocoa.py b/se/cocoa/py/dg_cocoa.py index 93eded52..11ce95b6 100644 --- a/se/cocoa/py/dg_cocoa.py +++ b/se/cocoa/py/dg_cocoa.py @@ -8,12 +8,12 @@ import objc from AppKit import * -from dupeguru import app_se_cocoa, scanner +from dupeguru_se.app_cocoa import DupeGuru +from dupeguru import scanner # Fix py2app imports with chokes on relative imports -from dupeguru import app, app_cocoa, data, directories, engine, export, ignore, results, scanner -from hsfs import auto, stats, tree -from hsfs.phys import bundle +from dupeguru_se import fs, data +from dupeguru import app, app_cocoa, data, directories, engine, export, ignore, results, fs from hsutil import conflict class PyApp(NSObject): @@ -22,7 +22,7 @@ class PyApp(NSObject): class PyDupeGuru(PyApp): def init(self): self = super(PyDupeGuru,self).init() - self.app = app_se_cocoa.DupeGuru() + self.app = DupeGuru() return self #---Directories diff --git a/se/py/app_cocoa.py b/se/py/app_cocoa.py index cffc8134..4eb58820 100644 --- a/se/py/app_cocoa.py +++ b/se/py/app_cocoa.py @@ -19,6 +19,7 @@ from dupeguru import fs from dupeguru.app_cocoa import DupeGuru as DupeGuruBase from dupeguru.directories import Directories as DirectoriesBase, STATE_EXCLUDED from . import data +from .fs import Bundle as BundleBase if NSWorkspace.sharedWorkspace().respondsToSelector_('typeOfFile:error:'): # Only from 10.5 def is_bundle(str_path): @@ -55,6 +56,6 @@ class Directories(DirectoriesBase): class DupeGuru(DupeGuruBase): def __init__(self): - app_cocoa.DupeGuru.__init__(self, data, 'dupeGuru', appid=4) + DupeGuruBase.__init__(self, data, 'dupeGuru', appid=4) self.directories = Directories()