blob: f8d860258680ce9cb3b76e2c0f5fe87125b5b5dd [file] [log] [blame]
[email protected]41310062009-10-06 18:03:471#!/usr/bin/python
2# Copyright (c) 2009 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 os
[email protected]41310062009-10-06 18:03:477import sys
[email protected]f6613be2010-06-30 01:14:058from subprocess import Popen, PIPE
[email protected]41310062009-10-06 18:03:479
[email protected]f3c92802009-10-15 18:41:5410# Try locating depot_tools from the user's PATH.
11depot_tools_path = None
[email protected]f6613be2010-06-30 01:14:0512
13# First parse PATH if there's a "depot_tools" inside
[email protected]94ba0242009-10-15 21:35:4114for path in os.environ.get("PATH").split(os.pathsep):
[email protected]f6613be2010-06-30 01:14:0515 if not path.endswith("depot_tools") and not path.endswith("depot_tools/"):
[email protected]41310062009-10-06 18:03:4716 continue
[email protected]f3c92802009-10-15 18:41:5417 depot_tools_path = path
[email protected]41310062009-10-06 18:03:4718 break
19
[email protected]f6613be2010-06-30 01:14:0520# If depot_tools dir is not called depot_tools, or other weirdness
21if not depot_tools_path:
22 # Grab a `which gclient', which gives first match
23 # `which' also uses PATH, but is not restricted to specific directory name
[email protected]c98b0472010-09-24 18:37:4224 path = Popen(["which", "gclient"], stdout=PIPE).communicate()[0].strip()
[email protected]f6613be2010-06-30 01:14:0525 if path:
26 depot_tools_path = path.replace("/gclient","")
27
[email protected]f3c92802009-10-15 18:41:5428# If we found depot_tools, add it to the script's import path.
[email protected]f6613be2010-06-30 01:14:0529# Use realpath to normalize the actual path
[email protected]f3c92802009-10-15 18:41:5430if depot_tools_path:
[email protected]075c6392011-01-31 18:35:5931 sys.path.insert(0, os.path.realpath(depot_tools_path))
[email protected]f3c92802009-10-15 18:41:5432else:
33 print "ERROR: Could not find depot_tools in your PATH."
34 print "ERROR: Please add it to your PATH and try again."
35 sys.exit(1)
36
37# Try importing git_cl_hooks from depot_tools.
38try:
39 import git_cl_hooks
40except ImportError:
[email protected]94ba0242009-10-15 21:35:4141 print "ERROR: Could not import git_cl_hooks from depot_tools in your PATH."
[email protected]f3c92802009-10-15 18:41:5442 print "ERROR: Make sure %s is up-to-date and try again." % depot_tools_path
43 sys.exit(1)
[email protected]41310062009-10-06 18:03:4744
45# Ensure we were called with the necessary number of arguments.
46program_name = os.path.basename(sys.argv[0])
[email protected]7658eb32009-10-08 18:00:3147if len(sys.argv) != 2:
[email protected]f3c92802009-10-15 18:41:5448 print "usage: %s [upstream branch]" % program_name
49 sys.exit(1)
[email protected]41310062009-10-06 18:03:4750
[email protected]7658eb32009-10-08 18:00:3151# Run the hooks library with our arguments.
52exec git_cl_hooks.RunHooks(hook_name=program_name, upstream_branch=sys.argv[1])