diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-07-18 06:16:08 (GMT) |
commit | 182b5aca27d376b08a2904bed42b751496f932f3 (patch) | |
tree | df13115820dbc879c0fe2eae488c9f8c0215a7da /Mac/scripts | |
parent | e6ddc8b20b493fef2e7cffb2e1351fe1d238857e (diff) | |
download | cpython-182b5aca27d376b08a2904bed42b751496f932f3.zip cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.gz cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.bz2 |
Whitespace normalization, via reindent.py.
Diffstat (limited to 'Mac/scripts')
-rw-r--r-- | Mac/scripts/BuildApplet.py | 210 | ||||
-rw-r--r-- | Mac/scripts/bgenall.py | 94 | ||||
-rw-r--r-- | Mac/scripts/buildpkg.py | 78 | ||||
-rw-r--r-- | Mac/scripts/cachersrc.py | 59 | ||||
-rw-r--r-- | Mac/scripts/genallsuites.py | 45 | ||||
-rw-r--r-- | Mac/scripts/mkestrres.py | 269 | ||||
-rw-r--r-- | Mac/scripts/zappycfiles.py | 45 |
7 files changed, 398 insertions, 402 deletions
diff --git a/Mac/scripts/BuildApplet.py b/Mac/scripts/BuildApplet.py index e954854..cb2aed8 100644 --- a/Mac/scripts/BuildApplet.py +++ b/Mac/scripts/BuildApplet.py @@ -17,117 +17,117 @@ import buildtools import getopt def main(): - try: - buildapplet() - except buildtools.BuildError, detail: - EasyDialogs.Message(detail) + try: + buildapplet() + except buildtools.BuildError, detail: + EasyDialogs.Message(detail) def buildapplet(): - buildtools.DEBUG=1 - - # Find the template - # (there's no point in proceeding if we can't find it) - - template = buildtools.findtemplate() - - # Ask for source text if not specified in sys.argv[1:] - - if not sys.argv[1:]: - filename = EasyDialogs.AskFileForOpen(message='Select Python source or applet:', - typeList=('TEXT', 'APPL')) - if not filename: - return - tp, tf = os.path.split(filename) - if tf[-3:] == '.py': - tf = tf[:-3] - else: - tf = tf + '.applet' - dstfilename = EasyDialogs.AskFileForSave(message='Save application as:', - savedFileName=tf) - if not dstfilename: return - cr, tp = MacOS.GetCreatorAndType(filename) - if tp == 'APPL': - buildtools.update(template, filename, dstfilename) - else: - buildtools.process(template, filename, dstfilename, 1) - else: - - SHORTOPTS = "o:r:ne:v?P" - LONGOPTS=("output=", "resource=", "noargv", "extra=", "verbose", "help", "python=") - try: - options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS) - except getopt.error: - usage() - if options and len(args) > 1: - sys.stderr.write("Cannot use options when specifying multiple input files") - sys.exit(1) - dstfilename = None - rsrcfilename = None - raw = 0 - extras = [] - verbose = None - for opt, arg in options: - if opt in ('-o', '--output'): - dstfilename = arg - elif opt in ('-r', '--resource'): - rsrcfilename = arg - elif opt in ('-n', '--noargv'): - raw = 1 - elif opt in ('-e', '--extra'): - if ':' in arg: - arg = arg.split(':') - extras.append(arg) - elif opt in ('-P', '--python'): - # This is a very dirty trick. We set sys.executable - # so that bundlebuilder will use this in the #! line - # for the applet bootstrap. - sys.executable = arg - elif opt in ('-v', '--verbose'): - verbose = Verbose() - elif opt in ('-?', '--help'): - usage() - # On OS9 always be verbose - if sys.platform == 'mac' and not verbose: - verbose = 'default' - # Loop over all files to be processed - for filename in args: - cr, tp = MacOS.GetCreatorAndType(filename) - if tp == 'APPL': - buildtools.update(template, filename, dstfilename) - else: - buildtools.process(template, filename, dstfilename, 1, - rsrcname=rsrcfilename, others=extras, raw=raw, progress=verbose) + buildtools.DEBUG=1 + + # Find the template + # (there's no point in proceeding if we can't find it) + + template = buildtools.findtemplate() + + # Ask for source text if not specified in sys.argv[1:] + + if not sys.argv[1:]: + filename = EasyDialogs.AskFileForOpen(message='Select Python source or applet:', + typeList=('TEXT', 'APPL')) + if not filename: + return + tp, tf = os.path.split(filename) + if tf[-3:] == '.py': + tf = tf[:-3] + else: + tf = tf + '.applet' + dstfilename = EasyDialogs.AskFileForSave(message='Save application as:', + savedFileName=tf) + if not dstfilename: return + cr, tp = MacOS.GetCreatorAndType(filename) + if tp == 'APPL': + buildtools.update(template, filename, dstfilename) + else: + buildtools.process(template, filename, dstfilename, 1) + else: + + SHORTOPTS = "o:r:ne:v?P" + LONGOPTS=("output=", "resource=", "noargv", "extra=", "verbose", "help", "python=") + try: + options, args = getopt.getopt(sys.argv[1:], SHORTOPTS, LONGOPTS) + except getopt.error: + usage() + if options and len(args) > 1: + sys.stderr.write("Cannot use options when specifying multiple input files") + sys.exit(1) + dstfilename = None + rsrcfilename = None + raw = 0 + extras = [] + verbose = None + for opt, arg in options: + if opt in ('-o', '--output'): + dstfilename = arg + elif opt in ('-r', '--resource'): + rsrcfilename = arg + elif opt in ('-n', '--noargv'): + raw = 1 + elif opt in ('-e', '--extra'): + if ':' in arg: + arg = arg.split(':') + extras.append(arg) + elif opt in ('-P', '--python'): + # This is a very dirty trick. We set sys.executable + # so that bundlebuilder will use this in the #! line + # for the applet bootstrap. + sys.executable = arg + elif opt in ('-v', '--verbose'): + verbose = Verbose() + elif opt in ('-?', '--help'): + usage() + # On OS9 always be verbose + if sys.platform == 'mac' and not verbose: + verbose = 'default' + # Loop over all files to be processed + for filename in args: + cr, tp = MacOS.GetCreatorAndType(filename) + if tp == 'APPL': + buildtools.update(template, filename, dstfilename) + else: + buildtools.process(template, filename, dstfilename, 1, + rsrcname=rsrcfilename, others=extras, raw=raw, progress=verbose) def usage(): - print "BuildApplet creates an application from a Python source file" - print "Usage:" - print " BuildApplet interactive, single file, no options" - print " BuildApplet src1.py src2.py ... non-interactive multiple file" - print " BuildApplet [options] src.py non-interactive single file" - print "Options:" - print " --output o Output file; default based on source filename, short -o" - print " --resource r Resource file; default based on source filename, short -r" - print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only" - print " --extra src[:dst] Extra file to put in .app bundle, short -e, OSX only" - print " --verbose Verbose, short -v" - print " --help This message, short -?" - sys.exit(1) + print "BuildApplet creates an application from a Python source file" + print "Usage:" + print " BuildApplet interactive, single file, no options" + print " BuildApplet src1.py src2.py ... non-interactive multiple file" + print " BuildApplet [options] src.py non-interactive single file" + print "Options:" + print " --output o Output file; default based on source filename, short -o" + print " --resource r Resource file; default based on source filename, short -r" + print " --noargv Build applet without drag-and-drop sys.argv emulation, short -n, OSX only" + print " --extra src[:dst] Extra file to put in .app bundle, short -e, OSX only" + print " --verbose Verbose, short -v" + print " --help This message, short -?" + sys.exit(1) class Verbose: - """This class mimics EasyDialogs.ProgressBar but prints to stderr""" - def __init__(self, *args): - if args and args[0]: - self.label(args[0]) - - def set(self, *args): - pass - - def inc(self, *args): - pass - - def label(self, str): - sys.stderr.write(str+'\n') + """This class mimics EasyDialogs.ProgressBar but prints to stderr""" + def __init__(self, *args): + if args and args[0]: + self.label(args[0]) + + def set(self, *args): + pass + + def inc(self, *args): + pass + + def label(self, str): + sys.stderr.write(str+'\n') if __name__ == '__main__': - main() + main() diff --git a/Mac/scripts/bgenall.py b/Mac/scripts/bgenall.py index 6490265..1fe5f34 100644 --- a/Mac/scripts/bgenall.py +++ b/Mac/scripts/bgenall.py @@ -5,52 +5,52 @@ import os import string def bgenone(dirname, shortname): - os.chdir(dirname) - print '%s:'%shortname - # Sigh, we don't want to lose CVS history, so two - # modules have funny names: - if shortname == 'carbonevt': - modulename = 'CarbonEvtscan' - elif shortname == 'ibcarbon': - modulename = 'IBCarbonscan' - else: - modulename = shortname + 'scan' - try: - m = __import__(modulename) - except: - print "Error:", shortname, sys.exc_info()[1] - return 0 - try: - m.main() - except: - print "Error:", shortname, sys.exc_info()[1] - return 0 - return 1 - + os.chdir(dirname) + print '%s:'%shortname + # Sigh, we don't want to lose CVS history, so two + # modules have funny names: + if shortname == 'carbonevt': + modulename = 'CarbonEvtscan' + elif shortname == 'ibcarbon': + modulename = 'IBCarbonscan' + else: + modulename = shortname + 'scan' + try: + m = __import__(modulename) + except: + print "Error:", shortname, sys.exc_info()[1] + return 0 + try: + m.main() + except: + print "Error:", shortname, sys.exc_info()[1] + return 0 + return 1 + def main(): - success = [] - failure = [] - sys.path.insert(0, os.curdir) - if len(sys.argv) > 1: - srcdir = sys.argv[1] - else: - srcdir = os.path.join(os.path.join(sys.prefix, 'Mac'), 'Modules') - srcdir = os.path.abspath(srcdir) - contents = os.listdir(srcdir) - for name in contents: - moduledir = os.path.join(srcdir, name) - scanmodule = os.path.join(moduledir, name +'scan.py') - if os.path.exists(scanmodule): - if bgenone(moduledir, name): - success.append(name) - else: - failure.append(name) - print 'Done:', string.join(success, ' ') - if failure: - print 'Failed:', string.join(failure, ' ') - return 0 - return 1 - + success = [] + failure = [] + sys.path.insert(0, os.curdir) + if len(sys.argv) > 1: + srcdir = sys.argv[1] + else: + srcdir = os.path.join(os.path.join(sys.prefix, 'Mac'), 'Modules') + srcdir = os.path.abspath(srcdir) + contents = os.listdir(srcdir) + for name in contents: + moduledir = os.path.join(srcdir, name) + scanmodule = os.path.join(moduledir, name +'scan.py') + if os.path.exists(scanmodule): + if bgenone(moduledir, name): + success.append(name) + else: + failure.append(name) + print 'Done:', string.join(success, ' ') + if failure: + print 'Failed:', string.join(failure, ' ') + return 0 + return 1 + if __name__ == '__main__': - rv = main() - sys.exit(not rv)
\ No newline at end of file + rv = main() + sys.exit(not rv) diff --git a/Mac/scripts/buildpkg.py b/Mac/scripts/buildpkg.py index a9c70c1..7f635a0 100644 --- a/Mac/scripts/buildpkg.py +++ b/Mac/scripts/buildpkg.py @@ -3,34 +3,34 @@ """buildpkg.py -- Build OS X packages for Apple's Installer.app. This is an experimental command-line tool for building packages to be -installed with the Mac OS X Installer.app application. +installed with the Mac OS X Installer.app application. -It is much inspired by Apple's GUI tool called PackageMaker.app, that -seems to be part of the OS X developer tools installed in the folder -/Developer/Applications. But apparently there are other free tools to -do the same thing which are also named PackageMaker like Brian Hill's -one: +It is much inspired by Apple's GUI tool called PackageMaker.app, that +seems to be part of the OS X developer tools installed in the folder +/Developer/Applications. But apparently there are other free tools to +do the same thing which are also named PackageMaker like Brian Hill's +one: http://personalpages.tds.net/~brian_hill/packagemaker.html -Beware of the multi-package features of Installer.app (which are not -yet supported here) that can potentially screw-up your installation +Beware of the multi-package features of Installer.app (which are not +yet supported here) that can potentially screw-up your installation and are discussed in these articles on Stepwise: http://www.stepwise.com/Articles/Technical/Packages/InstallerWoes.html http://www.stepwise.com/Articles/Technical/Packages/InstallerOnX.html -Beside using the PackageMaker class directly, by importing it inside +Beside using the PackageMaker class directly, by importing it inside another module, say, there are additional ways of using this module: -the top-level buildPackage() function provides a shortcut to the same +the top-level buildPackage() function provides a shortcut to the same feature and is also called when using this module from the command- line. **************************************************************** - NOTE: For now you should be able to run this even on a non-OS X + NOTE: For now you should be able to run this even on a non-OS X system and get something similar to a package, but without - the real archive (needs pax) and bom files (needs mkbom) - inside! This is only for providing a chance for testing to + the real archive (needs pax) and bom files (needs mkbom) + inside! This is only for providing a chance for testing to folks without OS X. **************************************************************** @@ -39,7 +39,7 @@ TODO: - handle multi-volume packages (?) - integrate into distutils (?) -Dinu C. Gherman, +Dinu C. Gherman, gherman@europemail.com November 2001 @@ -120,14 +120,14 @@ class PackageMaker: """A class to generate packages for Mac OS X. This is intended to create OS X packages (with extension .pkg) - containing archives of arbitrary files that the Installer.app + containing archives of arbitrary files that the Installer.app will be able to handle. - As of now, PackageMaker instances need to be created with the - title, version and description of the package to be built. - The package is built after calling the instance method - build(root, **options). It has the same name as the constructor's - title argument plus a '.pkg' extension and is located in the same + As of now, PackageMaker instances need to be created with the + title, version and description of the package to be built. + The package is built after calling the instance method + build(root, **options). It has the same name as the constructor's + title argument plus a '.pkg' extension and is located in the same parent folder that contains the root folder. E.g. this will create a package folder /my/space/distutils.pkg/: @@ -165,7 +165,7 @@ class PackageMaker: info = {"Title": title, "Version": version, "Description": desc} self.packageInfo = copy.deepcopy(self.packageInfoDefaults) self.packageInfo.update(info) - + # variables set later self.packageRootFolder = None self.packageResourceFolder = None @@ -176,8 +176,8 @@ class PackageMaker: def build(self, root, resources=None, **options): """Create a package for some given root folder. - With no 'resources' argument set it is assumed to be the same - as the root directory. Option items replace the default ones + With no 'resources' argument set it is assumed to be the same + as the root directory. Option items replace the default ones in the package info. """ @@ -195,12 +195,12 @@ class PackageMaker: self.packageInfo[k] = v elif not k in ["OutputDir"]: raise Error, "Unknown package option: %s" % k - + # Check where we should leave the output. Default is current directory outputdir = options.get("OutputDir", os.getcwd()) packageName = self.packageInfo["Title"] self.PackageRootFolder = os.path.join(outputdir, packageName + ".pkg") - + # do what needs to be done self._makeFolders() self._addInfo() @@ -215,7 +215,7 @@ class PackageMaker: "Create package folder structure." # Not sure if the package name should contain the version or not... - # packageName = "%s-%s" % (self.packageInfo["Title"], + # packageName = "%s-%s" % (self.packageInfo["Title"], # self.packageInfo["Version"]) # ?? contFolder = join(self.PackageRootFolder, "Contents") @@ -267,7 +267,7 @@ class PackageMaker: self.archPath = join(self.packageResourceFolder, base) cmd = "pax -w -f %s %s" % (self.archPath, ".") res = os.system(cmd) - + # compress archive cmd = "gzip %s" % self.archPath res = os.system(cmd) @@ -277,8 +277,8 @@ class PackageMaker: def _addResources(self): "Add Welcome/ReadMe/License files, .lproj folders and scripts." - # Currently we just copy everything that matches the allowed - # filenames. So, it's left to Installer.app to deal with the + # Currently we just copy everything that matches the allowed + # filenames. So, it's left to Installer.app to deal with the # same file available in multiple formats... if not self.resourceFolder: @@ -337,9 +337,9 @@ class PackageMaker: def _addSizes(self): "Write .sizes file with info about number and size of files." - # Not sure if this is correct, but 'installedSize' and - # 'zippedSize' are now in Bytes. Maybe blocks are needed? - # Well, Installer.app doesn't seem to care anyway, saying + # Not sure if this is correct, but 'installedSize' and + # 'zippedSize' are now in Bytes. Maybe blocks are needed? + # Well, Installer.app doesn't seem to care anyway, saying # the installation needs 100+ MB... numFiles = 0 @@ -353,7 +353,7 @@ class PackageMaker: try: zippedSize = os.stat(self.archPath+ ".gz")[6] - except OSError: # ignore error + except OSError: # ignore error pass base = self.packageInfo["Title"] + ".sizes" f = open(join(self.packageResourceFolder, base), "w") @@ -370,7 +370,7 @@ class PackageMaker: def buildPackage(*args, **options): "A Shortcut function for building a package." - + o = options title, version, desc = o["Title"], o["Version"], o["Description"] pm = PackageMaker(title, version, desc) @@ -391,9 +391,9 @@ def test0(): def test1(): "Test for the reportlab distribution with modified options." - pm = PackageMaker("reportlab", "1.10", + pm = PackageMaker("reportlab", "1.10", "ReportLab's Open Source PDF toolkit.") - pm.build(root="/Users/dinu/Desktop/reportlab", + pm.build(root="/Users/dinu/Desktop/reportlab", DefaultLocation="/Applications/ReportLab", Relocatable="YES") @@ -401,9 +401,9 @@ def test2(): "Shortcut test for the reportlab distribution with modified options." buildPackage( - "/Users/dinu/Desktop/reportlab", - Title="reportlab", - Version="1.10", + "/Users/dinu/Desktop/reportlab", + Title="reportlab", + Version="1.10", Description="ReportLab's Open Source PDF toolkit.", DefaultLocation="/Applications/ReportLab", Relocatable="YES") diff --git a/Mac/scripts/cachersrc.py b/Mac/scripts/cachersrc.py index e6524c9..e2eed8b 100644 --- a/Mac/scripts/cachersrc.py +++ b/Mac/scripts/cachersrc.py @@ -10,36 +10,35 @@ import sys import getopt class NoArgsError(Exception): - pass - + pass + def handler((verbose, force), dirname, fnames): - for fn in fnames: - if fn[-5:] == '.rsrc' and fn[-13:] != '.rsrc.df.rsrc': - if force: - try: - os.unlink(os.path.join(dirname, fn + '.df.rsrc')) - except IOError: - pass - macresource.open_pathname(os.path.join(dirname, fn), verbose=verbose) - + for fn in fnames: + if fn[-5:] == '.rsrc' and fn[-13:] != '.rsrc.df.rsrc': + if force: + try: + os.unlink(os.path.join(dirname, fn + '.df.rsrc')) + except IOError: + pass + macresource.open_pathname(os.path.join(dirname, fn), verbose=verbose) + def main(): - try: - opts, args = getopt.getopt(sys.argv[1:], 'vf') - if not args: - raise NoArgsError - except (getopt.GetoptError, NoArgsError): - sys.stderr.write('Usage: cachersrc.py dirname ...\n') - sys.exit(1) - verbose = 0 - force = 0 - for o, v in opts: - if o == '-v': - verbose = 1 - if o == '-f': - force = 1 - for dir in sys.argv[1:]: - os.path.walk(dir, handler, (verbose, force)) - + try: + opts, args = getopt.getopt(sys.argv[1:], 'vf') + if not args: + raise NoArgsError + except (getopt.GetoptError, NoArgsError): + sys.stderr.write('Usage: cachersrc.py dirname ...\n') + sys.exit(1) + verbose = 0 + force = 0 + for o, v in opts: + if o == '-v': + verbose = 1 + if o == '-f': + force = 1 + for dir in sys.argv[1:]: + os.path.walk(dir, handler, (verbose, force)) + if __name__ == '__main__': - main() -
\ No newline at end of file + main() diff --git a/Mac/scripts/genallsuites.py b/Mac/scripts/genallsuites.py index 884d4a4..a556847 100644 --- a/Mac/scripts/genallsuites.py +++ b/Mac/scripts/genallsuites.py @@ -22,32 +22,31 @@ NETSCAPE=OS9DISK + "/Applications (Mac OS 9)/Netscape Communicator\xe2\x84\xa2 F TERMINAL="/Applications/Utilities/Terminal.app" gensuitemodule.processfile_fromresource(APPLESCRIPT, - output=os.path.join(DSTDIR, 'StdSuites'), - basepkgname='_builtinSuites', - edit_modnames=[], verbose=verbose) + output=os.path.join(DSTDIR, 'StdSuites'), + basepkgname='_builtinSuites', + edit_modnames=[], verbose=verbose) gensuitemodule.processfile(SYSTEMEVENTS, - output=os.path.join(DSTDIR, 'SystemEvents'), - basepkgname='StdSuites', - edit_modnames=[('Disk_2d_Folder_2d_File_Suite', 'Disk_Folder_File_Suite')], - verbose=verbose) + output=os.path.join(DSTDIR, 'SystemEvents'), + basepkgname='StdSuites', + edit_modnames=[('Disk_2d_Folder_2d_File_Suite', 'Disk_Folder_File_Suite')], + verbose=verbose) gensuitemodule.processfile(CODEWARRIOR, - output=os.path.join(DSTDIR, 'CodeWarrior'), - basepkgname='StdSuites', - edit_modnames=[], verbose=verbose) + output=os.path.join(DSTDIR, 'CodeWarrior'), + basepkgname='StdSuites', + edit_modnames=[], verbose=verbose) gensuitemodule.processfile(EXPLORER, - output=os.path.join(DSTDIR, 'Explorer'), - basepkgname='StdSuites', - edit_modnames=[], verbose=verbose) + output=os.path.join(DSTDIR, 'Explorer'), + basepkgname='StdSuites', + edit_modnames=[], verbose=verbose) gensuitemodule.processfile(FINDER, - output=os.path.join(DSTDIR, 'Finder'), - basepkgname='StdSuites', - edit_modnames=[], verbose=verbose) + output=os.path.join(DSTDIR, 'Finder'), + basepkgname='StdSuites', + edit_modnames=[], verbose=verbose) gensuitemodule.processfile(NETSCAPE, - output=os.path.join(DSTDIR, 'Netscape'), - basepkgname='StdSuites', - edit_modnames=[('WorldWideWeb_suite_2c__as_d', 'WorldWideWeb_suite')], verbose=verbose) + output=os.path.join(DSTDIR, 'Netscape'), + basepkgname='StdSuites', + edit_modnames=[('WorldWideWeb_suite_2c__as_d', 'WorldWideWeb_suite')], verbose=verbose) gensuitemodule.processfile(TERMINAL, - output=os.path.join(DSTDIR, 'Terminal'), - basepkgname='StdSuites', - edit_modnames=[], verbose=verbose) -
\ No newline at end of file + output=os.path.join(DSTDIR, 'Terminal'), + basepkgname='StdSuites', + edit_modnames=[], verbose=verbose) diff --git a/Mac/scripts/mkestrres.py b/Mac/scripts/mkestrres.py index faa203b..715b8c6 100644 --- a/Mac/scripts/mkestrres.py +++ b/Mac/scripts/mkestrres.py @@ -10,149 +10,148 @@ WRITE = 2 smAllScripts = -3 ERRNO_PROG="#define[ \t]+" \ - "([A-Z0-9a-z_]+)" \ - "[ \t]+" \ - "([0-9]+)" \ - "[ \t]*/\*[ \t]*" \ - "(.*)" \ - "[ \t]*\*/" - + "([A-Z0-9a-z_]+)" \ + "[ \t]+" \ + "([0-9]+)" \ + "[ \t]*/\*[ \t]*" \ + "(.*)" \ + "[ \t]*\*/" + ERRORS_PROG="[ \t]*" \ - "([A-Z0-9a-z_]+)" \ - "[ \t]*=[ \t]*" \ - "([-0-9]+)" \ - "[, \t]*/\*[ \t]*" \ - "(.*)" \ - "[ \t]*\*/" - + "([A-Z0-9a-z_]+)" \ + "[ \t]*=[ \t]*" \ + "([-0-9]+)" \ + "[, \t]*/\*[ \t]*" \ + "(.*)" \ + "[ \t]*\*/" + ERRORS_PROG_2="[ \t]*" \ - "([A-Z0-9a-z_]+)" \ - "[ \t]*=[ \t]*" \ - "([-0-9]+)" \ - "[, \t]*" + "([A-Z0-9a-z_]+)" \ + "[ \t]*=[ \t]*" \ + "([-0-9]+)" \ + "[, \t]*" def Pstring(str): - if len(str) > 255: - raise ValueError, 'String too large' - return chr(len(str))+str - + if len(str) > 255: + raise ValueError, 'String too large' + return chr(len(str))+str + def writeestr(dst, edict): - """Create Estr resource file given a dictionary of errors.""" - - os.unlink(dst.as_pathname()) - Res.FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts) - output = Res.FSpOpenResFile(dst, WRITE) - Res.UseResFile(output) - for num in edict.keys(): - res = Res.Resource(Pstring(edict[num][0])) - res.AddResource('Estr', num, '') - res.WriteResource() - Res.CloseResFile(output) - + """Create Estr resource file given a dictionary of errors.""" + + os.unlink(dst.as_pathname()) + Res.FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts) + output = Res.FSpOpenResFile(dst, WRITE) + Res.UseResFile(output) + for num in edict.keys(): + res = Res.Resource(Pstring(edict[num][0])) + res.AddResource('Estr', num, '') + res.WriteResource() + Res.CloseResFile(output) + def writepython(fp, dict): - k = dict.keys() - k.sort() - for i in k: - fp.write("%s\t=\t%d\t#%s\n"%(dict[i][1], i, dict[i][0])) - + k = dict.keys() + k.sort() + for i in k: + fp.write("%s\t=\t%d\t#%s\n"%(dict[i][1], i, dict[i][0])) + def parse_errno_h(fp, dict): - errno_prog = re.compile(ERRNO_PROG) - for line in fp.readlines(): - m = errno_prog.match(line) - if m: - number = string.atoi(m.group(2)) - name = m.group(1) - desc = string.strip(m.group(3)) - - if not dict.has_key(number): - dict[number] = desc, name - else: - print 'DUPLICATE', number - print '\t', dict[number] - print '\t', (desc, name) - + errno_prog = re.compile(ERRNO_PROG) + for line in fp.readlines(): + m = errno_prog.match(line) + if m: + number = string.atoi(m.group(2)) + name = m.group(1) + desc = string.strip(m.group(3)) + + if not dict.has_key(number): + dict[number] = desc, name + else: + print 'DUPLICATE', number + print '\t', dict[number] + print '\t', (desc, name) + def parse_errors_h(fp, dict): - errno_prog = re.compile(ERRORS_PROG) - errno_prog_2 = re.compile(ERRORS_PROG_2) - for line in fp.readlines(): - match = 0 - m = errno_prog.match(line) - m2 = errno_prog_2.match(line) - if m: - number = string.atoi(m.group(2)) - name = m.group(1) - desc = string.strip(m.group(3)) - match=1 - elif m2: - number = string.atoi(m2.group(2)) - name = m2.group(1) - desc = name - match=1 - if match: - if number > 0: continue - - if not dict.has_key(number): - dict[number] = desc, name - else: - print 'DUPLICATE', number - print '\t', dict[number] - print '\t', (desc, name) - if len(desc) > len(dict[number][0]): - print 'Pick second one' - dict[number] = desc, name - + errno_prog = re.compile(ERRORS_PROG) + errno_prog_2 = re.compile(ERRORS_PROG_2) + for line in fp.readlines(): + match = 0 + m = errno_prog.match(line) + m2 = errno_prog_2.match(line) + if m: + number = string.atoi(m.group(2)) + name = m.group(1) + desc = string.strip(m.group(3)) + match=1 + elif m2: + number = string.atoi(m2.group(2)) + name = m2.group(1) + desc = name + match=1 + if match: + if number > 0: continue + + if not dict.has_key(number): + dict[number] = desc, name + else: + print 'DUPLICATE', number + print '\t', dict[number] + print '\t', (desc, name) + if len(desc) > len(dict[number][0]): + print 'Pick second one' + dict[number] = desc, name + def main(): - dict = {} - pathname = EasyDialogs.AskFileForOpen(message="Where is GUSI sys/errno.h?") - if pathname: - fp = open(pathname) - parse_errno_h(fp, dict) - fp.close() - - pathname = EasyDialogs.AskFileForOpen(message="Select cerrno (MSL) or cancel") - if pathname: - fp = open(pathname) - parse_errno_h(fp, dict) - fp.close() - - pathname = EasyDialogs.AskFileForOpen(message="Where is MacErrors.h?") - if pathname: - fp = open(pathname) - parse_errors_h(fp, dict) - fp.close() - - pathname = EasyDialogs.AskFileForOpen(message="Where is mkestrres-MacErrors.h?") - if pathname: - fp = open(pathname) - parse_errors_h(fp, dict) - fp.close() - - if not dict: - return - - pathname = EasyDialogs.AskFileForSave(message="Resource output file?", savedFileName="errors.rsrc") - if pathname: - writeestr(fss, dict) - - pathname = EasyDialogs.AskFileForSave(message="Python output file?", savedFileName="macerrors.py") - if pathname: - fp = open(pathname, "w") - writepython(fp, dict) - fp.close() - fss.SetCreatorType('Pyth', 'TEXT') - - pathname = EasyDialogs.AskFileForSave(message="Text output file?", savedFileName="errors.txt") - if pathname: - fp = open(pathname, "w") - - k = dict.keys() - k.sort() - for i in k: - fp.write("%d\t%s\t%s\n"%(i, dict[i][1], dict[i][0])) - fp.close() - - + dict = {} + pathname = EasyDialogs.AskFileForOpen(message="Where is GUSI sys/errno.h?") + if pathname: + fp = open(pathname) + parse_errno_h(fp, dict) + fp.close() + + pathname = EasyDialogs.AskFileForOpen(message="Select cerrno (MSL) or cancel") + if pathname: + fp = open(pathname) + parse_errno_h(fp, dict) + fp.close() + + pathname = EasyDialogs.AskFileForOpen(message="Where is MacErrors.h?") + if pathname: + fp = open(pathname) + parse_errors_h(fp, dict) + fp.close() + + pathname = EasyDialogs.AskFileForOpen(message="Where is mkestrres-MacErrors.h?") + if pathname: + fp = open(pathname) + parse_errors_h(fp, dict) + fp.close() + + if not dict: + return + + pathname = EasyDialogs.AskFileForSave(message="Resource output file?", savedFileName="errors.rsrc") + if pathname: + writeestr(fss, dict) + + pathname = EasyDialogs.AskFileForSave(message="Python output file?", savedFileName="macerrors.py") + if pathname: + fp = open(pathname, "w") + writepython(fp, dict) + fp.close() + fss.SetCreatorType('Pyth', 'TEXT') + + pathname = EasyDialogs.AskFileForSave(message="Text output file?", savedFileName="errors.txt") + if pathname: + fp = open(pathname, "w") + + k = dict.keys() + k.sort() + for i in k: + fp.write("%d\t%s\t%s\n"%(i, dict[i][1], dict[i][0])) + fp.close() + + if __name__ == '__main__': - main() - + main() diff --git a/Mac/scripts/zappycfiles.py b/Mac/scripts/zappycfiles.py index 0349220..a8193c1 100644 --- a/Mac/scripts/zappycfiles.py +++ b/Mac/scripts/zappycfiles.py @@ -8,30 +8,29 @@ import sys doit = 1 def main(): - if not sys.argv[1:]: - if os.name == 'mac': - import EasyDialogs - dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in') - if not dir: - sys.exit(0) - zappyc(dir) - else: - print 'Usage: zappyc dir ...' - sys.exit(1) - for dir in sys.argv[1:]: - zappyc(dir) + if not sys.argv[1:]: + if os.name == 'mac': + import EasyDialogs + dir = EasyDialogs.AskFolder(message='Directory to zap pyc files in') + if not dir: + sys.exit(0) + zappyc(dir) + else: + print 'Usage: zappyc dir ...' + sys.exit(1) + for dir in sys.argv[1:]: + zappyc(dir) def zappyc(dir): - os.path.walk(dir, walker, None) - + os.path.walk(dir, walker, None) + def walker(dummy, top, names): - for name in names: - if name[-4:] in ('.pyc', '.pyo'): - path = os.path.join(top, name) - print 'Zapping', path - if doit: - os.unlink(path) - + for name in names: + if name[-4:] in ('.pyc', '.pyo'): + path = os.path.join(top, name) + print 'Zapping', path + if doit: + os.unlink(path) + if __name__ == '__main__': - main() - + main() |