Jack Jansen | 7323f08 | 2004-07-15 16:03:55 +0000 | [diff] [blame] | 1 | """fixversions - Fix version numbers in .plist files to match current |
| 2 | python version and date""" |
| 3 | |
| 4 | import sys |
| 5 | import os |
| 6 | import time |
| 7 | import plistlib |
| 8 | |
| 9 | SHORTVERSION = "%d.%d" % (sys.version_info[0], sys.version_info[1]) |
| 10 | if sys.version_info[2]: |
| 11 | SHORTVERSION = SHORTVERSION + ".%d" % sys.version_info[2] |
| 12 | if sys.version_info[3] != 'final': |
| 13 | SHORTVERSION = SHORTVERSION + "%s%d" % (sys.version_info[3], sys.version_info[4]) |
| 14 | |
| 15 | COPYRIGHT = "(c) %d Python Software Foundation." % time.gmtime()[0] |
| 16 | |
| 17 | LONGVERSION = SHORTVERSION + ", " + COPYRIGHT |
| 18 | |
| 19 | def fix(file): |
| 20 | plist = plistlib.Plist.fromFile(file) |
| 21 | changed = False |
| 22 | if plist.has_key("CFBundleGetInfoString") and \ |
| 23 | plist["CFBundleGetInfoString"] != LONGVERSION: |
| 24 | plist["CFBundleGetInfoString"] = LONGVERSION |
| 25 | changed = True |
| 26 | if plist.has_key("CFBundleLongVersionString") and \ |
| 27 | plist["CFBundleLongVersionString"] != LONGVERSION: |
| 28 | plist["CFBundleLongVersionString"] = LONGVERSION |
| 29 | changed = True |
| 30 | if plist.has_key("NSHumanReadableCopyright") and \ |
| 31 | plist["NSHumanReadableCopyright"] != COPYRIGHT: |
| 32 | plist["NSHumanReadableCopyright"] = COPYRIGHT |
| 33 | changed = True |
| 34 | if plist.has_key("CFBundleVersion") and \ |
| 35 | plist["CFBundleVersion"] != SHORTVERSION: |
| 36 | plist["CFBundleVersion"] = SHORTVERSION |
| 37 | changed = True |
| 38 | if plist.has_key("CFBundleShortVersionString") and \ |
| 39 | plist["CFBundleShortVersionString"] != SHORTVERSION: |
| 40 | plist["CFBundleShortVersionString"] = SHORTVERSION |
| 41 | changed = True |
| 42 | if changed: |
| 43 | os.rename(file, file + '~') |
| 44 | plist.write(file) |
| 45 | |
| 46 | def main(): |
| 47 | if len(sys.argv) < 2: |
| 48 | print "Usage: %s plistfile ..." % sys.argv[0] |
| 49 | print "or: %s -a fix standard Python plist files" |
| 50 | sys.exit(1) |
| 51 | if sys.argv[1] == "-a": |
| 52 | files = [ |
| 53 | "../OSXResources/app/Info.plist", |
| 54 | "../OSXResources/framework/version.plist", |
| 55 | "../Tools/IDE/PackageManager.plist", |
| 56 | "../Tools/IDE/PythonIDE.plist", |
| 57 | "../scripts/BuildApplet.plist" |
| 58 | ] |
| 59 | if not os.path.exists(files[0]): |
| 60 | print "%s -a must be run from Mac/OSX directory" |
| 61 | sys.exit(1) |
| 62 | else: |
| 63 | files = sys.argv[1:] |
| 64 | for file in files: |
| 65 | fix(file) |
| 66 | sys.exit(0) |
| 67 | |
| 68 | if __name__ == "__main__": |
| 69 | main() |
| 70 | |