| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 # | 5 # |
| 6 # This utility allows for easy update to chromium os tree status, with proper | 6 # This utility allows for easy update to chromium os tree status, with proper |
| 7 # password protected authorization. | 7 # password protected authorization. |
| 8 # | 8 # |
| 9 # Example usage: | 9 # Example usage: |
| 10 # ./set_tree_status.py "a quoted space separated message." | 10 # ./set_tree_status.py [options] "a quoted space separated message." |
| 11 | 11 |
| 12 import getpass | 12 import getpass |
| 13 import optparse |
| 13 import os | 14 import os |
| 14 import sys | 15 import sys |
| 15 import urllib | 16 import urllib |
| 16 | 17 |
| 17 CHROMEOS_STATUS_SERVER = 'https://chromiumos-status.appspot.com' | 18 CHROMEOS_STATUS_SERVER = 'https://chromiumos-status.appspot.com' |
| 18 | 19 |
| 19 | 20 |
| 20 def get_status(): | 21 def get_status(): |
| 21 response = urllib.urlopen(CHROMEOS_STATUS_SERVER + '/current?format=raw') | 22 response = urllib.urlopen(CHROMEOS_STATUS_SERVER + '/current?format=raw') |
| 22 return response.read() | 23 return response.read() |
| 23 | 24 |
| 24 | 25 |
| 25 def get_pwd(): | 26 def get_pwd(): |
| 26 password_file = os.path.join('/home', getpass.getuser(), | 27 password_file = os.path.join('/home', getpass.getuser(), |
| 27 '.status_password.txt') | 28 '.status_password.txt') |
| 28 if os.path.isfile(password_file): | 29 if os.path.isfile(password_file): |
| 29 return open(password_file, 'r').read().strip() | 30 return open(password_file, 'r').read().strip() |
| 30 return getpass.getpass() | 31 return getpass.getpass() |
| 31 | 32 |
| 32 | 33 |
| 33 def post_status(message): | 34 def post_status(force, message): |
| 34 status = get_status() | 35 if not force: |
| 35 if 'tree is closed' in status.lower(): | 36 status = get_status() |
| 36 print >> sys.stderr, 'Tree is already closed for some other reason.' | 37 if 'tree is closed' in status.lower(): |
| 37 print >> sys.stderr, status | 38 print >> sys.stderr, 'Tree is already closed for some other reason.' |
| 38 return -1 | 39 print >> sys.stderr, status |
| 40 return -1 |
| 39 data = { | 41 data = { |
| 40 'message': message, | 42 'message': message, |
| 41 'username': getpass.getuser(), | 43 'username': getpass.getuser(), |
| 42 'password': get_pwd(), | 44 'password': get_pwd(), |
| 43 } | 45 } |
| 44 urllib.urlopen(CHROMEOS_STATUS_SERVER + '/status', urllib.urlencode(data)) | 46 urllib.urlopen(CHROMEOS_STATUS_SERVER + '/status', urllib.urlencode(data)) |
| 45 return 0 | 47 return 0 |
| 46 | 48 |
| 47 | 49 |
| 48 if __name__ == '__main__': | 50 if __name__ == '__main__': |
| 49 if len(sys.argv) != 2: | 51 parser = optparse.OptionParser("%prog [options] quoted_message") |
| 50 print('Usage: set_tree_status.py "message"') | 52 parser.add_option('--noforce', |
| 51 sys.exit(1) | 53 dest='force', action='store_false', |
| 52 | 54 default=True, |
| 53 sys.exit(post_status(sys.argv[1])) | 55 help='Dont force to close tree if it is already closed.') |
| 56 options, args = parser.parse_args() |
| 57 if not args: |
| 58 print >> sys.stderr, 'missing tree close message.' |
| 59 sys.exit(post_status(options.force, args[0])) |
| OLD | NEW |