Commit f3c92808 authored by chase@chromium.org's avatar chase@chromium.org

Fail gracefully when we can't import hooks library.

BUG=5339
TEST=excluding depot_tools from PATH shows an
instructive error, trying to run the hook with
git_cl_hooks.py missing shows an instructive error
Review URL: http://codereview.chromium.org/264069

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@29156 0039d316-1c4b-4281-b951-d872f2087c98
parent cce9e1c2
......@@ -6,20 +6,36 @@
import os
import sys
# Find depot_tools in PATH, append it to sys.path so we can import.
paths = os.environ.get("PATH")
for path in paths.split(':'):
# Try locating depot_tools from the user's PATH.
depot_tools_path = None
for path in os.environ.get("PATH").split(':'):
if not path.endswith("depot_tools"):
continue
sys.path.append(path)
depot_tools_path = path
break
import git_cl_hooks
# If we found depot_tools, add it to the script's import path.
if depot_tools_path:
sys.path.append(depot_tools_path)
else:
print "ERROR: Could not find depot_tools in your PATH."
print "ERROR: Please add it to your PATH and try again."
sys.exit(1)
# Try importing git_cl_hooks from depot_tools.
try:
import git_cl_hooks
except ImportError:
print ("ERROR: Could not import git_cl_hooks from your depot_tools at %s." %
depot_tools_path)
print "ERROR: Make sure %s is up-to-date and try again." % depot_tools_path
sys.exit(1)
# Ensure we were called with the necessary number of arguments.
program_name = os.path.basename(sys.argv[0])
if len(sys.argv) != 2:
raise Exception("usage: %s [upstream branch]" % program_name)
print "usage: %s [upstream branch]" % program_name
sys.exit(1)
# Run the hooks library with our arguments.
exec git_cl_hooks.RunHooks(hook_name=program_name, upstream_branch=sys.argv[1])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment