1 """macfs - Pure Python module designed to be backward compatible with
10 warnings
.warn("macfs is deprecated, use Carbon.File, Carbon.Folder or EasyDialogs",
11 DeprecationWarning, stacklevel
=2)
13 # First step: ensure we also emulate the MACFS module, which contained
16 sys
.modules
['MACFS'] = sys
.modules
[__name__
]
18 # Import all those constants
19 from Carbon
.Files
import *
20 from Carbon
.Folders
import *
22 # For some obscure historical reason these are here too:
28 # Find the epoch conversion for file dates in a way that works on OS9 and OSX
30 if time
.gmtime(0)[0] == 1970:
31 _EPOCHCONVERT
= -((1970-1904)*365 + 17) * (24*60*60) + 0x100000000L
33 t
= utc
[1] + _EPOCHCONVERT
36 t
= int(t
) - _EPOCHCONVERT
51 # The old name of the error object:
52 error
= Carbon
.File
.Error
55 # The various objects macfs used to export. We override them here, because some
56 # of the method names are subtly different.
58 class FSSpec(Carbon
.File
.FSSpec
):
62 def NewAlias(self
, src
=None):
63 return Alias(Carbon
.File
.NewAlias(src
, self
))
65 def GetCreatorType(self
):
66 finfo
= self
.FSpGetFInfo()
67 return finfo
.Creator
, finfo
.Type
69 def SetCreatorType(self
, ctor
, tp
):
70 finfo
= self
.FSpGetFInfo()
73 self
.FSpSetFInfo(finfo
)
76 return self
.FSpGetFInfo()
78 def SetFInfo(self
, info
):
79 return self
.FSpSetFInfo(info
)
82 catInfoFlags
= kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
83 catinfo
, d1
, d2
, d3
= FSRef(self
).FSGetCatalogInfo(catInfoFlags
)
84 cdate
= catinfo
.createDate
85 mdate
= catinfo
.contentModDate
86 bdate
= catinfo
.backupDate
87 return _utc2time(cdate
), _utc2time(mdate
), _utc2time(bdate
)
89 def SetDates(self
, cdate
, mdate
, bdate
):
90 catInfoFlags
= kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
91 catinfo
= Carbon
.File
.FSCatalogInfo(
92 createDate
= _time2utc(cdate
),
93 contentModDate
= _time2utc(mdate
),
94 backupDate
= _time2utc(bdate
))
95 FSRef(self
).FSSetCatalogInfo(catInfoFlags
, catinfo
)
97 class FSRef(Carbon
.File
.FSRef
):
101 class Alias(Carbon
.File
.Alias
):
103 def GetInfo(self
, index
):
104 return self
.GetAliasInfo(index
)
106 def Update(self
, *args
):
107 pass # print "Alias.Update not yet implemented"
109 def Resolve(self
, src
=None):
110 fss
, changed
= self
.ResolveAlias(src
)
111 return FSSpec(fss
), changed
113 from Carbon
.File
import FInfo
115 # Backward-compatible type names:
122 def ResolveAliasFile(fss
, chain
=1):
123 fss
, isdir
, isalias
= Carbon
.File
.ResolveAliasFile(fss
, chain
)
124 return FSSpec(fss
), isdir
, isalias
127 return FSSpec(rawdata
=data
)
130 return Alias(rawdata
=data
)
132 def FindApplication(*args
):
133 raise NotImplementedError, "FindApplication no longer implemented"
135 def NewAliasMinimalFromFullPath(path
):
136 return Alias(Carbon
.File
.NewAliasMinimalFromFullPath(path
, '', ''))
138 # Another global function:
139 from Carbon
.Folder
import FindFolder
142 # Finally the old Standard File routine emulators.
147 def StandardGetFile(*typelist
):
148 """Ask for an input file, optionally specifying 4-char file types that are
150 return PromptGetFile('', *typelist
)
152 def PromptGetFile(prompt
, *typelist
):
153 """Ask for an input file giving the user a prompt message. Optionally you can
154 specifying 4-char file types that are allowable"""
156 warnings
.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
157 DeprecationWarning, stacklevel
=2)
160 fss
= EasyDialogs
.AskFileForOpen(message
=prompt
, wanted
=FSSpec
,
161 typeList
=typelist
, defaultLocation
=_handleSetFolder())
162 return fss
, not fss
is None
164 def StandardPutFile(prompt
, default
=None):
165 """Ask the user for an output file, with a prompt. Optionally you cn supply a
166 default output filename"""
168 warnings
.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
169 DeprecationWarning, stacklevel
=2)
170 fss
= EasyDialogs
.AskFileForSave(wanted
=FSSpec
, message
=prompt
,
171 savedFileName
=default
, defaultLocation
=_handleSetFolder())
172 return fss
, not fss
is None
174 def SetFolder(folder
):
176 warnings
.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
177 DeprecationWarning, stacklevel
=2)
179 rv
= FSSpec(_curfolder
)
185 def _handleSetFolder():
191 def GetDirectory(prompt
=None):
192 """Ask the user to select a folder. Optionally you can give a prompt."""
194 warnings
.warn("macfs.StandardGetFile and friends are deprecated, use EasyDialogs.AskFileForOpen",
195 DeprecationWarning, stacklevel
=2)
196 fss
= EasyDialogs
.AskFolder(message
=prompt
, wanted
=FSSpec
,
197 defaultLocation
=_handleSetFolder())
198 return fss
, not fss
is None