Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 1 | """macfs - Pure Python module designed to be backward compatible with |
| 2 | macfs and MACFS. |
| 3 | """ |
| 4 | import sys |
| 5 | |
| 6 | # First step: ensure we also emulate the MACFS module, which contained |
| 7 | # all the constants |
| 8 | |
| 9 | sys.modules['MACFS'] = sys.modules[__name__] |
| 10 | |
| 11 | # Import all those constants |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 12 | from Carbon.Files import * |
| 13 | from Carbon.Folders import * |
| 14 | # Another method: |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 15 | from Carbon.Folder import FindFolder |
| 16 | |
| 17 | # For some obscure historical reason these are here too: |
| 18 | READ = 1 |
| 19 | WRITE = 2 |
| 20 | smAllScripts = -3 |
| 21 | |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 22 | |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 23 | import Carbon.File |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 24 | # The old name of the error object: |
| 25 | error = Carbon.File.Error |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 26 | |
| 27 | class FSSpec(Carbon.File.FSSpec): |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 28 | def as_fsref(self): |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 29 | return FSRef(self) |
| 30 | |
| 31 | def NewAlias(self, src=None): |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 32 | return Alias(Carbon.File.NewAlias(src, self)) |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 33 | |
| 34 | def GetCreatorType(self): |
| 35 | finfo = self.FSpGetFInfo() |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 36 | return finfo.Creator, finfo.Type |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 37 | |
| 38 | def SetCreatorType(self, ctor, tp): |
| 39 | finfo = self.FSpGetFInfo() |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 40 | finfo.Creator = ctor |
| 41 | finfo.Type = tp |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 42 | 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 Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 51 | import os |
| 52 | statb = os.stat(self.as_pathname()) |
| 53 | return statb.st_ctime, statb.st_mtime, 0 |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 54 | |
| 55 | def SetDates(self, *dates): |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 56 | print "FSSpec.SetDates no longer implemented" |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 57 | |
| 58 | class FSRef(Carbon.File.FSRef): |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 59 | def as_fsspec(self): |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 60 | return FSSpec(self) |
| 61 | |
| 62 | class Alias(Carbon.File.Alias): |
| 63 | |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 64 | def GetInfo(self, index): |
| 65 | return self.GetAliasInfo(index) |
| 66 | |
| 67 | def Update(self, *args): |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 68 | print "Alias.Update not yet implemented" |
| 69 | |
| 70 | def Resolve(self, src=None): |
Jack Jansen | 315e9be | 2002-12-26 20:46:54 +0000 | [diff] [blame^] | 71 | fss, changed = self.ResolveAlias(src) |
| 72 | return FSSpec(fss), changed |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 73 | |
| 74 | from Carbon.File import FInfo |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 75 | |
| 76 | FSSpecType = FSSpec |
| 77 | FSRefType = FSRef |
| 78 | AliasType = Alias |
| 79 | FInfoType = FInfo |
| 80 | |
| 81 | def ResolveAliasFile(fss, chain=1): |
Jack Jansen | 315e9be | 2002-12-26 20:46:54 +0000 | [diff] [blame^] | 82 | fss, isdir, isalias = Carbon.File.ResolveAliasFile(fss, chain) |
| 83 | return FSSpec(fss), isdir, isalias |
Jack Jansen | 58fc91f | 2002-12-17 23:28:24 +0000 | [diff] [blame] | 84 | |
| 85 | def RawFSSpec(data): |
| 86 | return FSSpec(rawdata=data) |
| 87 | |
| 88 | def RawAlias(data): |
| 89 | return Alias(rawdata=data) |
| 90 | |
| 91 | def FindApplication(*args): |
| 92 | raise NotImplementedError, "FindApplication no longer implemented" |
| 93 | |
| 94 | def NewAliasMinimalFromFullPath(path): |
Jack Jansen | 315e9be | 2002-12-26 20:46:54 +0000 | [diff] [blame^] | 95 | return Alias(Carbon.File.NewAliasMinimalFromFullPath(path, '', '')) |
Jack Jansen | 4235e71 | 2002-12-19 23:26:07 +0000 | [diff] [blame] | 96 | |
| 97 | # Finally, install nav services |
| 98 | import macfsn |