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 |
| 20 import svn |
22 import sys | 21 import sys |
23 import urllib2 | |
24 | 22 |
25 | 23 |
26 def GetGlobalVariables(): | 24 GLOBAL_VARIABLES = json.loads(svn.Svn.Cat('http://skia.googlecode.com/svn/' |
27 """ Retrieve a global variable from the global_variables.json file. """ | 25 'buildbot/site_config/' |
28 global_variables_file = ('http://skia.googlecode.com/svn/buildbot/' | 26 'global_variables.json')) |
29 'site_config/global_variables.json') | |
30 with closing(urllib2.urlopen(global_variables_file)) as f: | |
31 return json.load(f) | |
32 | |
33 | |
34 GLOBAL_VARIABLES = GetGlobalVariables() | |
35 | 27 |
36 | 28 |
37 def GetGlobalVariable(var_name): | 29 def GetGlobalVariable(var_name): |
38 return GLOBAL_VARIABLES[var_name]['value'] | 30 return GLOBAL_VARIABLES[var_name]['value'] |
39 | 31 |
40 | 32 |
41 # Alias which can be used to run a try on every builder. | 33 # Alias which can be used to run a try on every builder. |
42 ALL_BUILDERS = 'all' | 34 ALL_BUILDERS = 'all' |
43 | 35 |
44 # Contact information for the build master. | 36 # Contact information for the build master. |
45 SKIA_BUILD_MASTER_HOST = str(GetGlobalVariable('master_host')) | 37 SKIA_BUILD_MASTER_HOST = str(GetGlobalVariable('master_host')) |
46 SKIA_BUILD_MASTER_PORT = str(GetGlobalVariable('external_port')) | 38 SKIA_BUILD_MASTER_PORT = str(GetGlobalVariable('external_port')) |
47 | 39 |
48 # All try builders have this suffix. | 40 # All try builders have this suffix. |
49 TRYBOT_SUFFIX = '_Trybot' | 41 TRYBOT_SUFFIX = '_Trybot' |
50 | 42 |
51 # Location of the codereview.settings file in the Skia repo. | 43 # Location of the codereview.settings file in the Skia repo. |
52 SKIA_URL = 'skia.googlecode.com' | 44 SKIA_URL = 'skia.googlecode.com' |
53 CODEREVIEW_SETTINGS = '/svn/codereview.settings' | 45 CODEREVIEW_SETTINGS = '/svn/codereview.settings' |
54 | 46 |
55 # String for matching the svn url of the try server inside codereview.settings. | 47 # String for matching the svn url of the try server inside codereview.settings. |
56 TRYSERVER_SVN_URL = 'TRYSERVER_SVN_URL: ' | 48 TRYSERVER_SVN_URL = 'TRYSERVER_SVN_URL: ' |
57 | 49 |
58 # Strings used for matching svn config properties. | 50 # Strings used for matching svn config properties. |
59 URL_STR = 'URL: ' | 51 URL_STR = 'URL' |
60 REPO_ROOT_STR = 'Repository Root: ' | 52 REPO_ROOT_STR = 'Repository Root' |
61 | 53 |
62 | 54 |
63 def FindDepotTools(): | 55 def FindDepotTools(): |
64 """ Find depot_tools on the local machine and return its location. """ | 56 """ Find depot_tools on the local machine and return its location. """ |
65 which_cmd = 'where' if os.name == 'nt' else 'which' | 57 which_cmd = 'where' if os.name == 'nt' else 'which' |
66 cmd = [which_cmd, 'gcl'] | 58 cmd = [which_cmd, 'gcl'] |
67 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 59 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
68 if proc.wait() != 0: | 60 if proc.wait() != 0: |
69 raise Exception('Couldn\'t find depot_tools in PATH!') | 61 raise Exception('Couldn\'t find depot_tools in PATH!') |
70 gcl = proc.communicate()[0].split('\n')[0].rstrip() | 62 gcl = proc.communicate()[0].split('\n')[0].rstrip() |
71 depot_tools_dir = os.path.dirname(gcl) | 63 depot_tools_dir = os.path.dirname(gcl) |
72 return depot_tools_dir | 64 return depot_tools_dir |
73 | 65 |
74 | 66 |
75 def GetCheckoutRoot(is_svn=True): | 67 def GetCheckoutRoot(is_svn=True): |
76 """ Determine where the local checkout is rooted. | 68 """ Determine where the local checkout is rooted. |
77 | 69 |
78 is_svn: boolean; whether we're in an SVN checkout. If False, assume we're in | 70 is_svn: boolean; whether we're in an SVN checkout. If False, assume we're in |
79 a git checkout. | 71 a git checkout. |
80 """ | 72 """ |
81 if is_svn: | 73 if is_svn: |
82 svn_cmd = 'svn.bat' if os.name == 'nt' else 'svn' | 74 repo = svn.Svn(os.curdir) |
83 cmd = [svn_cmd, 'info'] | 75 svn_info = repo.GetInfo() |
84 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 76 url = svn_info.get(URL_STR, None) |
85 stderr=subprocess.STDOUT) | 77 repo_root = svn_info.get(REPO_ROOT_STR, None) |
86 if proc.wait() != 0: | |
87 raise Exception('Couldn\'t find checkout root!') | |
88 output = proc.communicate()[0].split('\n') | |
89 url = None | |
90 repo_root = None | |
91 for line in output: | |
92 if line.startswith(REPO_ROOT_STR): | |
93 repo_root = line[len(REPO_ROOT_STR):].rstrip() | |
94 elif line.startswith(URL_STR): | |
95 url = line[len(URL_STR):].rstrip() | |
96 if not url or not repo_root: | 78 if not url or not repo_root: |
97 raise Exception('Couldn\'t find checkout root!') | 79 raise Exception('Couldn\'t find checkout root!') |
98 if url == repo_root: | 80 if url == repo_root: |
99 return 'svn' | 81 return 'svn' |
100 return url[len(repo_root)+1:] | 82 return url[len(repo_root)+1:] |
101 else: | 83 else: |
102 cmd = ['git', 'rev-parse', '--show-toplevel'] | 84 cmd = ['git', 'rev-parse', '--show-toplevel'] |
103 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | 85 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
104 stderr=subprocess.STDOUT) | 86 stderr=subprocess.STDOUT) |
105 if proc.wait() != 0: | 87 if proc.wait() != 0: |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 255 |
274 # Parse and validate the command-line arguments. | 256 # Parse and validate the command-line arguments. |
275 args = ValidateArgs(sys.argv[1:], trybots=trybots, is_svn=is_svn) | 257 args = ValidateArgs(sys.argv[1:], trybots=trybots, is_svn=is_svn) |
276 | 258 |
277 # Submit the try request. | 259 # Submit the try request. |
278 SubmitTryRequest(args, is_svn=is_svn) | 260 SubmitTryRequest(args, is_svn=is_svn) |
279 | 261 |
280 | 262 |
281 if __name__ == '__main__': | 263 if __name__ == '__main__': |
282 sys.exit(main()) | 264 sys.exit(main()) |
OLD | NEW |