[Python-checkins] python/dist/src/Lib/plat-mac macfs.py,1.2,1.3
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Wed, 15 Jan 2003 14:36:18 -0800
Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1:/tmp/cvs-serv26831/Lib/plat-mac
Modified Files:
macfs.py
Log Message:
Implemented FSCatalogInfo structure support, and used this to implement
FSSpec.SetDates() and GetDates(). Closes #662836.
Index: macfs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/macfs.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** macfs.py 8 Jan 2003 16:32:29 -0000 1.2
--- macfs.py 15 Jan 2003 22:36:16 -0000 1.3
***************
*** 22,25 ****
--- 22,42 ----
smAllScripts = -3
+ #
+ # Find the epoch conversion for file dates in a way that works on OS9 and OSX
+ import time
+ if time.gmtime(0)[0] == 1970:
+ _EPOCHCONVERT = -((1970-1904)*365 + 17) * (24*60*60) + 0x100000000L
+ def _utc2time(utc):
+ t = utc[1] + _EPOCHCONVERT
+ return int(t)
+ def _time2utc(t):
+ t = t - _EPOCHCONVERT
+ if t < -0x7fffffff:
+ t = t + 0x10000000L
+ return (0, int(t), 0)
+ else:
+ def _utc2time(utc): return utc[1]
+ def _time2utc(t): return (0, t, 0)
+
# The old name of the error object:
error = Carbon.File.Error
***************
*** 53,62 ****
def GetDates(self):
! import os
! statb = os.stat(self.as_pathname())
! return statb.st_ctime, statb.st_mtime, 0
! def SetDates(self, *dates):
! pass # print "FSSpec.SetDates not yet implemented"
class FSRef(Carbon.File.FSRef):
--- 70,87 ----
def GetDates(self):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo, d1, d2, d3 = FSRef(self).FSGetCatalogInfo(catInfoFlags)
! cdate = catinfo.createDate
! mdate = catinfo.contentModDate
! bdate = catinfo.backupDate
! return _utc2time(cdate), _utc2time(mdate), _utc2time(bdate)
! def SetDates(self, cdate, mdate, bdate):
! catInfoFlags = kFSCatInfoCreateDate|kFSCatInfoContentMod|kFSCatInfoBackupDate
! catinfo = Carbon.File.FSCatalogInfo(
! createDate = _time2utc(cdate),
! contentModDate = _time2utc(mdate),
! backupDate = _time2utc(bdate))
! FSRef(self).FSSetCatalogInfo(catInfoFlags, catinfo)
class FSRef(Carbon.File.FSRef):