2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Copyright (c) 2014 Intel Corp. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
8 upstream_revision.py -- Upstream revision fetching utility.
16 def WriteIfChanged(file_name, contents):
18 Writes the specified contents to the specified file_name
19 iff the contents are different than the current contents.
22 old_contents = open(file_name, 'r').read()
23 except EnvironmentError:
26 if contents == old_contents:
29 open(file_name, 'w').write(contents)
36 parser = optparse.OptionParser(usage="upstream_revision.py [options]")
37 parser.add_option("-r", "--revision",
38 help="The revision number.")
39 parser.add_option("-o", "--output", metavar="FILE",
40 help="Write revision to FILE. ")
41 opts, _ = parser.parse_args(argv[1:])
43 contents = 'UPSTREAM_REVISION=%s' % opts.revision
44 WriteIfChanged(opts.output, contents)
49 if __name__ == '__main__':