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 | |
19 | 17 |
20 | 18 |
21 def hack_subprocess(): | 19 def hack_subprocess(): |
22 """subprocess functions may throw exceptions when used in multiple threads. | 20 """subprocess functions may throw exceptions when used in multiple threads. |
23 | 21 |
24 See http://bugs.python.org/issue1731717 for more information. | 22 See http://bugs.python.org/issue1731717 for more information. |
25 """ | 23 """ |
26 subprocess._cleanup = lambda: None | 24 subprocess._cleanup = lambda: None |
27 | 25 |
28 | 26 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 # Make sure ssh://user-name@example.com/~/test.git@stable works | 105 # Make sure ssh://user-name@example.com/~/test.git@stable works |
108 regex = r'(ssh://(?:[-\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' | 106 regex = r'(ssh://(?:[-\w]+@)?[-\w:\.]+/[-~\w\./]+)(?:@(.+))?' |
109 components = re.search(regex, url).groups() | 107 components = re.search(regex, url).groups() |
110 else: | 108 else: |
111 components = url.split('@', 1) | 109 components = url.split('@', 1) |
112 if len(components) == 1: | 110 if len(components) == 1: |
113 components += [None] | 111 components += [None] |
114 return tuple(components) | 112 return tuple(components) |
115 | 113 |
116 | 114 |
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 | |
140 def SyntaxErrorToError(filename, e): | 115 def SyntaxErrorToError(filename, e): |
141 """Raises a gclient_utils.Error exception with the human readable message""" | 116 """Raises a gclient_utils.Error exception with the human readable message""" |
142 try: | 117 try: |
143 # Try to construct a human readable error message | 118 # Try to construct a human readable error message |
144 if filename: | 119 if filename: |
145 error_message = 'There is a syntax error in %s\n' % filename | 120 error_message = 'There is a syntax error in %s\n' % filename |
146 else: | 121 else: |
147 error_message = 'There is a syntax error\n' | 122 error_message = 'There is a syntax error\n' |
148 error_message += 'Line #%s, character %s: "%s"' % ( | 123 error_message += 'Line #%s, character %s: "%s"' % ( |
149 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) | 124 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 logging.info('Caught exception in thread %s' % self.item.name) | 678 logging.info('Caught exception in thread %s' % self.item.name) |
704 logging.info(str(sys.exc_info())) | 679 logging.info(str(sys.exc_info())) |
705 work_queue.exceptions.put(sys.exc_info()) | 680 work_queue.exceptions.put(sys.exc_info()) |
706 logging.info('Task %s done' % self.item.name) | 681 logging.info('Task %s done' % self.item.name) |
707 | 682 |
708 work_queue.ready_cond.acquire() | 683 work_queue.ready_cond.acquire() |
709 try: | 684 try: |
710 work_queue.ready_cond.notifyAll() | 685 work_queue.ready_cond.notifyAll() |
711 finally: | 686 finally: |
712 work_queue.ready_cond.release() | 687 work_queue.ready_cond.release() |
OLD | NEW |