Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2015 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 | |
| 6 | |
| 7 """Wrapper for updating and calling infra.git tools. | |
| 8 | |
| 9 This tool does a two things: | |
| 10 * Maintains a infra.git checkout pinned at "deployed" in the home dir | |
| 11 * Acts as an alias to infra.tools.* | |
| 12 """ | |
| 13 | |
| 14 # TODO(hinoka): Use cipd/glyco instead of git/gclient. | |
| 15 | |
| 16 import sys | |
| 17 import os | |
| 18 import subprocess | |
| 19 import re | |
| 20 | |
| 21 | |
| 22 THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | |
|
ghost stip (do not use)
2015/07/11 00:44:47
probably name it SCRIPT_DIR or something
hinoka
2015/07/14 18:51:36
Done.
| |
| 23 GCLIENT = os.path.join(THIS_DIR, 'gclient.py') | |
| 24 TARGET_DIR = os.path.expanduser('~/.chrome-infra') | |
| 25 INFRA_DIR = os.path.join(TARGET_DIR, 'infra') | |
| 26 | |
| 27 | |
| 28 def get_git_rev(target, branch): | |
| 29 return subprocess.check_output( | |
| 30 ['git', 'log', '--format=%B', '-n1', branch], cwd=target) | |
| 31 | |
| 32 | |
| 33 def need_to_update(): | |
| 34 """Checks to see if we need to update the ~/.chrome-infra/infra checkout.""" | |
| 35 try: | |
| 36 cmd = [sys.executable, GCLIENT, 'revinfo'] | |
| 37 subprocess.check_call( | |
| 38 cmd, cwd=os.path.join(TARGET_DIR), stdout=subprocess.PIPE) | |
| 39 except subprocess.CalledProcessError: | |
| 40 return True # Gclient failed, definitely need to update. | |
| 41 except OSError: | |
| 42 return True # Gclient failed, definitely need to update. | |
| 43 | |
| 44 local_rev = get_git_rev(INFRA_DIR, 'HEAD') | |
| 45 | |
| 46 subprocess.check_call( | |
| 47 ['git', 'fetch', 'origin'], cwd=INFRA_DIR, stdout=subprocess.PIPE) | |
| 48 origin_rev = get_git_rev(INFRA_DIR, 'origin/deployed') | |
| 49 return origin_rev != local_rev | |
| 50 | |
| 51 | |
| 52 def ensure_infra(): | |
| 53 """Ensures that infra.git is present in ~/.chrome-infra.""" | |
| 54 print 'Fetching infra, may take a couple of minutes...' | |
|
ghost stip (do not use)
2015/07/11 00:44:47
'Fetching infra into %s, may take..' % TARGET_DIR
hinoka
2015/07/14 18:51:36
Done.
| |
| 55 if not os.path.isdir(TARGET_DIR): | |
| 56 os.mkdir(TARGET_DIR) | |
| 57 if not os.path.exists(os.path.join(TARGET_DIR, '.gclient')): | |
| 58 subprocess.check_call( | |
| 59 [sys.executable, os.path.join(THIS_DIR, 'fetch.py'), 'infra'], | |
| 60 cwd=TARGET_DIR, | |
| 61 stdout=subprocess.PIPE) | |
| 62 subprocess.check_call( | |
| 63 [sys.executable, GCLIENT, 'sync', '--revision', 'deployed'], | |
| 64 cwd=TARGET_DIR, | |
| 65 stdout=subprocess.PIPE) | |
| 66 | |
| 67 | |
| 68 def run(args): | |
| 69 tool_name = args[0] | |
| 70 cmd = [ | |
| 71 sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'), | |
| 72 'infra.tools.%s' % tool_name] | |
| 73 cmd.extend(args[1:]) | |
| 74 return subprocess.call(cmd) | |
| 75 | |
| 76 def main(): | |
| 77 if need_to_update(): | |
| 78 ensure_infra() | |
| 79 return run(sys.argv[1:]) | |
| 80 | |
| 81 if __name__ == '__main__': | |
| 82 sys.exit(main()) | |
| OLD | NEW |