| 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, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 """Generic utils.""" | 15 """Generic utils.""" |
| 16 | 16 |
| 17 import errno | 17 import errno |
| 18 import logging | 18 import logging |
| 19 import os | 19 import os |
| 20 import re | 20 import re |
| 21 import stat | 21 import stat |
| 22 import subprocess | 22 import subprocess |
| 23 import sys | 23 import sys |
| 24 import threading | 24 import threading |
| 25 import time | 25 import time |
| 26 import xml.dom.minidom | 26 import xml.dom.minidom |
| 27 import xml.parsers.expat | 27 import xml.parsers.expat |
| 28 | 28 |
| 29 | 29 |
| 30 class CheckCallError(OSError): | 30 class Error(Exception): |
| 31 """gclient exception class.""" |
| 32 pass |
| 33 |
| 34 |
| 35 class CheckCallError(OSError, Error): |
| 31 """CheckCall() returned non-0.""" | 36 """CheckCall() returned non-0.""" |
| 32 def __init__(self, command, cwd, retcode, stdout, stderr=None): | 37 def __init__(self, command, cwd, returncode, stdout, stderr=None): |
| 33 OSError.__init__(self, command, cwd, retcode, stdout, stderr) | 38 OSError.__init__(self, command, cwd, returncode, stdout, stderr) |
| 39 Error.__init__(self) |
| 34 self.command = command | 40 self.command = command |
| 35 self.cwd = cwd | 41 self.cwd = cwd |
| 36 self.retcode = retcode | 42 self.returncode = returncode |
| 37 self.stdout = stdout | 43 self.stdout = stdout |
| 38 self.stderr = stderr | 44 self.stderr = stderr |
| 39 | 45 |
| 40 | 46 |
| 41 def Popen(args, **kwargs): | 47 def Popen(args, **kwargs): |
| 42 """Calls subprocess.Popen() with hacks to work around certain behaviors. | 48 """Calls subprocess.Popen() with hacks to work around certain behaviors. |
| 43 | 49 |
| 44 Ensure English outpout for svn and make it work reliably on Windows. | 50 Ensure English outpout for svn and make it work reliably on Windows. |
| 45 """ | 51 """ |
| 46 logging.debug(u'%s, cwd=%s' % (u' '.join(args), kwargs.get('cwd', ''))) | 52 logging.debug(u'%s, cwd=%s' % (u' '.join(args), kwargs.get('cwd', ''))) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 110 |
| 105 | 111 |
| 106 def GetNodeNamedAttributeText(node, node_name, attribute_name): | 112 def GetNodeNamedAttributeText(node, node_name, attribute_name): |
| 107 child_nodes = node.getElementsByTagName(node_name) | 113 child_nodes = node.getElementsByTagName(node_name) |
| 108 if not child_nodes: | 114 if not child_nodes: |
| 109 return None | 115 return None |
| 110 assert len(child_nodes) == 1 | 116 assert len(child_nodes) == 1 |
| 111 return child_nodes[0].getAttribute(attribute_name) | 117 return child_nodes[0].getAttribute(attribute_name) |
| 112 | 118 |
| 113 | 119 |
| 114 class Error(Exception): | |
| 115 """gclient exception class.""" | |
| 116 # TODO(maruel): Merge with CheckCallError. | |
| 117 pass | |
| 118 | |
| 119 | |
| 120 def SyntaxErrorToError(filename, e): | 120 def SyntaxErrorToError(filename, e): |
| 121 """Raises a gclient_utils.Error exception with the human readable message""" | 121 """Raises a gclient_utils.Error exception with the human readable message""" |
| 122 try: | 122 try: |
| 123 # Try to construct a human readable error message | 123 # Try to construct a human readable error message |
| 124 if filename: | 124 if filename: |
| 125 error_message = 'There is a syntax error in %s\n' % filename | 125 error_message = 'There is a syntax error in %s\n' % filename |
| 126 else: | 126 else: |
| 127 error_message = 'There is a syntax error\n' | 127 error_message = 'There is a syntax error\n' |
| 128 error_message += 'Line #%s, character %s: "%s"' % ( | 128 error_message += 'Line #%s, character %s: "%s"' % ( |
| 129 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) | 129 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 if exception: | 525 if exception: |
| 526 self.parent.exceptions.append(exception) | 526 self.parent.exceptions.append(exception) |
| 527 if self.parent.progress: | 527 if self.parent.progress: |
| 528 self.parent.progress.update(1) | 528 self.parent.progress.update(1) |
| 529 assert not self.item.name in self.parent.ran | 529 assert not self.item.name in self.parent.ran |
| 530 if not self.item.name in self.parent.ran: | 530 if not self.item.name in self.parent.ran: |
| 531 self.parent.ran.append(self.item.name) | 531 self.parent.ran.append(self.item.name) |
| 532 finally: | 532 finally: |
| 533 self.parent.ready_cond.notifyAll() | 533 self.parent.ready_cond.notifyAll() |
| 534 self.parent.ready_cond.release() | 534 self.parent.ready_cond.release() |
| OLD | NEW |