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 import json | 11 import json |
12 import svn | 12 import svn |
13 | 13 |
14 _global_vars = None | 14 _global_vars = None |
15 | 15 |
16 | |
17 GLOBAL_VARS_JSON_URL = ('http://skia.googlecode.com/svn/buildbot/site_config/' | |
epoger
2013/12/02 18:36:28
Personally, I would write it this way so the URL w
borenet
2013/12/02 20:22:24
Done.
| |
18 'global_variables.json') | |
19 | |
20 | |
21 class GlobalVarsRetrievalError(Exception): | |
epoger
2013/12/02 18:36:28
Please add docstrings giving a brief description o
borenet
2013/12/02 20:22:24
Done.
| |
22 pass | |
23 | |
24 | |
25 class JsonDecodeError(Exception): | |
rmistry
2013/12/02 14:57:12
simplejson has a JSONDecodeError. Also, I wonder i
borenet
2013/12/02 16:26:29
Probably a good decision in the long run. All I c
rmistry
2013/12/02 16:28:24
Makes sense.
| |
26 pass | |
27 | |
28 | |
16 class NoSuchGlobalVariable(KeyError): | 29 class NoSuchGlobalVariable(KeyError): |
17 pass | 30 pass |
18 | 31 |
32 | |
19 def Get(var_name): | 33 def Get(var_name): |
20 '''Return the value associated with this name in global_variables.json. | 34 '''Return the value associated with this name in global_variables.json. |
21 Raises NoSuchGlobalVariable if there is no variable with that name.''' | 35 Raises NoSuchGlobalVariable if there is no variable with that name.''' |
22 global _global_vars | 36 global _global_vars |
23 if not _global_vars: | 37 if not _global_vars: |
24 _global_vars = json.loads(svn.Cat('http://skia.googlecode.com/svn/' | 38 try: |
25 'buildbot/site_config/' | 39 global_vars_text = svn.Cat(GLOBAL_VARS_JSON_URL) |
26 'global_variables.json')) | 40 except Exception: |
epoger
2013/12/02 18:36:28
TL;DR : this is fine. :-)
I wondered what the pro
borenet
2013/12/02 20:22:24
Yeah, I guess this isn't ideal, but losing the sta
| |
41 raise GlobalVarsRetrievalError('Failed to retrieve %s.' % | |
42 GLOBAL_VARS_JSON_URL) | |
43 try: | |
44 _global_vars = json.loads(global_vars_text) | |
45 except ValueError as e: | |
46 raise JsonDecodeError(e.message + '\n' + global_vars_text) | |
27 try: | 47 try: |
28 return _global_vars[var_name]['value'] | 48 return _global_vars[var_name]['value'] |
29 except KeyError: | 49 except KeyError: |
30 raise NoSuchGlobalVariable(var_name) | 50 raise NoSuchGlobalVariable(var_name) |
OLD | NEW |