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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 return None | 93 return None |
94 assert len(child_nodes) == 1 | 94 assert len(child_nodes) == 1 |
95 return child_nodes[0].getAttribute(attribute_name) | 95 return child_nodes[0].getAttribute(attribute_name) |
96 | 96 |
97 | 97 |
98 class Error(Exception): | 98 class Error(Exception): |
99 """gclient exception class.""" | 99 """gclient exception class.""" |
100 pass | 100 pass |
101 | 101 |
102 | 102 |
| 103 def SyntaxErrorToError(filename, e): |
| 104 """Raises a gclient_utils.Error exception with the human readable message""" |
| 105 try: |
| 106 # Try to construct a human readable error message |
| 107 if filename: |
| 108 error_message = 'There is a syntax error in %s\n' % filename |
| 109 else: |
| 110 error_message = 'There is a syntax error\n' |
| 111 error_message += 'Line #%s, character %s: "%s"' % ( |
| 112 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text)) |
| 113 except: |
| 114 # Something went wrong, re-raise the original exception |
| 115 raise e |
| 116 else: |
| 117 raise Error(error_message) |
| 118 |
| 119 |
103 class PrintableObject(object): | 120 class PrintableObject(object): |
104 def __str__(self): | 121 def __str__(self): |
105 output = '' | 122 output = '' |
106 for i in dir(self): | 123 for i in dir(self): |
107 if i.startswith('__'): | 124 if i.startswith('__'): |
108 continue | 125 continue |
109 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) | 126 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) |
110 return output | 127 return output |
111 | 128 |
112 | 129 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 config_path = FindFileUpwards(config_file, path) | 364 config_path = FindFileUpwards(config_file, path) |
348 | 365 |
349 if not config_path: | 366 if not config_path: |
350 print "Can't find %s" % config_file | 367 print "Can't find %s" % config_file |
351 return None | 368 return None |
352 | 369 |
353 env = {} | 370 env = {} |
354 execfile(config_path, env) | 371 execfile(config_path, env) |
355 config_dir = os.path.dirname(config_path) | 372 config_dir = os.path.dirname(config_path) |
356 return config_dir, env['entries'] | 373 return config_dir, env['entries'] |
OLD | NEW |