Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2594)

Unified Diff: cit.py

Issue 1232573007: Added tool to call tools in infra.git (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | yo » ('j') | yo » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cit.py
diff --git a/cit.py b/cit.py
new file mode 100755
index 0000000000000000000000000000000000000000..9be4b012c21747cb6c427bb7aa074d9ba6d6aab7
--- /dev/null
+++ b/cit.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Wrapper for updating and calling infra.git tools.
+
+This tool does a two things:
+* Maintains a infra.git checkout pinned at "deployed" in the home dir
+* Acts as an alias to infra.tools.*
+"""
+
+# TODO(hinoka): Use cipd/glyco instead of git/gclient.
+
+import sys
+import os
+import subprocess
+import re
+
+
+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.
+GCLIENT = os.path.join(THIS_DIR, 'gclient.py')
+TARGET_DIR = os.path.expanduser('~/.chrome-infra')
+INFRA_DIR = os.path.join(TARGET_DIR, 'infra')
+
+
+def get_git_rev(target, branch):
+ return subprocess.check_output(
+ ['git', 'log', '--format=%B', '-n1', branch], cwd=target)
+
+
+def need_to_update():
+ """Checks to see if we need to update the ~/.chrome-infra/infra checkout."""
+ try:
+ cmd = [sys.executable, GCLIENT, 'revinfo']
+ subprocess.check_call(
+ cmd, cwd=os.path.join(TARGET_DIR), stdout=subprocess.PIPE)
+ except subprocess.CalledProcessError:
+ return True # Gclient failed, definitely need to update.
+ except OSError:
+ return True # Gclient failed, definitely need to update.
+
+ local_rev = get_git_rev(INFRA_DIR, 'HEAD')
+
+ subprocess.check_call(
+ ['git', 'fetch', 'origin'], cwd=INFRA_DIR, stdout=subprocess.PIPE)
+ origin_rev = get_git_rev(INFRA_DIR, 'origin/deployed')
+ return origin_rev != local_rev
+
+
+def ensure_infra():
+ """Ensures that infra.git is present in ~/.chrome-infra."""
+ 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.
+ if not os.path.isdir(TARGET_DIR):
+ os.mkdir(TARGET_DIR)
+ if not os.path.exists(os.path.join(TARGET_DIR, '.gclient')):
+ subprocess.check_call(
+ [sys.executable, os.path.join(THIS_DIR, 'fetch.py'), 'infra'],
+ cwd=TARGET_DIR,
+ stdout=subprocess.PIPE)
+ subprocess.check_call(
+ [sys.executable, GCLIENT, 'sync', '--revision', 'deployed'],
+ cwd=TARGET_DIR,
+ stdout=subprocess.PIPE)
+
+
+def run(args):
+ tool_name = args[0]
+ cmd = [
+ sys.executable, os.path.join(TARGET_DIR, 'infra', 'run.py'),
+ 'infra.tools.%s' % tool_name]
+ cmd.extend(args[1:])
+ return subprocess.call(cmd)
+
+def main():
+ if need_to_update():
+ ensure_infra()
+ return run(sys.argv[1:])
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « no previous file | yo » ('j') | yo » ('J')

Powered by Google App Engine
This is Rietveld 408576698