Chromium Code Reviews| Index: utils/set_tree_status.py |
| diff --git a/utils/set_tree_status.py b/utils/set_tree_status.py |
| index a189503bf17c2ec8568bb477dda21fb07b7d5ff7..5f4a16478ae430c8fb6ea47d7c081ddda5e8c166 100755 |
| --- a/utils/set_tree_status.py |
| +++ b/utils/set_tree_status.py |
| @@ -7,9 +7,10 @@ |
| # password protected authorization. |
| # |
| # Example usage: |
| -# ./set_tree_status.py "a quoted space separated message." |
| +# ./set_tree_status.py [options] "a quoted space separated message." |
| import getpass |
| +import optparse |
| import os |
| import sys |
| import urllib |
| @@ -30,24 +31,37 @@ def get_pwd(): |
| return getpass.getpass() |
| -def post_status(message): |
| - status = get_status() |
| - if 'tree is closed' in status.lower(): |
| - print >> sys.stderr, 'Tree is already closed for some other reason.' |
| - print >> sys.stderr, status |
| - return -1 |
| +def post_status(force, message): |
| + if not force: |
| + status = get_status() |
| + if 'tree is closed' in status.lower(): |
| + print >> sys.stderr, 'Tree is already closed for some other reason.' |
| + print >> sys.stderr, status |
| + return -1 |
| data = { |
| 'message': message, |
| 'username': getpass.getuser(), |
| 'password': get_pwd(), |
| } |
| - urllib.urlopen(CHROMEOS_STATUS_SERVER + '/status', urllib.urlencode(data)) |
| + try: |
|
Dale Curtis
2011/04/07 18:01:33
No need to catch anything here really, the excepti
ericli
2011/04/07 18:08:28
Done.
|
| + urllib.urlopen(CHROMEOS_STATUS_SERVER + '/status', |
| + urllib.urlencode(data)) |
| + except IOError, ioex: |
| + if ioex.errno == 'socket error': |
| + logging.warn('Remote server is not available') |
| + return -1 |
| + else: |
| + raise |
| return 0 |
| if __name__ == '__main__': |
| - if len(sys.argv) != 2: |
| - print('Usage: set_tree_status.py "message"') |
| - sys.exit(1) |
| - |
| - sys.exit(post_status(sys.argv[1])) |
| + parser = optparse.OptionParser("%prog [options] quoted_messages") |
|
Dale Curtis
2011/04/07 18:01:33
quoted_message
ericli
2011/04/07 18:08:28
Done.
|
| + parser.add_option('--noforce', |
| + dest='force', action='store_false', |
| + default=True, |
| + help='Force closing tree action.') |
|
Dale Curtis
2011/04/07 18:01:33
Test should be 'Don't close the tree if it's alrea
ericli
2011/04/07 18:08:28
Done.
|
| + options, args = parser.parse_args() |
| + if not args: |
| + print >> sys.stderr, 'missing tree close message.' |
| + sys.exit(post_status(options.force, args[0])) |