From 57d53a90d92e83f7d3a72d5c775be9f52aa0d89c Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Sun, 15 Sep 1996 22:13:26 +0000 Subject: - Optionally copy file times for copy/copytree (default on) - Added touch(file) routine to tell the finder a files icon or something has changed (*finally* found out how to do this) --- Mac/Lib/macostools.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Mac/Lib/macostools.py b/Mac/Lib/macostools.py index da1e3ab..46eef98 100644 --- a/Mac/Lib/macostools.py +++ b/Mac/Lib/macostools.py @@ -9,6 +9,7 @@ import Res import os from MACFS import * import MacOS +import time try: openrf = MacOS.openrf except AttributeError: @@ -52,7 +53,18 @@ def mkdirs(dst): mkdirs(head) os.mkdir(dst, 0777) -def copy(src, dst, createpath=0): +def touched(dst): + """Tell the finder a file has changed""" + file_fss = macfs.FSSpec(dst) + vRefNum, dirID, name = file_fss.as_tuple() + dir_fss = macfs.FSSpec((vRefNum, dirID, '')) + crdate, moddate, bkdate = dir_fss.GetDates() + now = time.time() + if now == moddate: + now = now + 1 + dir_fss.SetDates(crdate, now, bkdate) + +def copy(src, dst, createpath=0, copydates=1): """Copy a file, including finder info, resource fork, etc""" if createpath: mkdirs(os.path.split(dst)[0]) @@ -82,13 +94,17 @@ def copy(src, dst, createpath=0): df.Creator, df.Type = sf.Creator, sf.Type df.Flags = (sf.Flags & (kIsStationary|kNameLocked|kHasBundle|kIsInvisible|kIsAlias)) dstfss.SetFInfo(df) + if copydates: + crdate, mddate, bkdate = srcfss.GetDates() + dstfss.SetDates(crdate, mddate, bkdate) + touched(dstfss) -def copytree(src, dst): +def copytree(src, dst, copydates=1): """Copy a complete file tree to a new destination""" if os.path.isdir(src): mkdirs(dst) files = os.listdir(src) for f in files: - copytree(os.path.join(src, f), os.path.join(dst, f)) + copytree(os.path.join(src, f), os.path.join(dst, f), copydates) else: - copy(src, dst, 1) + copy(src, dst, 1, copydates) -- cgit v0.12