blob: 4ddc8130f574fffecc3a6535ad6c5f5447c1d83a [file] [log] [blame]
#!/usr/bin/env python2
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This utility allows for easy update to chromium os tree status, with proper
# password protected authorization.
# Example usage:
# ./ [options] "a quoted space separated message."
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import getpass
import optparse
import os
import sys
from six.moves import urllib
def get_status():
response = urllib.request.urlopen(
CHROMEOS_STATUS_SERVER + '/current?format=raw')
def get_pwd():
password_file = os.path.join('/home', getpass.getuser(),
if os.path.isfile(password_file):
return open(password_file, 'r').read().strip()
return getpass.getpass()
def post_status(force, message):
if not force:
status = get_status()
if 'tree is closed' in status.lower():
print('Tree is already closed for some other reason.',
print(status, file=sys.stderr)
return -1
data = {
'message': message,
'username': getpass.getuser(),
'password': get_pwd(),
urllib.request.urlopen(CHROMEOS_STATUS_SERVER + '/status',
return 0
if __name__ == '__main__':
parser = optparse.OptionParser("%prog [options] quoted_message")
dest='force', action='store_false',
help='Dont force to close tree if it is already closed.')
options, args = parser.parse_args()
if not args:
print('missing tree close message.', file=sys.stderr)
sys.exit(post_status(options.force, args[0]))