Added partial is_bundle() support for Tiger (I hadn't noticed that typeOfFile:error: was Leopard only).

--HG--
extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40132
This commit is contained in:
hsoft 2009-09-07 10:06:41 +00:00
parent cc1bb76c07
commit 3cf2839dc3
1 changed files with 10 additions and 7 deletions

View File

@ -20,16 +20,19 @@ from hsutil.str import get_file_ext
from . import app_cocoa, data
from .directories import Directories as DirectoriesBase, STATE_EXCLUDED
def is_bundle(path):
sw = NSWorkspace.sharedWorkspace()
uti, error = sw.typeOfFile_error_(path)
if error is not None:
logging.warning(u'There was an error trying to detect the UTI of %s', path)
return sw.type_conformsToType_(uti, 'com.apple.bundle') or sw.type_conformsToType_(uti, 'com.apple.package')
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):
ext = get_file_ext(name)
if is_bundle(unicode(self.path + name)):
parent = self if with_parent else None
return Bundle(parent, name)