Chromium Code Reviews| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 If a filter function is specified, it is expected to take a single | 189 If a filter function is specified, it is expected to take a single |
| 190 string argument, and it will be called with each line of the | 190 string argument, and it will be called with each line of the |
| 191 subprocess's output. Each line has had the trailing newline character | 191 subprocess's output. Each line has had the trailing newline character |
| 192 trimmed. | 192 trimmed. |
| 193 | 193 |
| 194 If the command fails, as indicated by a nonzero exit status, gclient will | 194 If the command fails, as indicated by a nonzero exit status, gclient will |
| 195 exit with an exit status of fail_status. If fail_status is None (the | 195 exit with an exit status of fail_status. If fail_status is None (the |
| 196 default), gclient will raise an Error exception. | 196 default), gclient will raise an Error exception. |
| 197 """ | 197 """ |
| 198 | 198 |
| 199 messages_printed = False | |
|
M-A Ruel
2009/10/02 01:23:10
unnecessary
| |
| 199 if print_messages: | 200 if print_messages: |
| 200 print("\n________ running \'%s\' in \'%s\'" | 201 print("\n________ running \'%s\' in \'%s\'" |
| 201 % (' '.join(command), in_directory)) | 202 % (' '.join(command), in_directory)) |
| 203 messages_printed = True | |
| 202 | 204 |
| 203 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the | 205 # *Sigh*: Windows needs shell=True, or else it won't search %PATH% for the |
| 204 # executable, but shell=True makes subprocess on Linux fail when it's called | 206 # executable, but shell=True makes subprocess on Linux fail when it's called |
| 205 # with a list because it only tries to execute the first item in the list. | 207 # with a list because it only tries to execute the first item in the list. |
| 206 kid = subprocess.Popen(command, bufsize=0, cwd=in_directory, | 208 kid = subprocess.Popen(command, bufsize=0, cwd=in_directory, |
| 207 shell=(sys.platform == 'win32'), stdout=subprocess.PIPE) | 209 shell=(sys.platform == 'win32'), stdout=subprocess.PIPE) |
| 208 | 210 |
| 209 # Also, we need to forward stdout to prevent weird re-ordering of output. | 211 # Also, we need to forward stdout to prevent weird re-ordering of output. |
| 210 # This has to be done on a per byte basis to make sure it is not buffered: | 212 # This has to be done on a per byte basis to make sure it is not buffered: |
| 211 # normally buffering is done for each line, but if svn requests input, no | 213 # normally buffering is done for each line, but if svn requests input, no |
| 212 # end-of-line character is output after the prompt and it would not show up. | 214 # end-of-line character is output after the prompt and it would not show up. |
| 213 in_byte = kid.stdout.read(1) | 215 in_byte = kid.stdout.read(1) |
| 214 in_line = "" | 216 in_line = "" |
| 215 while in_byte: | 217 while in_byte: |
| 216 if in_byte != "\r": | 218 if in_byte != "\r": |
| 217 if print_stdout: | 219 if print_stdout: |
| 220 if not messages_printed: | |
|
M-A Ruel
2009/10/02 01:23:10
if not print_messages:
| |
| 221 print("\n________ running \'%s\' in \'%s\'" | |
| 222 % (' '.join(command), in_directory)) | |
| 223 messages_printed = True | |
|
M-A Ruel
2009/10/02 01:23:10
print_messages = True
| |
| 218 sys.stdout.write(in_byte) | 224 sys.stdout.write(in_byte) |
| 219 if in_byte != "\n": | 225 if in_byte != "\n": |
| 220 in_line += in_byte | 226 in_line += in_byte |
| 221 if in_byte == "\n" and filter: | 227 if in_byte == "\n" and filter: |
| 222 filter(in_line) | 228 filter(in_line) |
| 223 in_line = "" | 229 in_line = "" |
| 224 in_byte = kid.stdout.read(1) | 230 in_byte = kid.stdout.read(1) |
| 225 rv = kid.wait() | 231 rv = kid.wait() |
| 226 | 232 |
| 227 if rv: | 233 if rv: |
| 228 msg = "failed to run command: %s" % " ".join(command) | 234 msg = "failed to run command: %s" % " ".join(command) |
| 229 | 235 |
| 230 if fail_status != None: | 236 if fail_status != None: |
| 231 print >>sys.stderr, msg | 237 print >>sys.stderr, msg |
| 232 sys.exit(fail_status) | 238 sys.exit(fail_status) |
| 233 | 239 |
| 234 raise Error(msg) | 240 raise Error(msg) |
| 235 | 241 |
| 236 | 242 |
| 237 def IsUsingGit(root, paths): | 243 def IsUsingGit(root, paths): |
| 238 """Returns True if we're using git to manage any of our checkouts. | 244 """Returns True if we're using git to manage any of our checkouts. |
| 239 |entries| is a list of paths to check.""" | 245 |entries| is a list of paths to check.""" |
| 240 for path in paths: | 246 for path in paths: |
| 241 if os.path.exists(os.path.join(root, path, '.git')): | 247 if os.path.exists(os.path.join(root, path, '.git')): |
| 242 return True | 248 return True |
| 243 return False | 249 return False |
| OLD | NEW |