Thanks for the reply Bob.  I've been digging around in the Python Documentation Macintosh and more specifically Carbon.File.  
(All seems to be a bit of a secret society :~) with scant docs that are not up to date and no content in __doc__s so it's a little hard going)

What you noted doesn't seem to work verbatim for me, but noting the following from the Python site googling:
ResolveAliasFile(file)    Resolve an alias file. Returns a 3-tuple (fsspec, isfolder, aliased) where fsspec is the resulting FSSpec object,  isfolder is true if fsspec points to a folder and aliased is true if the file was an alias in the first place (otherwise the FSSpec object for the file itself is returned).


and following your lead I got the following where ppath is an Aqua alias to a folder so I need to check for an Aqua alias to a file:
>>> FSResolveAliasFile(ppath, 1)
(<Carbon.File.FSRef object at 0xe0a70>, 1, 1)
>>> FSResolveAliasFile(ppath, 1)[0].as_pathname()
'/Library/Documentation'

with the FSRef though I get the following 
>>> def is_alias(ppath):
...      return FSRef(ppath)[0]
...
>>> ppath = '/Users/Chinook/Documents/Personal/Sys Documentation alias 1'
>>> is_alias(ppath)
Traceback (most recent call last):
  File "/Applications/WingIDE-Professional-2.0.3/WingIDE.app/Contents/MacOS/src/debug/server/_sandbox.py", line 1, in ?
    # Used internally for debug sandbox under external interpreter
  File "/Applications/WingIDE-Professional-2.0.3/WingIDE.app/Contents/MacOS/src/debug/server/_sandbox.py", line 2, in is_alias
    if __name__ == '__main__':
TypeError: unsubscriptable object  

Or from the Terminal:
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from Carbon.File import FSResolveAliasFile, FSRef
>>> FSRef('/Users/Chinook/Documents/Personal/Sys Documentation alias 1')
<Carbon.File.FSRef object at 0x16cd8>
>>> def is_alias(ppath):
...   return FSRef(ppath)[0]
...
>>> ppath = '/Users/Chinook/Documents/Personal/Sys Documentation alias 1'
>>> is_alias(ppath)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in is_alias
TypeError: unsubscriptable object
>>>


Guess I'll have to do some more googling, but it (tentatively) looks like I'm getting back a file ref object as if .data is a default and I have to look at what other methods are available.

Thanks again,
Lee C



On Jun 5, 2005, at 11:02 PM, Bob Ippolito wrote:


On Jun 5, 2005, at 7:09 PM, Lee Cullens wrote:


One of my little utilities needs to know when it encounters links/
aliases.

I can of course detect a Unix symbolic link with os.path.islink
('path') and determine what it points to with os.readlink('path'),
but an Aqua alias only triggers os.isfile and it has a size of zero.
The size is not a reliable indicator though and I was wondering how
(in Python) to detect such and determine what it points to.

Is this one of those OS unique things where I need to get into the
dev tools to resolve? I've been putting such off till I get into
ObjC, since Bob said I would understand the interfaces better then.


Aliases have nothing to do with Objective-C, they're only dealt with from Carbon.

import os
from Carbon.File import FSResolveAliasFile, FSRef

def resolve_alias(path):
    # resolve an alias, if not an alias then it will just return the
    # given path.
    return FSResolveAliasFile(path, True)[0].as_pathname()

def is_alias(path):
    # return 1 if an alias, 0 otherwise
    return FSRef(path)[0]

-bob



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to