| OLD | NEW |
| 1 # Copyright 2009 Google Inc. All Rights Reserved. | 1 # Copyright 2009 Google Inc. All Rights Reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class CheckCallError(OSError): | 28 class CheckCallError(OSError): |
| 29 """CheckCall() returned non-0.""" | 29 """CheckCall() returned non-0.""" |
| 30 def __init__(self, command, cwd, retcode, stdout): | 30 def __init__(self, command, cwd, retcode, stdout): |
| 31 OSError.__init__(self, command, cwd, retcode, stdout) | 31 OSError.__init__(self, command, cwd, retcode, stdout) |
| 32 self.command = command | 32 self.command = command |
| 33 self.cwd = cwd | 33 self.cwd = cwd |
| 34 self.retcode = retcode | 34 self.retcode = retcode |
| 35 self.stdout = stdout | 35 self.stdout = stdout |
| 36 | 36 |
| 37 | 37 |
| 38 def CheckCall(command, cwd=None): | 38 def CheckCall(command, cwd=None, print_error=True): |
| 39 """Like subprocess.check_call() but returns stdout. | 39 """Like subprocess.check_call() but returns stdout. |
| 40 | 40 |
| 41 Works on python 2.4 | 41 Works on python 2.4 |
| 42 """ | 42 """ |
| 43 try: | 43 try: |
| 44 stderr = None |
| 45 if not print_error: |
| 46 stderr = subprocess.PIPE |
| 44 process = subprocess.Popen(command, cwd=cwd, | 47 process = subprocess.Popen(command, cwd=cwd, |
| 45 shell=sys.platform.startswith('win'), | 48 shell=sys.platform.startswith('win'), |
| 46 stdout=subprocess.PIPE) | 49 stdout=subprocess.PIPE, |
| 50 stderr=stderr) |
| 47 output = process.communicate()[0] | 51 output = process.communicate()[0] |
| 48 except OSError, e: | 52 except OSError, e: |
| 49 raise CheckCallError(command, cwd, errno, None) | 53 raise CheckCallError(command, cwd, errno, None) |
| 50 if process.returncode: | 54 if process.returncode: |
| 51 raise CheckCallError(command, cwd, process.returncode, output) | 55 raise CheckCallError(command, cwd, process.returncode, output) |
| 52 return output | 56 return output |
| 53 | 57 |
| 54 | 58 |
| 55 def SplitUrlRevision(url): | 59 def SplitUrlRevision(url): |
| 56 """Splits url and returns a two-tuple: url, rev""" | 60 """Splits url and returns a two-tuple: url, rev""" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 raise Error(msg) | 300 raise Error(msg) |
| 297 | 301 |
| 298 | 302 |
| 299 def IsUsingGit(root, paths): | 303 def IsUsingGit(root, paths): |
| 300 """Returns True if we're using git to manage any of our checkouts. | 304 """Returns True if we're using git to manage any of our checkouts. |
| 301 |entries| is a list of paths to check.""" | 305 |entries| is a list of paths to check.""" |
| 302 for path in paths: | 306 for path in paths: |
| 303 if os.path.exists(os.path.join(root, path, '.git')): | 307 if os.path.exists(os.path.join(root, path, '.git')): |
| 304 return True | 308 return True |
| 305 return False | 309 return False |
| OLD | NEW |