Mercurial > cpython-lru_cache-weakref
comparison Mac/scripts/EditPythonPrefs.py @ 4448:85d38456adf0 legacy-trunk
Get preference file name from a resource.
Changed for 1.8.0 CWGUSI release
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Tue, 22 Oct 1996 15:33:02 +0000 |
| parents | ec4c42bea69d |
| children | f1244036ebab |
comparison
equal
deleted
inserted
replaced
| 4447:1ba22f749489 | 4448:85d38456adf0 |
|---|---|
| 12 import MacOS | 12 import MacOS |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 import Res # For Res.Error | 15 import Res # For Res.Error |
| 16 | 16 |
| 17 # Resource in the Python resource chain | |
| 18 PREFNAME_NAME="PythonPreferenceFileName" | |
| 19 | |
| 17 # resource IDs in our own resources (dialogs, etc) | 20 # resource IDs in our own resources (dialogs, etc) |
| 18 MESSAGE_ID = 256 | 21 MESSAGE_ID = 256 |
| 19 | 22 |
| 20 DIALOG_ID = 511 | 23 DIALOG_ID = 511 |
| 21 TEXT_ITEM = 1 | 24 TEXT_ITEM = 1 |
| 51 # Things we know about the GUSI resource. Note the code knows these too. | 54 # Things we know about the GUSI resource. Note the code knows these too. |
| 52 GUSIPOS_TYPE=0 | 55 GUSIPOS_TYPE=0 |
| 53 GUSIPOS_CREATOR=4 | 56 GUSIPOS_CREATOR=4 |
| 54 GUSIPOS_SKIP=8 | 57 GUSIPOS_SKIP=8 |
| 55 GUSIPOS_FLAGS=9 | 58 GUSIPOS_FLAGS=9 |
| 56 GUSIFLAGS_DELAY=0x04 # Mask | 59 GUSIPOS_VERSION=10 |
| 60 GUSIVERSION='0181' | |
| 61 GUSIFLAGS_DELAY=0x20 # Mask | |
| 57 | 62 |
| 58 READ = 1 | 63 READ = 1 |
| 59 WRITE = 2 | 64 WRITE = 2 |
| 60 smAllScripts = -3 | 65 smAllScripts = -3 |
| 61 kOnSystemDisk = 0x8000 | 66 kOnSystemDisk = 0x8000 |
| 199 return '????', '????', 0, None | 204 return '????', '????', 0, None |
| 200 data = opr.data | 205 data = opr.data |
| 201 type = data[GUSIPOS_TYPE:GUSIPOS_TYPE+4] | 206 type = data[GUSIPOS_TYPE:GUSIPOS_TYPE+4] |
| 202 creator = data[GUSIPOS_CREATOR:GUSIPOS_CREATOR+4] | 207 creator = data[GUSIPOS_CREATOR:GUSIPOS_CREATOR+4] |
| 203 flags = ord(data[GUSIPOS_FLAGS]) | 208 flags = ord(data[GUSIPOS_FLAGS]) |
| 209 version = data[GUSIPOS_VERSION:GUSIPOS_VERSION+4] | |
| 210 if version <> GUSIVERSION: | |
| 211 message('GU\267I resource version "%s", fixing to "%s"'%(version, GUSIVERSION)) | |
| 212 flags = 0 | |
| 204 delay = (not not (flags & GUSIFLAGS_DELAY)) | 213 delay = (not not (flags & GUSIFLAGS_DELAY)) |
| 205 return creator, type, delay, opr | 214 return creator, type, delay, opr |
| 206 | 215 |
| 207 def setgusioptions(opr, creator, type, delay): | 216 def setgusioptions(opr, creator, type, delay): |
| 208 data = opr.data | 217 data = opr.data |
| 209 flags = ord(data[GUSIPOS_FLAGS]) | 218 flags = ord(data[GUSIPOS_FLAGS]) |
| 219 version = data[GUSIPOS_VERSION:GUSIPOS_VERSION+4] | |
| 220 if version <> GUSIVERSION: | |
| 221 flags = 0x88 | |
| 222 version = GUSIVERSION | |
| 210 if delay: | 223 if delay: |
| 211 flags = flags | GUSIFLAGS_DELAY | 224 flags = flags | GUSIFLAGS_DELAY |
| 212 else: | 225 else: |
| 213 flags = flags & ~GUSIFLAGS_DELAY | 226 flags = flags & ~GUSIFLAGS_DELAY |
| 214 data = type + creator + data[GUSIPOS_SKIP] + chr(flags) + data[GUSIPOS_FLAGS+1:] | 227 data = type + creator + data[GUSIPOS_SKIP] + chr(flags) + GUSIVERSION + data[GUSIPOS_VERSION+4:] |
| 215 return data | 228 return data |
| 216 | 229 |
| 217 def openpreffile(rw): | 230 def openpreffile(rw): |
| 218 # Find the preferences folder and our prefs file, create if needed. | 231 # Find the preferences folder and our prefs file, create if needed. |
| 219 vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0) | 232 vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0) |
| 220 preff_fss = macfs.FSSpec((vrefnum, dirid, 'Python Preferences')) | 233 try: |
| 234 pnhandle = GetNamedResource('STR ', PREFNAME_NAME) | |
| 235 except Res.Error: | |
| 236 message("No %s resource (old Python?)"%PREFNAME_NAME) | |
| 237 sys.exit(1) | |
| 238 prefname = pnhandle.data[1:] | |
| 239 preff_fss = macfs.FSSpec((vrefnum, dirid, prefname)) | |
| 221 try: | 240 try: |
| 222 preff_handle = FSpOpenResFile(preff_fss, rw) | 241 preff_handle = FSpOpenResFile(preff_fss, rw) |
| 223 except Res.Error: | 242 except Res.Error: |
| 224 # Create it | 243 # Create it |
| 225 message('No preferences file, creating one...') | 244 message('No preferences file, creating one...') |
