OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 Provides read access to buildbot's global_variables.json . | 8 Provides read access to buildbot's global_variables.json . |
9 """ | 9 """ |
10 | 10 |
11 | 11 |
12 from contextlib import closing | |
13 | |
14 import HTMLParser | 12 import HTMLParser |
15 import base64 | |
16 import json | 13 import json |
17 import re | 14 import re |
| 15 import retrieve_from_googlesource |
18 import svn | 16 import svn |
19 import sys | 17 import sys |
20 import urllib2 | |
21 | 18 |
22 | 19 |
23 _global_vars = None | 20 _global_vars = None |
24 | 21 |
25 | 22 |
26 _GLOBAL_VARS_JSON_BASE64_URL = ( | 23 _GLOBAL_VARS_JSON_BASE64_URL = ( |
27 'https://skia.googlesource.com/buildbot/+/master/' | 24 'https://skia.googlesource.com/buildbot/+/master/' |
28 'site_config/global_variables.json?format=TEXT') | 25 'site_config/global_variables.json?format=TEXT') |
29 | 26 |
30 | 27 |
(...skipping 23 matching lines...) Expand all Loading... |
54 Args: | 51 Args: |
55 var_name: string; the variable to look up. | 52 var_name: string; the variable to look up. |
56 Returns: | 53 Returns: |
57 The value of the variable. | 54 The value of the variable. |
58 Raises: | 55 Raises: |
59 NoSuchGlobalVariable if there is no variable with that name. | 56 NoSuchGlobalVariable if there is no variable with that name. |
60 """ | 57 """ |
61 global _global_vars | 58 global _global_vars |
62 if not _global_vars: | 59 if not _global_vars: |
63 try: | 60 try: |
64 with closing(urllib2.urlopen(_GLOBAL_VARS_JSON_BASE64_URL)) as f: | 61 retrieve_from_googlesource.retrieve_from_googlesource( |
65 global_vars_text = base64.b64decode(f.read()) | 62 _GLOBAL_VARS_JSON_BASE64_URL) |
66 except Exception as e: | 63 except Exception as e: |
67 raise GlobalVarsRetrievalError('Failed to retrieve %s:\n%s' % | 64 raise GlobalVarsRetrievalError('Failed to retrieve %s:\n%s' % |
68 (_GLOBAL_VARS_JSON_BASE64_URL, str(e))) | 65 (_GLOBAL_VARS_JSON_BASE64_URL, str(e))) |
69 try: | 66 try: |
70 _global_vars = json.loads(global_vars_text) | 67 _global_vars = json.loads(global_vars_text) |
71 except ValueError as e: | 68 except ValueError as e: |
72 raise JsonDecodeError(e.message + '\n' + global_vars_text) | 69 raise JsonDecodeError(e.message + '\n' + global_vars_text) |
73 try: | 70 try: |
74 return _global_vars[var_name]['value'] | 71 return _global_vars[var_name]['value'] |
75 except KeyError: | 72 except KeyError: |
76 raise NoSuchGlobalVariable(var_name) | 73 raise NoSuchGlobalVariable(var_name) |
77 | 74 |
78 | 75 |
79 if __name__ == '__main__': | 76 if __name__ == '__main__': |
80 print Get(sys.argv[1]) | 77 print Get(sys.argv[1]) |
OLD | NEW |