Fwd: [Pythonmac-SIG] MacOSX posixpath to macpath?

Larry Meyn Larry.A.Meyn at nasa.gov
Sun Oct 5 15:38:37 EDT 2003

Begin forwarded message:

On Sunday, October 5, 2003, at 10:20 AM, Sean Hummel wrote:

> I probably just didn't look around enough, however I have a problem 
> with which I need help.
> The problem is that using Stuffit Installer Maker on OS X (even the 
> supposed OSX version of this program,) with the Generated OSA 
> wrappers, I need to pass string paths to SIM.  However SIM does not 
> accept the standard posix paths (i.e. '/Users/sean/instalerfile",)  
> that the newest version of MacPython for OSX uses. (In this case 2.3)  
> Instead it will only accept the old standard macintosh paths 
> ("MacHD:Users:sean:installerfile")
> Is there a conversion function for handling this? I need one because 
> of course these paths are going to be based off of different settings 
> per developer.
> I of course would prefer not use paths, but that is the way that SIM 
> works.
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig

I had this problem in mid-August (see subject "[Pythonmac-SIG] 
AppleEvents in MacPython 2.3?") and received a lot of help.  For known 
posix  paths try the following functions:

def makeOS9path(path):
	if path[0] != '/':
		return ":".join(path.split('/'))
		rootdisk = Carbon.File.FSRef('/').FSGetCatalogInfo(0)[2].as_tuple()[2]
		return rootdisk + ":".join(path.split('/'))

def makeOS9abspath(path):
	"""Returns an ":" delimited, OS 9 style absolute path.
	import Carbon.File, os.path
	abspath = os.path.abspath(path)
	rootdisk = Carbon.File.FSRef('/').FSGetCatalogInfo(0)[2].as_tuple()[2]
	abspath = rootdisk + ":".join(abspath.split('/'))

	if os.path.isdir(path):
		return abspath + ":"
		return abspath

For new paths, Jack Jasen offered the following snippet, note the 
potential problem with names longer than 31 characters and names with 
":" in them.  I would suggest that we all ask application developers to 
start supporting posix paths in their scriptable applications.

if os.path.exists(path):
	return makeOS9abspath(path)
head, tail = os.path.split(path)
head = makeOS9abspath(head)
if len(tail) > 31 or ':' in tail:
	raise IOError, "Come up with good error message here"
return macpath.join(head, unicode(tail, 'utf8').encode('mac-roman'))

Larry Meyn
Aerospace Operations Modeling Office

M/S 210-10                      Phone:  (650) 604-5038
NASA Ames Research Center       Fax:    (650) 604-0222
Moffett Field, CA 94035-1000    E-mail: Larry.A.Meyn at nasa.gov
                                 E-Fax:  (425) 944-5526 sent via e-mail

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2802 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20031005/6b8df4cf/attachment.bin

More information about the Pythonmac-SIG mailing list