Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: tools/buildbot_globals.py

Issue 873593005: Cleanup: Delete buildbot_globals.py script. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2
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
5 # found in the LICENSE file.
6
7 """
8 Provides read access to buildbot's global_variables.json .
9 """
10
11
12 import json
13 import retrieve_from_googlesource
14 import sys
15
16
17 _global_vars = None
18
19
20 SKIABOT_REPO = 'https://skia.googlesource.com/buildbot'
21 _GLOBAL_VARS_PATH = 'site_config/global_variables.json'
22
23
24 class GlobalVarsRetrievalError(Exception):
25 """Exception which is raised when the global_variables.json file cannot be
26 retrieved from the Skia buildbot repository."""
27 pass
28
29
30 class JsonDecodeError(Exception):
31 """Exception which is raised when the global_variables.json file cannot be
32 interpreted as JSON. This may be due to the file itself being incorrectly
33 formatted or due to an incomplete or corrupted downloaded version of the file.
34 """
35 pass
36
37
38 class NoSuchGlobalVariable(KeyError):
39 """Exception which is raised when a given variable is not found in the
40 global_variables.json file."""
41 pass
42
43
44 def Get(var_name):
45 """Return the value associated with this name in global_variables.json.
46
47 Args:
48 var_name: string; the variable to look up.
49 Returns:
50 The value of the variable.
51 Raises:
52 NoSuchGlobalVariable if there is no variable with that name.
53 """
54 global _global_vars
55 if not _global_vars:
56 try:
57 global_vars_text = retrieve_from_googlesource.get(SKIABOT_REPO,
58 _GLOBAL_VARS_PATH)
59 except Exception as e:
60 raise GlobalVarsRetrievalError('Failed to retrieve %s from %s:\n%s' %
61 (_GLOBAL_VARS_PATH, SKIABOT_REPO, str(e)))
62 try:
63 _global_vars = json.loads(global_vars_text)
64 except ValueError as e:
65 raise JsonDecodeError(e.message + '\n' + global_vars_text)
66 try:
67 return _global_vars[var_name]['value']
68 except KeyError:
69 raise NoSuchGlobalVariable(var_name)
70
71
72 if __name__ == '__main__':
73 print Get(sys.argv[1])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698