update_server.py revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import getpass 7import os 8import subprocess 9import sys 10 11import build_server 12 13if __name__ == '__main__': 14 additional_args = [] 15 if len(sys.argv) > 1 and sys.argv[1].endswith('appcfg.py'): 16 appcfg_path = sys.argv[1] 17 additional_args = sys.argv[2:] 18 else: 19 appcfg_path = None 20 additional_args = sys.argv[1:] 21 for path in ['.', 22 os.path.join(os.environ['HOME'], 'local', 'google_appengine'), 23 os.path.join(os.environ['HOME'], 'google_appengine'), 24 os.getcwd()] + sys.path: 25 full_path = os.path.join(path, 'appcfg.py') 26 if os.path.exists(full_path): 27 appcfg_path = full_path 28 break 29 if appcfg_path is None: 30 print 'appcfg.py could not be found in default paths.' 31 print 'usage: update_server.py <path_to_appcfg.py> <appcfg_options>' 32 exit(1) 33 34 build_server.main() 35 server2_path = os.path.dirname(sys.argv[0]) 36 username = raw_input('Username for server2 github account: ') 37 password = getpass.getpass() 38 with open('github_file_system.py') as f: 39 contents = f.read() 40 if 'USERNAME = None' not in contents: 41 print 'Error: Can\'t find "USERNAME = None" in github_file_system.py.' 42 exit(1) 43 if 'PASSWORD = None' not in contents: 44 print 'Error: Can\'t find "PASSWORD = None" in github_file_system.py.' 45 exit(1) 46 try: 47 with open('github_file_system.py', 'w+') as f: 48 f.write( 49 contents.replace('PASSWORD = None', 'PASSWORD = \'%s\'' % password) 50 .replace('USERNAME = None', 'USERNAME = \'%s\'' % username)) 51 subprocess.call([appcfg_path, 'update', server2_path] + additional_args) 52 finally: 53 with open('github_file_system.py', 'w+') as f: 54 f.write(contents) 55