[Python-checkins] python/dist/src/Mac/scripts gensuitemodule.py,1.30,1.31

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Fri, 21 Mar 2003 08:07:42 -0800


Update of /cvsroot/python/python/dist/src/Mac/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv27648

Modified Files:
	gensuitemodule.py 
Log Message:
Allow gensuitemodule to be run non-interactively, from the OSX command
line. 90% of the work is done, missing enums still cause a dialog to appear.


Index: gensuitemodule.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/scripts/gensuitemodule.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** gensuitemodule.py	21 Mar 2003 12:04:19 -0000	1.30
--- gensuitemodule.py	21 Mar 2003 16:07:39 -0000	1.31
***************
*** 21,24 ****
--- 21,25 ----
  from Carbon.Res import *
  import MacOS
+ import getopt
  
  _MAC_LIB_FOLDER=os.path.dirname(aetools.__file__)
***************
*** 26,33 ****
  DEFAULT_USER_PACKAGEFOLDER=distutils.sysconfig.get_python_lib()
  
  def main():
  	if len(sys.argv) > 1:
! 		for filename in sys.argv[1:]:
! 			processfile(filename)
  	else:
  		# The dialogOptionFlags below allows selection of .app bundles.
--- 27,74 ----
  DEFAULT_USER_PACKAGEFOLDER=distutils.sysconfig.get_python_lib()
  
+ def usage():
+ 	sys.stderr.write("Usage: %s [opts] application-or-resource-file\n" % sys.argv[0])
+ 	sys.stderr.write("""Options:
+ --output pkgdir  Pathname of the output package (short: -o)  
+ --resource       Parse resource file in stead of launching application (-r)
+ --base package   Use another base package in stead of default StdSuites (-b)
+ --edit old=new   Edit suite names, use empty new to skip a suite (-e)
+ """)
+ 	sys.exit(1)
+ 
  def main():
  	if len(sys.argv) > 1:
! 		SHORTOPTS = "rb:o:e:"
! 		LONGOPTS = ("resource", "base=", "output=", "edit=")
! 		try:
! 			opts, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS)
! 		except getopt.GetoptError:
! 			usage()
! 		
! 		process_func = processfile
! 		basepkgname = 'StdSuites'
! 		output = None
! 		edit_modnames = []
! 		
! 		for o, a in opts:
! 			if o in ('-r', '--resource'):
! 				process_func = processfile_fromresource
! 			if o in ('-b', '--base'):
! 				basepkgname = a
! 			if o in ('-o', '--output'):
! 				output = a
! 			if o in ('-e', '--edit'):
! 				split = a.split('=')
! 				if len(split) != 2:
! 					usage()
! 				edit_modnames.append(split)
! 					
! 		if output and len(args) > 1:
! 			sys.stderr.write("%s: cannot specify --output with multiple inputs\n" % sys.argv[0])
! 			sys.exit(1)
! 			
! 		for filename in args:
! 			process_func(filename, output=output, basepkgname=basepkgname, 
! 				edit_modnames=edit_modnames)
  	else:
  		# The dialogOptionFlags below allows selection of .app bundles.
***************
*** 44,48 ****
  			processfile_fromresource(filename)
  
! def processfile_fromresource(fullname):
  	"""Process all resources in a single file"""
  	cur = CurResFile()
--- 85,89 ----
  			processfile_fromresource(filename)
  
! def processfile_fromresource(fullname, output=None, basepkgname=None, edit_modnames=None):
  	"""Process all resources in a single file"""
  	cur = CurResFile()
***************
*** 71,77 ****
  	# switch back (needed for dialogs in Python)
  	UseResFile(cur)
! 	compileaetelist(aetelist, fullname)
  
! def processfile(fullname):
  	"""Ask an application for its terminology and process that"""
  	aedescobj, launched = OSATerminology.GetSysTerminology(fullname)
--- 112,119 ----
  	# switch back (needed for dialogs in Python)
  	UseResFile(cur)
! 	compileaetelist(aetelist, fullname, output=output, 
! 		basepkgname=basepkgname, edit_modnames=edit_modnames)
  
! def processfile(fullname, output=None, basepkgname=None, edit_modnames=None):
  	"""Ask an application for its terminology and process that"""
  	aedescobj, launched = OSATerminology.GetSysTerminology(fullname)
***************
*** 87,95 ****
  	aedata = raw[0]
  	aete = decode(aedata.data)
! 	compileaete(aete, None, fullname)
  
! def compileaetelist(aetelist, fullname):
  	for aete, resinfo in aetelist:
! 		compileaete(aete, resinfo, fullname)
  		
  def decode(data):
--- 129,138 ----
  	aedata = raw[0]
  	aete = decode(aedata.data)
! 	compileaete(aete, None, fullname, output=output, basepkgname=basepkgname)
  
