OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """A git command for managing a local cache of git repositories.""" | 6 """A git command for managing a local cache of git repositories.""" |
7 | 7 |
8 from __future__ import print_function | 8 from __future__ import print_function |
9 import errno | 9 import errno |
10 import logging | 10 import logging |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 def FindExecutable(executable): | 148 def FindExecutable(executable): |
149 """This mimics the "which" utility.""" | 149 """This mimics the "which" utility.""" |
150 path_folders = os.environ.get('PATH').split(os.pathsep) | 150 path_folders = os.environ.get('PATH').split(os.pathsep) |
151 | 151 |
152 for path_folder in path_folders: | 152 for path_folder in path_folders: |
153 target = os.path.join(path_folder, executable) | 153 target = os.path.join(path_folder, executable) |
154 # Just incase we have some ~/blah paths. | 154 # Just incase we have some ~/blah paths. |
155 target = os.path.abspath(os.path.expanduser(target)) | 155 target = os.path.abspath(os.path.expanduser(target)) |
156 if os.path.isfile(target) and os.access(target, os.X_OK): | 156 if os.path.isfile(target) and os.access(target, os.X_OK): |
157 return target | 157 return target |
158 if sys.platform.startswith('win'): | |
159 for suffix in ('.bat', '.cmd', '.exe'): | |
160 alt_target = target + suffix | |
161 if os.path.isfile(alt_target) and os.access(target, os.X_OK): | |
iannucci
2014/04/10 16:50:48
wouldn't os.access(... X_OK) always return True on
| |
162 return alt_target | |
158 return None | 163 return None |
159 | 164 |
160 @classmethod | 165 @classmethod |
161 def SetCachePath(cls, cachepath): | 166 def SetCachePath(cls, cachepath): |
162 setattr(cls, 'cachepath', cachepath) | 167 setattr(cls, 'cachepath', cachepath) |
163 | 168 |
164 @classmethod | 169 @classmethod |
165 def GetCachePath(cls): | 170 def GetCachePath(cls): |
166 if not hasattr(cls, 'cachepath'): | 171 if not hasattr(cls, 'cachepath'): |
167 try: | 172 try: |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 return options, args | 490 return options, args |
486 | 491 |
487 | 492 |
488 def main(argv): | 493 def main(argv): |
489 dispatcher = subcommand.CommandDispatcher(__name__) | 494 dispatcher = subcommand.CommandDispatcher(__name__) |
490 return dispatcher.execute(OptionParser(), argv) | 495 return dispatcher.execute(OptionParser(), argv) |
491 | 496 |
492 | 497 |
493 if __name__ == '__main__': | 498 if __name__ == '__main__': |
494 sys.exit(main(sys.argv[1:])) | 499 sys.exit(main(sys.argv[1:])) |
OLD | NEW |