OLD | NEW |
(Empty) | |
| 1 #!/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 |
| 6 import optparse |
| 7 import os |
| 8 import sys |
| 9 from subprocess import Popen, PIPE |
| 10 |
| 11 # Try locating depot_tools from the user's PATH. |
| 12 depot_tools_path = None |
| 13 |
| 14 # First parse PATH if there's a "depot_tools" inside |
| 15 for path in os.environ.get("PATH").split(os.pathsep): |
| 16 if not path.endswith("depot_tools") and not path.endswith("depot_tools/"): |
| 17 continue |
| 18 depot_tools_path = path |
| 19 break |
| 20 |
| 21 # If depot_tools dir is not called depot_tools, or other weirdness |
| 22 if not depot_tools_path: |
| 23 # Grab a `which gclient', which gives first match |
| 24 # `which' also uses PATH, but is not restricted to specific directory name |
| 25 path = Popen(["which", "gclient"], stdout=PIPE).communicate()[0].strip() |
| 26 if path: |
| 27 depot_tools_path = path.replace("/gclient","") |
| 28 |
| 29 # If we found depot_tools, add it to the script's import path. |
| 30 # Use realpath to normalize the actual path |
| 31 if depot_tools_path: |
| 32 sys.path.insert(0, os.path.realpath(depot_tools_path)) |
| 33 else: |
| 34 print "ERROR: Could not find depot_tools in your PATH." |
| 35 print "ERROR: Please add it to your PATH and try again." |
| 36 sys.exit(1) |
| 37 |
| 38 # Try importing git_cl_hooks from depot_tools. |
| 39 try: |
| 40 import git_cl_hooks |
| 41 except ImportError: |
| 42 print "ERROR: Could not import git_cl_hooks from depot_tools in your PATH." |
| 43 print "ERROR: Make sure %s is up-to-date and try again." % depot_tools_path |
| 44 sys.exit(1) |
| 45 |
| 46 parser = optparse.OptionParser() |
| 47 parser.set_usage('%prog [options] <upstream-branch>') |
| 48 parser.add_option('--tbr', action='store_true', default=False, |
| 49 help='skip checks for reviewers, owners') |
| 50 parser.add_option('--host-url', default=None, |
| 51 help='scheme, origin, and port for Rietveld server') |
| 52 options, args = parser.parse_args() |
| 53 if len(args) != 1: |
| 54 parser.print_help() |
| 55 sys.exit(1) |
| 56 |
| 57 # Run the hooks library with our arguments. |
| 58 exec git_cl_hooks.RunHooks(hook_name=parser.get_prog_name(), |
| 59 upstream_branch=args[0], |
| 60 cmd_line_options=options) |
OLD | NEW |