Add ICU message format support
[chromium-blink-merge.git] / ios / build / util / canary_version.py
blob09923683460780ca706626d168209adc78b5a829
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Writes canary version information to a specified file."""
8 import datetime
9 import sys
10 import optparse
11 import os
14 def WriteIfChanged(file_name, content):
15 """
16 Write |content| to |file_name| iff the content is different from the
17 current content.
18 """
19 try:
20 old_content = open(file_name, 'rb').read()
21 except EnvironmentError:
22 pass
23 else:
24 if content == old_content:
25 return
26 os.unlink(file_name)
27 open(file_name, 'wb').write(content)
30 def main(argv=None):
31 if argv is None:
32 argv = sys.argv
34 parser = optparse.OptionParser(usage="canary_version.py [options]")
35 parser.add_option("-o", "--output", metavar="FILE",
36 help="write patch level to FILE")
37 opts, args = parser.parse_args(argv[1:])
38 out_file = opts.output
40 if args and out_file is None:
41 out_file = args.pop(0)
43 if args:
44 sys.stderr.write('Unexpected arguments: %r\n\n' % args)
45 parser.print_help()
46 sys.exit(2)
48 # Number of days since January 1st, 2012.
49 day_number = (datetime.date.today() - datetime.date(2012, 1, 1)).days
50 content = "PATCH={}\n".format(day_number)
52 if not out_file:
53 sys.stdout.write(content)
54 else:
55 WriteIfChanged(out_file, content)
57 if __name__ == '__main__':
58 sys.exit(main())