michael@0: #!/usr/bin/python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: from optparse import OptionParser michael@0: import sys michael@0: import re michael@0: michael@0: o = OptionParser() michael@0: o.add_option("--buildid", dest="buildid") michael@0: o.add_option("--version", dest="version") michael@0: michael@0: (options, args) = o.parse_args() michael@0: michael@0: if not options.buildid: michael@0: print >>sys.stderr, "--buildid is required" michael@0: sys.exit(1) michael@0: michael@0: if not options.version: michael@0: print >>sys.stderr, "--version is required" michael@0: sys.exit(1) michael@0: michael@0: # We want to build a version number that matches the format allowed for michael@0: # CFBundleVersion (nnnnn[.nn[.nn]]). We'll incorporate both the version michael@0: # number as well as the date, so that it changes at least daily (for nightly michael@0: # builds), but also so that newly-built older versions (e.g. beta build) aren't michael@0: # considered "newer" than previously-built newer versions (e.g. a trunk nightly) michael@0: michael@0: buildid = open(options.buildid, 'r').read() michael@0: michael@0: # extract only the major version (i.e. "14" from "14.0b1") michael@0: majorVersion = re.match(r'^(\d+)[^\d].*', options.version).group(1) michael@0: # last two digits of the year michael@0: twodigityear = buildid[2:4] michael@0: month = buildid[4:6] michael@0: if month[0] == '0': michael@0: month = month[1] michael@0: day = buildid[6:8] michael@0: if day[0] == '0': michael@0: day = day[1] michael@0: michael@0: print '%s.%s.%s' % (majorVersion + twodigityear, month, day)