[Python-checkins] python/dist/src/Mac/scripts gensuitemodule.py,1.37,1.38
jackjansen@users.sourceforge.net
jackjansen@users.sourceforge.net
Sat, 29 Mar 2003 14:54:03 -0800
Update of /cvsroot/python/python/dist/src/Mac/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv5854
Modified Files:
gensuitemodule.py
Log Message:
- Added an is_scriptable method to test applications for having
a scripting dictionary. Made up by me, not guaranteed to be correct
(and, indeed, Internet Explorer does not seem to play by the book).
- Added the interactive main program as a separate routine, so it
can be called from the IDE later. Also made it less interactive by
default: only the input app and output package folder are asked for.
Index: gensuitemodule.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/scripts/gensuitemodule.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** gensuitemodule.py 29 Mar 2003 00:08:24 -0000 1.37
--- gensuitemodule.py 29 Mar 2003 22:54:00 -0000 1.38
***************
*** 20,25 ****
--- 20,27 ----
import OSATerminology
from Carbon.Res import *
+ import Carbon.Folder
import MacOS
import getopt
+ import plistlib
_MAC_LIB_FOLDER=os.path.dirname(aetools.__file__)
***************
*** 80,99 ****
edit_modnames=edit_modnames, creatorsignature=creatorsignature)
else:
! # The dialogOptionFlags below allows selection of .app bundles.
! filename = EasyDialogs.AskFileForOpen(
! message='Select scriptable application',
! dialogOptionFlags=0x1056)
! if not filename:
! sys.exit(0)
! try:
! processfile(filename)
! except MacOS.Error, arg:
! print "Error getting terminology:", arg
! print "Retry, manually parsing resources"
! processfile_fromresource(filename)
def processfile_fromresource(fullname, output=None, basepkgname=None,
edit_modnames=None, creatorsignature=None):
"""Process all resources in a single file"""
cur = CurResFile()
print "Processing", fullname
--- 82,140 ----
edit_modnames=edit_modnames, creatorsignature=creatorsignature)
else:
! main_interactive()
!
! def main_interactive(interact=0, basepkgname='StdSuites'):
! if interact:
! # Ask for save-filename for each module
! edit_modnames = None
! else:
! # Use default filenames for each module
! edit_modnames = []
! appsfolder = Carbon.Folder.FSFindFolder(-32765, 'apps', 0)
! filename = EasyDialogs.AskFileForOpen(
! message='Select scriptable application',
! dialogOptionFlags=0x1056, # allow selection of .app bundles
! defaultLocation=appsfolder)
! if not filename:
! return
! if not is_scriptable(filename):
! if EasyDialogs.AskYesNoCancel(
! "Warning: application does not seem scriptable",
! yes="Continue", default=2, no="") <= 0:
! return
! try:
! processfile(filename, edit_modnames=edit_modnames, basepkgname=basepkgname)
! except MacOS.Error, arg:
! print "Error getting terminology:", arg
! print "Retry, manually parsing resources"
! processfile_fromresource(filename, edit_modnames=edit_modnames,
! basepkgname=basepkgname)
!
! def is_scriptable(application):
! """Return true if the application is scriptable"""
! if os.path.isdir(application):
! plistfile = os.path.join(application, 'Contents', 'Info.plist')
! if not os.path.exists(plistfile):
! return False
! plist = plistlib.Plist.fromFile(plistfile)
! return plist.get('NSAppleScriptEnabled', False)
! # If it is a file test for an aete/aeut resource.
! currf = CurResFile()
! try:
! refno = macresource.open_pathname(application)
! except MacOS.Error:
! return False
! UseResFile(refno)
! n_terminology = Count1Resources('aete') + Count1Resources('aeut') + \
! Count1Resources('scsz') + Count1Resources('osiz')
! CloseResFile(refno)
! UseResFile(currf)
! return n_terminology > 0
def processfile_fromresource(fullname, output=None, basepkgname=None,
edit_modnames=None, creatorsignature=None):
"""Process all resources in a single file"""
+ if not is_scriptable(fullname):
+ print "Warning: app does not seem scriptable: %s" % fullname
cur = CurResFile()
print "Processing", fullname
***************
*** 128,131 ****
--- 169,174 ----
edit_modnames=None, creatorsignature=None):
"""Ask an application for its terminology and process that"""
+ if not is_scriptable(fullname):
+ print "Warning: app does not seem scriptable: %s" % fullname
print "\nASKING FOR aete DICTIONARY IN", `fullname`
try: