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

Unified Diff: git-cl-upload-hook

Issue 264069: Fail gracefully when we can't import hooks library.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git-cl-upload-hook
===================================================================
--- git-cl-upload-hook (revision 28888)
+++ git-cl-upload-hook (working copy)
@@ -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(':'):
M-A Ruel 2009/10/15 19:20:46 Shouldn't you use os.pathsep instead of ':' ? I do
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
M-A Ruel 2009/10/15 19:20:46 I think putting the depot_tools_path two times is
+ 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])
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698