blob: 93f40e6a061014b1f02e727bd754a6bcd1d1d1f1 [file] [log] [blame]
Jack Jansen58fc91f2002-12-17 23:28:24 +00001"""macfs - Pure Python module designed to be backward compatible with
2macfs and MACFS.
3"""
4import sys
5
6# First step: ensure we also emulate the MACFS module, which contained
7# all the constants
8
9sys.modules['MACFS'] = sys.modules[__name__]
10
11# Import all those constants
Jack Jansen4235e712002-12-19 23:26:07 +000012from Carbon.Files import *
13from Carbon.Folders import *
14# Another method:
Jack Jansen58fc91f2002-12-17 23:28:24 +000015from Carbon.Folder import FindFolder
16
17# For some obscure historical reason these are here too:
18READ = 1
19WRITE = 2
20smAllScripts = -3
21
Jack Jansen4235e712002-12-19 23:26:07 +000022
Jack Jansen58fc91f2002-12-17 23:28:24 +000023import Carbon.File
Jack Jansen4235e712002-12-19 23:26:07 +000024# The old name of the error object:
25error = Carbon.File.Error
Jack Jansen58fc91f2002-12-17 23:28:24 +000026
27class FSSpec(Carbon.File.FSSpec):
Jack Jansen4235e712002-12-19 23:26:07 +000028 def as_fsref(self):
Jack Jansen58fc91f2002-12-17 23:28:24 +000029 return FSRef(self)
30
31 def NewAlias(self, src=None):
Jack Jansen4235e712002-12-19 23:26:07 +000032 return Alias(Carbon.File.NewAlias(src, self))
Jack Jansen58fc91f2002-12-17 23:28:24 +000033
34 def GetCreatorType(self):
35 finfo = self.FSpGetFInfo()
Jack Jansen4235e712002-12-19 23:26:07 +000036 return finfo.Creator, finfo.Type
Jack Jansen58fc91f2002-12-17 23:28:24 +000037
38 def SetCreatorType(self, ctor, tp):
39 finfo = self.FSpGetFInfo()
Jack Jansen4235e712002-12-19 23:26:07 +000040 finfo.Creator = ctor
41 finfo.Type = tp
Jack Jansen58fc91f2002-12-17 23:28:24 +000042 self.FSpSetFInfo(finfo)
43
44 def GetFInfo(self):
45 return self.FSpGetFInfo()
46
47 def SetFInfo(self, info):
48 return self.FSpSetFInfo(info)
49
50 def GetDates(self):
Jack Jansen4235e712002-12-19 23:26:07 +000051 import os
52 statb = os.stat(self.as_pathname())
53 return statb.st_ctime, statb.st_mtime, 0
Jack Jansen58fc91f2002-12-17 23:28:24 +000054
55 def SetDates(self, *dates):
Jack Jansen4235e712002-12-19 23:26:07 +000056 print "FSSpec.SetDates no longer implemented"
Jack Jansen58fc91f2002-12-17 23:28:24 +000057
58class FSRef(Carbon.File.FSRef):
Jack Jansen4235e712002-12-19 23:26:07 +000059 def as_fsspec(self):
Jack Jansen58fc91f2002-12-17 23:28:24 +000060 return FSSpec(self)
61
62class Alias(Carbon.File.Alias):
63
Jack Jansen58fc91f2002-12-17 23:28:24 +000064 def GetInfo(self, index):
65 return self.GetAliasInfo(index)
66
67 def Update(self, *args):
Jack Jansen4235e712002-12-19 23:26:07 +000068 print "Alias.Update not yet implemented"
69
70 def Resolve(self, src=None):
71 return self.ResolveAlias(src)[1:]
72
73from Carbon.File import FInfo
Jack Jansen58fc91f2002-12-17 23:28:24 +000074
75FSSpecType = FSSpec
76FSRefType = FSRef
77AliasType = Alias
78FInfoType = FInfo
79
80def ResolveAliasFile(fss, chain=1):
Jack Jansene77f58a2002-12-24 13:09:28 +000081 return Carbon.File.ResolveAliasFile(fss, chain)
Jack Jansen58fc91f2002-12-17 23:28:24 +000082
83def RawFSSpec(data):
84 return FSSpec(rawdata=data)
85
86def RawAlias(data):
87 return Alias(rawdata=data)
88
89def FindApplication(*args):
90 raise NotImplementedError, "FindApplication no longer implemented"
91
92def NewAliasMinimalFromFullPath(path):
Jack Jansen4235e712002-12-19 23:26:07 +000093 return Carbon.Files.NewAliasMinimalFromFullPath(path, '', '')
94
95# Finally, install nav services
96import macfsn