| 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 = ( |
| 18 'http://skia.googlecode.com/svn/buildbot/site_config/global_variables.json') |
| 19 |
| 20 |
| 21 class GlobalVarsRetrievalError(Exception): |
| 22 """Exception which is raised when the global_variables.json file cannot be |
| 23 retrieved from the Skia buildbot repository.""" |
| 24 pass |
| 25 |
| 26 |
| 27 class JsonDecodeError(Exception): |
| 28 """Exception which is raised when the global_variables.json file cannot be |
| 29 interpreted as JSON. This may be due to the file itself being incorrectly |
| 30 formatted or due to an incomplete or corrupted downloaded version of the file. |
| 31 """ |
| 32 pass |
| 33 |
| 34 |
| 16 class NoSuchGlobalVariable(KeyError): | 35 class NoSuchGlobalVariable(KeyError): |
| 36 """Exception which is raised when a given variable is not found in the |
| 37 global_variables.json file.""" |
| 17 pass | 38 pass |
| 18 | 39 |
| 40 |
| 19 def Get(var_name): | 41 def Get(var_name): |
| 20 '''Return the value associated with this name in global_variables.json. | 42 '''Return the value associated with this name in global_variables.json. |
| 21 Raises NoSuchGlobalVariable if there is no variable with that name.''' | 43 Raises NoSuchGlobalVariable if there is no variable with that name.''' |
| 22 global _global_vars | 44 global _global_vars |
| 23 if not _global_vars: | 45 if not _global_vars: |
| 24 _global_vars = json.loads(svn.Cat('http://skia.googlecode.com/svn/' | 46 try: |
| 25 'buildbot/site_config/' | 47 global_vars_text = svn.Cat(GLOBAL_VARS_JSON_URL) |
| 26 'global_variables.json')) | 48 except Exception: |
| 49 raise GlobalVarsRetrievalError('Failed to retrieve %s.' % |
| 50 GLOBAL_VARS_JSON_URL) |
| 51 try: |
| 52 _global_vars = json.loads(global_vars_text) |
| 53 except ValueError as e: |
| 54 raise JsonDecodeError(e.message + '\n' + global_vars_text) |
| 27 try: | 55 try: |
| 28 return _global_vars[var_name]['value'] | 56 return _global_vars[var_name]['value'] |
| 29 except KeyError: | 57 except KeyError: |
| 30 raise NoSuchGlobalVariable(var_name) | 58 raise NoSuchGlobalVariable(var_name) |
| OLD | NEW |