OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 # Find depot_tools in PATH, append it to sys.path so we can import. | 9 # Try locating depot_tools from the user's PATH. |
10 paths = os.environ.get("PATH") | 10 depot_tools_path = None |
11 for path in paths.split(':'): | 11 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
| |
12 if not path.endswith("depot_tools"): | 12 if not path.endswith("depot_tools"): |
13 continue | 13 continue |
14 sys.path.append(path) | 14 depot_tools_path = path |
15 break | 15 break |
16 | 16 |
17 import git_cl_hooks | 17 # If we found depot_tools, add it to the script's import path. |
18 if depot_tools_path: | |
19 sys.path.append(depot_tools_path) | |
20 else: | |
21 print "ERROR: Could not find depot_tools in your PATH." | |
22 print "ERROR: Please add it to your PATH and try again." | |
23 sys.exit(1) | |
24 | |
25 # Try importing git_cl_hooks from depot_tools. | |
26 try: | |
27 import git_cl_hooks | |
28 except ImportError: | |
29 print ("ERROR: Could not import git_cl_hooks from your depot_tools at %s." % | |
30 depot_tools_path) | |
31 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
| |
32 sys.exit(1) | |
18 | 33 |
19 # Ensure we were called with the necessary number of arguments. | 34 # Ensure we were called with the necessary number of arguments. |
20 program_name = os.path.basename(sys.argv[0]) | 35 program_name = os.path.basename(sys.argv[0]) |
21 if len(sys.argv) != 2: | 36 if len(sys.argv) != 2: |
22 raise Exception("usage: %s [upstream branch]" % program_name) | 37 print "usage: %s [upstream branch]" % program_name |
38 sys.exit(1) | |
23 | 39 |
24 # Run the hooks library with our arguments. | 40 # Run the hooks library with our arguments. |
25 exec git_cl_hooks.RunHooks(hook_name=program_name, upstream_branch=sys.argv[1]) | 41 exec git_cl_hooks.RunHooks(hook_name=program_name, upstream_branch=sys.argv[1]) |
OLD | NEW |