OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generic utils.""" | 5 """Generic utils.""" |
6 | 6 |
7 import errno | 7 import errno |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import Queue | 10 import Queue |
11 import re | 11 import re |
12 import stat | 12 import stat |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import threading | 15 import threading |
16 import time | 16 import time |
| 17 import xml.dom.minidom |
| 18 import xml.parsers.expat |
17 | 19 |
18 | 20 |
19 def hack_subprocess(): | 21 def hack_subprocess(): |
20 """subprocess functions may throw exceptions when used in multiple threads. | 22 """subprocess functions may throw exceptions when used in multiple threads. |
21 | 23 |
22 See http://bugs.python.org/issue1731717 for more information. | 24 See http://bugs.python.org/issue1731717 for more information. |
23 """ | 25 """ |
24 subprocess._cleanup = lambda: None | 26 subprocess._cleanup = lambda: None |
25 | 27 |
26 | 28 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 # Make sure ssh://user-name@example.com/~/test.git@stable works | 107 # Make sure ssh://user-name@example.com/~/test.git@stable works |
106 regex = r'(ssh://(?:[-\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' | 108 regex = r'(ssh://(?:[-\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' |
107 components = re.search(regex, url).groups() | 109 components = re.search(regex, url).groups() |
108 else: | 110 else: |
109 components = url.split('@', 1) | 111 components = url.split('@', 1) |
110 if len(components) == 1: | 112 if len(components) == 1: |
111 components += [None] | 113 components += [None] |
112 return tuple(components) | 114 return tuple(components) |
113 | 115 |
114 | 116 |
| 117 def ParseXML(output): |
| 118 try: |
| 119 return xml.dom.minidom.parseString(output) |
| 120 except xml.parsers.expat.ExpatError: |
| 121 return None |
| 122 |
| 123 |
| 124 def GetNamedNodeText(node, node_name): |
| 125 child_nodes = node.getElementsByTagName(node_name) |
| 126 if not child_nodes: |
| 127 return None |
| 128 assert len(child_nodes) == 1 and child_nodes[0].childNodes.length == 1 |
| 129 return child_nodes[0].firstChild.nodeValue |
| 130 |
| 131 |
| 132 def GetNodeNamedAttributeText(node, node_name, attribute_name): |
| 133 child_nodes = node.getElementsByTagName(node_name) |
| 134 if not child_nodes: |
| 135 return None |
| 136 assert len(child_nodes) == 1 |
| 137 return child_nodes[0].getAttribute(attribute_name) |
| 138 |
| 139 |
115 def SyntaxErrorToError(filename, e): | 140 def SyntaxErrorToError(filename, e): |
116 """Raises a gclient_utils.Error exception with the human readable message""" | 141 """Raises a gclient_utils.Error exception with the human readable message""" |
117 try: | 142 try: |
118 # Try to construct a human readable error message | 143 # Try to construct a human readable error message |
119 if filename: | 144 if filename: |
120 error_message = 'There is a syntax error in %s\n' % filename | 145 error_message = 'There is a syntax error in %s\n' % filename |
121 else: | 146 else: |
122 error_message = 'There is a syntax error\n' | 147 error_message = 'There is a syntax error\n' |
123 error_message += 'Line #%s, character %s: "%s"' % ( | 148 error_message += 'Line #%s, character %s: "%s"' % ( |
124 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) | 149 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 logging.info('Caught exception in thread %s' % self.item.name) | 703 logging.info('Caught exception in thread %s' % self.item.name) |
679 logging.info(str(sys.exc_info())) | 704 logging.info(str(sys.exc_info())) |
680 work_queue.exceptions.put(sys.exc_info()) | 705 work_queue.exceptions.put(sys.exc_info()) |
681 logging.info('Task %s done' % self.item.name) | 706 logging.info('Task %s done' % self.item.name) |
682 | 707 |
683 work_queue.ready_cond.acquire() | 708 work_queue.ready_cond.acquire() |
684 try: | 709 try: |
685 work_queue.ready_cond.notifyAll() | 710 work_queue.ready_cond.notifyAll() |
686 finally: | 711 finally: |
687 work_queue.ready_cond.release() | 712 work_queue.ready_cond.release() |
OLD | NEW |