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 """ | 8 """ |
9 submit_try: Submit a try request. | 9 submit_try: Submit a try request. |
10 | 10 |
11 This is a thin wrapper around the try request utilities in depot_tools which | 11 This is a thin wrapper around the try request utilities in depot_tools which |
12 adds some validation and supports both git and svn. | 12 adds some validation and supports both git and svn. |
13 """ | 13 """ |
14 | 14 |
15 | 15 |
16 from contextlib import closing | |
17 | |
18 import httplib | 16 import httplib |
19 import json | 17 import json |
20 import os | 18 import os |
21 import subprocess | 19 import subprocess |
22 import sys | 20 import sys |
23 import urllib2 | 21 |
22 | |
23 if os.name == 'nt': | |
24 SVN = 'svn.bat' | |
25 else: | |
26 SVN = 'svn' | |
24 | 27 |
25 | 28 |
26 def GetGlobalVariables(): | 29 def GetGlobalVariables(): |
27 """ Retrieve a global variable from the global_variables.json file. """ | 30 """ Retrieve a global variable from the global_variables.json file. """ |
28 global_variables_file = ('http://skia.googlecode.com/svn/buildbot/' | 31 global_variables_file = ('http://skia.googlecode.com/svn/buildbot/' |
29 'site_config/global_variables.json') | 32 'site_config/global_variables.json') |
30 with closing(urllib2.urlopen(global_variables_file)) as f: | 33 proc = subprocess.Popen([SVN, 'cat', global_variables_file], |
epoger
2013/03/14 14:51:41
It seems silly to have this subprocess-launching b
borenet
2013/03/14 17:18:05
Done.
| |
31 return json.load(f) | 34 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
35 exitcode = proc.wait() | |
36 if not exitcode == 0: | |
37 raise Exception('Could not retrieve global variables file from %s. ' | |
38 'Check your connection.' % global_variables_file) | |
39 global_variables = proc.communicate()[0] | |
40 return json.loads(global_variables) | |
epoger
2013/03/14 14:51:41
should be json.load() instead of json.loads() ?
s
epoger
2013/03/14 14:54:49
Oh, I see this part is actually fine. Sorry about
borenet
2013/03/14 17:18:05
Removed the whole function, since it shouldn't get
| |
32 | 41 |
33 | 42 |
34 GLOBAL_VARIABLES = GetGlobalVariables() | 43 GLOBAL_VARIABLES = GetGlobalVariables() |
35 | 44 |
36 | 45 |
37 def GetGlobalVariable(var_name): | 46 def GetGlobalVariable(var_name): |
38 return GLOBAL_VARIABLES[var_name]['value'] | 47 return GLOBAL_VARIABLES[var_name]['value'] |
39 | 48 |
40 | 49 |
41 # Alias which can be used to run a try on every builder. | 50 # Alias which can be used to run a try on every builder. |
(...skipping 30 matching lines...) Expand all Loading... | |
72 return depot_tools_dir | 81 return depot_tools_dir |
73 | 82 |
74 | 83 |
75 def GetCheckoutRoot(is_svn=True): | 84 def GetCheckoutRoot(is_svn=True): |
76 """ Determine where the local checkout is rooted. | 85 """ Determine where the local checkout is rooted. |
77 | 86 |
78 is_svn: boolean; whether we're in an SVN checkout. If False, assume we're in | 87 is_svn: boolean; whether we're in an SVN checkout. If False, assume we're in |
79 a git checkout. | 88 a git checkout. |
80 """ | 89 """ |
81 if is_svn: | 90 if is_svn: |
82 svn_cmd = 'svn.bat' if os.name == 'nt' else 'svn' | 91 cmd = [SVN, 'info'] |
83 cmd = [svn_cmd, 'info'] | |
84 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 92 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
85 stderr=subprocess.STDOUT) | 93 stderr=subprocess.STDOUT) |
86 if proc.wait() != 0: | 94 if proc.wait() != 0: |
87 raise Exception('Couldn\'t find checkout root!') | 95 raise Exception('Couldn\'t find checkout root!') |
88 output = proc.communicate()[0].split('\n') | 96 output = proc.communicate()[0].split('\n') |
89 url = None | 97 url = None |
90 repo_root = None | 98 repo_root = None |
91 for line in output: | 99 for line in output: |
92 if line.startswith(REPO_ROOT_STR): | 100 if line.startswith(REPO_ROOT_STR): |
93 repo_root = line[len(REPO_ROOT_STR):].rstrip() | 101 repo_root = line[len(REPO_ROOT_STR):].rstrip() |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 281 |
274 # Parse and validate the command-line arguments. | 282 # Parse and validate the command-line arguments. |
275 args = ValidateArgs(sys.argv[1:], trybots=trybots, is_svn=is_svn) | 283 args = ValidateArgs(sys.argv[1:], trybots=trybots, is_svn=is_svn) |
276 | 284 |
277 # Submit the try request. | 285 # Submit the try request. |
278 SubmitTryRequest(args, is_svn=is_svn) | 286 SubmitTryRequest(args, is_svn=is_svn) |
279 | 287 |
280 | 288 |
281 if __name__ == '__main__': | 289 if __name__ == '__main__': |
282 sys.exit(main()) | 290 sys.exit(main()) |
OLD | NEW |