Identifying bundles in MacOS X

Michael J. Fromberger Michael.J.Fromberger at Clothing.Dartmouth.EDU
Thu Nov 11 17:04:21 EST 2004


Greetings,

The following question pertains to a problem I am solving in Python 
2.4b2 on a MacOS 10 (Panther) system with an HFS+ filesystem.

Given the pathname of a directory in my filesystem, I would like a 
graceful way to determine whether or not that directory represents a 
"bundle", in the sense that, when you double-click on the directory's 
icon in the Finder, it is launched rather than "opened" for viewing.
Applications behave this way by default, but so do various other file 
types (e.g., the "rtfd" files created by TextEdit, and the data files 
for certain applications such as Quicken).

So, what I want is the following:  A function I can call which will, 
given a pathname, return True if the corresponding directory has that 
property, and False otherwise.  So far, I'm stumped.  Can anyone help?  

Here are the things I've tried so far:

I found the Carbon.File module, and tried what I thought was the obvious 
thing:

  from Carbon import File

  fss = File.FSSpec(dir_path)
  info = fss.FSpGetFInfo()

This, unfortunately, does not seem to work for directories; an OSError 
is raised (-43, File Not Found).  I investigated on Apple's developer 
site, and it seems this is the expected behaviour.  So, no fault of 
Python there.

Next, I tried the following:

  from Carbon import Files

  fsr = File.FSRef(dir_path)
  cat_info = fsr.FSGetCatalogInfo(Files.kFSCatInfoFinderInfo)

This works, but now I have no idea how to determine the answer to my 
question.  The value of cat_info is a tuple consisting of:

  - a File.FSCatalogInfo object
  - a Unicode string (the name of the directory)
  - a File.FSSpec object
  - a File.FSRef object

According to [1], the FSCatalogInfo structure has finderInfo and 
extFinderInfo fields, which ought to contain what I'm after (I think), 
but these do not appear to be exposed by the FSCatalogInfo class in the 
Carbon.File library, even if I specify I want the Finder info and 
extended Finder info when I call FSGetCatalogInfo().

All right, so now my questions for those of you who know better than I 
do, are these:

1. Am I looking in the right place for this information?

2. If not, is there a preferred method for determining whether
   a given directory represents a "bundle" in the MacOS sense?

I would be most grateful for any helpful advice you might be able to 
lend me regarding this puzzle.

Thanks,
-M

P.S.- I was disconcerted to discover that the Python documentation
      does not seem to list the Carbon.File module.  The macfs module 
      is listed, but it is deprecated, so I would prefer not to use it 
      in new code.

References:
[1] Carbon API documentation, "FSCatalogInfo"
    http://shorl.com/biginegastuni

-- 
Michael J. Fromberger             | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA



More information about the Python-list mailing list