! def compileaetelist(aetelist, fullname, output=None, basepkgname=None, edit_modnames=None):
  	for aete, resinfo in aetelist:
! 		compileaete(aete, resinfo, fullname, output=output, 
! 			basepkgname=basepkgname, edit_modnames=edit_modnames)
  		
  def decode(data):
***************
*** 256,260 ****
  	]
  
! def compileaete(aete, resinfo, fname):
  	"""Generate code for a full aete resource. fname passed for doc purposes"""
  	[version, language, script, suites] = aete
--- 299,303 ----
  	]
  
! def compileaete(aete, resinfo, fname, output=None, basepkgname=None, edit_modnames=None):
  	"""Generate code for a full aete resource. fname passed for doc purposes"""
  	[version, language, script, suites] = aete
***************
*** 268,281 ****
  	if len(packagename) > 27:
  		packagename = packagename[:27]
! 	pathname = EasyDialogs.AskFolder(message='Create and select package folder for %s'%packagename,
! 		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_STANDARD_PACKAGEFOLDER)
  	if basepkgname:
  		dirname, basepkgname = os.path.split(os.path.normpath(basepkgname))
! 		if not dirname in sys.path:
  			sys.path.insert(0, dirname)
  		basepackage = __import__(basepkgname)
--- 311,331 ----
  	if len(packagename) > 27:
  		packagename = packagename[:27]
! 	if output:
! 		# XXXX Put this in site-packages if it isn't a full pathname?
! 		if not os.path.exists(output):
! 			os.mkdir(output)
! 		pathname = output
! 	else:
! 		pathname = EasyDialogs.AskFolder(message='Create and select package folder for %s'%packagename,
! 			defaultLocation=DEFAULT_USER_PACKAGEFOLDER)
  	if not pathname:
  		return
  	packagename = os.path.split(os.path.normpath(pathname))[1]
! 	if not basepkgname:
! 		basepkgname = EasyDialogs.AskFolder(message='Package folder for base suite (usually StdSuites)',
! 			defaultLocation=DEFAULT_STANDARD_PACKAGEFOLDER)
  	if basepkgname:
  		dirname, basepkgname = os.path.split(os.path.normpath(basepkgname))
! 		if dirname and not dirname in sys.path:
  			sys.path.insert(0, dirname)
  		basepackage = __import__(basepkgname)
***************
*** 286,290 ****
  	allsuites = []
  	for suite in suites:
! 		code, suite, pathname, modname, precompinfo = precompilesuite(suite, basepackage)
  		if not code:
  			continue
--- 336,341 ----
  	allsuites = []
  	for suite in suites:
! 		code, suite, pathname, modname, precompinfo = precompilesuite(suite, basepackage, 
! 				output=output, edit_modnames=edit_modnames)
  		if not code:
  			continue
***************
*** 295,302 ****
  	for suiteinfo in allsuites:
  		compilesuite(suiteinfo, major, minor, language, script, fname, basepackage, allprecompinfo)
! 	initfilename = EasyDialogs.AskFileForSave(message='Package module', 
! 		savedFileName='__init__.py')
! 	if not initfilename:
! 		return
  	fp = open(initfilename, 'w')
  	MacOS.SetCreatorAndType(initfilename, 'Pyth', 'TEXT')
--- 346,350 ----
  	for suiteinfo in allsuites:
  		compilesuite(suiteinfo, major, minor, language, script, fname, basepackage, allprecompinfo)
! 	initfilename = os.path.join(output, '__init__.py')
  	fp = open(initfilename, 'w')
  	MacOS.SetCreatorAndType(initfilename, 'Pyth', 'TEXT')
***************
*** 359,363 ****
  	fp.close()
  	
! def precompilesuite(suite, basepackage=None):
  	"""Parse a single suite without generating the output. This step is needed
  	so we can resolve recursive references by suites to enums/comps/etc declared
--- 407,411 ----
  	fp.close()
  	
! def precompilesuite(suite, basepackage=None, edit_modnames=None, output=None):
  	"""Parse a single suite without generating the output. This step is needed
  	so we can resolve recursive references by suites to enums/comps/etc declared
***************
*** 368,373 ****
  	if len(modname) > 28:
  		modname = modname[:27]
! 	pathname = EasyDialogs.AskFileForSave(message='Python output file',
! 		savedFileName=modname+'.py')
  	if not pathname:
  		return None, None, None, None, None
--- 416,430 ----
  	if len(modname) > 28:
  		modname = modname[:27]
! 	if edit_modnames is None:
! 		pathname = EasyDialogs.AskFileForSave(message='Python output file',
! 			savedFileName=modname+'.py')
! 	else:
! 		for old, new in edit_modnames:
! 			if old == modname:
! 				modname = new
! 		if modname:
! 			pathname = os.path.join(output, modname + '.py')
! 		else:
! 			pathname = None
  	if not pathname:
  		return None, None, None, None, None