Upstream version 11.39.244.0
[platform/framework/web/crosswalk.git] / src / xwalk / tools / upstream_revision.py
1 #!/usr/bin/env python
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.
6
7 """
8 upstream_revision.py -- Upstream revision fetching utility.
9 """
10
11 import optparse
12 import os
13 import sys
14
15
16 def WriteIfChanged(file_name, contents):
17   """
18   Writes the specified contents to the specified file_name
19   iff the contents are different than the current contents.
20   """
21   try:
22     old_contents = open(file_name, 'r').read()
23   except EnvironmentError:
24     pass
25   else:
26     if contents == old_contents:
27       return
28     os.unlink(file_name)
29   open(file_name, 'w').write(contents)
30
31
32 def main(argv=None):
33   if argv is None:
34     argv = sys.argv
35
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:])
42
43   contents = 'UPSTREAM_REVISION=%s' % opts.revision
44   WriteIfChanged(opts.output, contents)
45
46   return 0
47
48
49 if __name__ == '__main__':
50   sys.exit(main())