| 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 23 matching lines...) Expand all Loading... |
| 34 self.cwd = cwd | 34 self.cwd = cwd |
| 35 self.retcode = retcode | 35 self.retcode = retcode |
| 36 self.stdout = stdout | 36 self.stdout = stdout |
| 37 | 37 |
| 38 | 38 |
| 39 def CheckCall(command, cwd=None, print_error=True): | 39 def CheckCall(command, cwd=None, print_error=True): |
| 40 """Like subprocess.check_call() but returns stdout. | 40 """Like subprocess.check_call() but returns stdout. |
| 41 | 41 |
| 42 Works on python 2.4 | 42 Works on python 2.4 |
| 43 """ | 43 """ |
| 44 logging.debug(command) | 44 logging.debug("%s, cwd=%s" % (str(command), str(cwd))) |
| 45 try: | 45 try: |
| 46 stderr = None | 46 stderr = None |
| 47 if not print_error: | 47 if not print_error: |
| 48 stderr = subprocess.PIPE | 48 stderr = subprocess.PIPE |
| 49 process = subprocess.Popen(command, cwd=cwd, | 49 process = subprocess.Popen(command, cwd=cwd, |
| 50 shell=sys.platform.startswith('win'), | 50 shell=sys.platform.startswith('win'), |
| 51 stdout=subprocess.PIPE, | 51 stdout=subprocess.PIPE, |
| 52 stderr=stderr) | 52 stderr=stderr) |
| 53 output = process.communicate()[0] | 53 output = process.communicate()[0] |
| 54 except OSError, e: | 54 except OSError, e: |
| 55 raise CheckCallError(command, cwd, errno, None) | 55 raise CheckCallError(command, cwd, e.errno, None) |
| 56 if process.returncode: | 56 if process.returncode: |
| 57 raise CheckCallError(command, cwd, process.returncode, output) | 57 raise CheckCallError(command, cwd, process.returncode, output) |
| 58 return output | 58 return output |
| 59 | 59 |
| 60 | 60 |
| 61 def SplitUrlRevision(url): | 61 def SplitUrlRevision(url): |
| 62 """Splits url and returns a two-tuple: url, rev""" | 62 """Splits url and returns a two-tuple: url, rev""" |
| 63 if url.startswith('ssh:'): | 63 if url.startswith('ssh:'): |
| 64 # Make sure ssh://test@example.com/test.git@stable works | 64 # Make sure ssh://test@example.com/test.git@stable works |
| 65 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?" | 65 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 """Returns the difference subpath minus root.""" | 326 """Returns the difference subpath minus root.""" |
| 327 root = os.path.realpath(root) | 327 root = os.path.realpath(root) |
| 328 subpath = os.path.realpath(subpath) | 328 subpath = os.path.realpath(subpath) |
| 329 if not subpath.startswith(root): | 329 if not subpath.startswith(root): |
| 330 return None | 330 return None |
| 331 # If the root does not have a trailing \ or /, we add it so the returned | 331 # If the root does not have a trailing \ or /, we add it so the returned |
| 332 # path starts immediately after the seperator regardless of whether it is | 332 # path starts immediately after the seperator regardless of whether it is |
| 333 # provided. | 333 # provided. |
| 334 root = os.path.join(root, '') | 334 root = os.path.join(root, '') |
| 335 return subpath[len(root):] | 335 return subpath[len(root):] |
| OLD | NEW |