diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2003-03-06 23:04:38 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2003-03-06 23:04:38 (GMT) |
commit | fa1bf1c518528ae8ec9b24ce452edc930ec80a7d (patch) | |
tree | d1e3b1f0743e413b0de14cfc0cd83a4f0697972b /Mac/scripts | |
parent | 7a251db9e6c9962f08c99e04c018b659a18a51fb (diff) | |
download | cpython-fa1bf1c518528ae8ec9b24ce452edc930ec80a7d.zip cpython-fa1bf1c518528ae8ec9b24ce452edc930ec80a7d.tar.gz cpython-fa1bf1c518528ae8ec9b24ce452edc930ec80a7d.tar.bz2 |
First try to use the OSATerminology module to get the terminology
resources before reverting to manually reading the resources.
Unfortunately there is still a bug in here somewhere: it doesn't work
for all applications.
Diffstat (limited to 'Mac/scripts')
-rw-r--r-- | Mac/scripts/gensuitemodule.py | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/Mac/scripts/gensuitemodule.py b/Mac/scripts/gensuitemodule.py index f72a50b..1cd2ef6 100644 --- a/Mac/scripts/gensuitemodule.py +++ b/Mac/scripts/gensuitemodule.py @@ -15,23 +15,35 @@ import types import StringIO import keyword import macresource -from aetools import unpack - +import aetools +import distutils.sysconfig +import OSATerminology from Carbon.Res import * +import MacOS -DEFAULT_PACKAGEFOLDER=os.path.join(sys.prefix, 'Lib', 'plat-mac', 'lib-scriptpackages') +_MAC_LIB_FOLDER=os.path.dirname(aetools.__file__) +DEFAULT_STANDARD_PACKAGEFOLDER=os.path.join(_MAC_LIB_FOLDER, 'lib-scriptpackages') +DEFAULT_USER_PACKAGEFOLDER=distutils.sysconfig.get_python_lib() def main(): if len(sys.argv) > 1: for filename in sys.argv[1:]: processfile(filename) else: - filename = EasyDialogs.AskFileForOpen(message='Select file with aeut/aete resource:') + # The dialogOptionFlags below allows selection of .app bundles. + filename = EasyDialogs.AskFileForOpen( + message='Select scriptable application', + dialogOptionFlags=0x1056) if not filename: sys.exit(0) - processfile(filename) + try: + processfile(filename) + except MacOS.Error, arg: + print "Error getting terminology:", arg + print "Retry, manually parsing resources" + processfile_fromresource(filename) -def processfile(fullname): +def processfile_fromresource(fullname): """Process all resources in a single file""" cur = CurResFile() print "Processing", fullname @@ -60,6 +72,22 @@ def processfile(fullname): UseResFile(cur) compileaetelist(aetelist, fullname) +def processfile(fullname): + """Ask an application for its terminology and process that""" + aedescobj, launched = OSATerminology.GetSysTerminology(fullname) + if launched: + print "Launched", fullname + raw = aetools.unpack(aedescobj) + if not raw: + print 'Unpack returned empty value:', raw + return + if not raw[0].data: + print 'Unpack returned value without data:', raw + return + aedata = raw[0] + aete = decode(aedata.data) + compileaete(aete, None, fullname) + def compileaetelist(aetelist, fullname): for aete, resinfo in aetelist: compileaete(aete, resinfo, fullname) @@ -240,12 +268,12 @@ def compileaete(aete, resinfo, fname): if len(packagename) > 27: packagename = packagename[:27] pathname = EasyDialogs.AskFolder(message='Create and select package folder for %s'%packagename, - defaultLocation=DEFAULT_PACKAGEFOLDER) + defaultLocation=DEFAULT_USER_PACKAGEFOLDER) if not pathname: return packagename = os.path.split(os.path.normpath(pathname))[1] basepkgname = EasyDialogs.AskFolder(message='Package folder for base suite (usually StdSuites)', - defaultLocation=DEFAULT_PACKAGEFOLDER) + defaultLocation=DEFAULT_STANDARD_PACKAGEFOLDER) if basepkgname: dirname, basepkgname = os.path.split(os.path.normpath(basepkgname)) if not dirname in sys.path: @@ -907,4 +935,3 @@ def identify(str): if __name__ == '__main__': main() sys.exit(1) -print identify('for') |