Show More
@@ -1,273 +1,280 b'' | |||
|
1 | 1 | # cli.py - Command line interface for automation |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | # no-check-code because Python 3 native. |
|
9 | 9 | |
|
10 | 10 | import argparse |
|
11 | 11 | import os |
|
12 | 12 | import pathlib |
|
13 | 13 | |
|
14 | 14 | from . import ( |
|
15 | 15 | aws, |
|
16 | 16 | HGAutomation, |
|
17 | 17 | windows, |
|
18 | 18 | ) |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | SOURCE_ROOT = pathlib.Path(os.path.abspath(__file__)).parent.parent.parent.parent |
|
22 | 22 | DIST_PATH = SOURCE_ROOT / 'dist' |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | def bootstrap_windows_dev(hga: HGAutomation, aws_region): |
|
26 | 26 | c = hga.aws_connection(aws_region) |
|
27 | 27 | image = aws.ensure_windows_dev_ami(c) |
|
28 | 28 | print('Windows development AMI available as %s' % image.id) |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | def build_inno(hga: HGAutomation, aws_region, arch, revision, version): |
|
32 | 32 | c = hga.aws_connection(aws_region) |
|
33 | 33 | image = aws.ensure_windows_dev_ami(c) |
|
34 | 34 | DIST_PATH.mkdir(exist_ok=True) |
|
35 | 35 | |
|
36 | 36 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
37 | 37 | instance = insts[0] |
|
38 | 38 | |
|
39 | 39 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
40 | 40 | |
|
41 | 41 | for a in arch: |
|
42 | 42 | windows.build_inno_installer(instance.winrm_client, a, |
|
43 | 43 | DIST_PATH, |
|
44 | 44 | version=version) |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | def build_wix(hga: HGAutomation, aws_region, arch, revision, version): |
|
48 | 48 | c = hga.aws_connection(aws_region) |
|
49 | 49 | image = aws.ensure_windows_dev_ami(c) |
|
50 | 50 | DIST_PATH.mkdir(exist_ok=True) |
|
51 | 51 | |
|
52 | 52 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
53 | 53 | instance = insts[0] |
|
54 | 54 | |
|
55 | 55 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
56 | 56 | |
|
57 | 57 | for a in arch: |
|
58 | 58 | windows.build_wix_installer(instance.winrm_client, a, |
|
59 | 59 | DIST_PATH, version=version) |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | def build_windows_wheel(hga: HGAutomation, aws_region, arch, revision): |
|
63 | 63 | c = hga.aws_connection(aws_region) |
|
64 | 64 | image = aws.ensure_windows_dev_ami(c) |
|
65 | 65 | DIST_PATH.mkdir(exist_ok=True) |
|
66 | 66 | |
|
67 | 67 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
68 | 68 | instance = insts[0] |
|
69 | 69 | |
|
70 | 70 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
71 | 71 | |
|
72 | 72 | for a in arch: |
|
73 | 73 | windows.build_wheel(instance.winrm_client, a, DIST_PATH) |
|
74 | 74 | |
|
75 | 75 | |
|
76 |
def build_all_windows_packages(hga: HGAutomation, aws_region, revision |
|
|
76 | def build_all_windows_packages(hga: HGAutomation, aws_region, revision, | |
|
77 | version): | |
|
77 | 78 | c = hga.aws_connection(aws_region) |
|
78 | 79 | image = aws.ensure_windows_dev_ami(c) |
|
79 | 80 | DIST_PATH.mkdir(exist_ok=True) |
|
80 | 81 | |
|
81 | 82 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
82 | 83 | instance = insts[0] |
|
83 | 84 | |
|
84 | 85 | winrm_client = instance.winrm_client |
|
85 | 86 | |
|
86 | 87 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
87 | 88 | |
|
88 | 89 | for arch in ('x86', 'x64'): |
|
89 | 90 | windows.purge_hg(winrm_client) |
|
90 | 91 | windows.build_wheel(winrm_client, arch, DIST_PATH) |
|
91 | 92 | windows.purge_hg(winrm_client) |
|
92 |
windows.build_inno_installer(winrm_client, arch, DIST_PATH |
|
|
93 | windows.build_inno_installer(winrm_client, arch, DIST_PATH, | |
|
94 | version=version) | |
|
93 | 95 | windows.purge_hg(winrm_client) |
|
94 |
windows.build_wix_installer(winrm_client, arch, DIST_PATH |
|
|
96 | windows.build_wix_installer(winrm_client, arch, DIST_PATH, | |
|
97 | version=version) | |
|
95 | 98 | |
|
96 | 99 | |
|
97 | 100 | def terminate_ec2_instances(hga: HGAutomation, aws_region): |
|
98 | 101 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) |
|
99 | 102 | aws.terminate_ec2_instances(c.ec2resource) |
|
100 | 103 | |
|
101 | 104 | |
|
102 | 105 | def purge_ec2_resources(hga: HGAutomation, aws_region): |
|
103 | 106 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) |
|
104 | 107 | aws.remove_resources(c) |
|
105 | 108 | |
|
106 | 109 | |
|
107 | 110 | def run_tests_windows(hga: HGAutomation, aws_region, instance_type, |
|
108 | 111 | python_version, arch, test_flags): |
|
109 | 112 | c = hga.aws_connection(aws_region) |
|
110 | 113 | image = aws.ensure_windows_dev_ami(c) |
|
111 | 114 | |
|
112 | 115 | with aws.temporary_windows_dev_instances(c, image, instance_type, |
|
113 | 116 | disable_antivirus=True) as insts: |
|
114 | 117 | instance = insts[0] |
|
115 | 118 | |
|
116 | 119 | windows.synchronize_hg(SOURCE_ROOT, '.', instance) |
|
117 | 120 | windows.run_tests(instance.winrm_client, python_version, arch, |
|
118 | 121 | test_flags) |
|
119 | 122 | |
|
120 | 123 | |
|
121 | 124 | def get_parser(): |
|
122 | 125 | parser = argparse.ArgumentParser() |
|
123 | 126 | |
|
124 | 127 | parser.add_argument( |
|
125 | 128 | '--state-path', |
|
126 | 129 | default='~/.hgautomation', |
|
127 | 130 | help='Path for local state files', |
|
128 | 131 | ) |
|
129 | 132 | parser.add_argument( |
|
130 | 133 | '--aws-region', |
|
131 | 134 | help='AWS region to use', |
|
132 | 135 | default='us-west-1', |
|
133 | 136 | ) |
|
134 | 137 | |
|
135 | 138 | subparsers = parser.add_subparsers() |
|
136 | 139 | |
|
137 | 140 | sp = subparsers.add_parser( |
|
138 | 141 | 'bootstrap-windows-dev', |
|
139 | 142 | help='Bootstrap the Windows development environment', |
|
140 | 143 | ) |
|
141 | 144 | sp.set_defaults(func=bootstrap_windows_dev) |
|
142 | 145 | |
|
143 | 146 | sp = subparsers.add_parser( |
|
144 | 147 | 'build-all-windows-packages', |
|
145 | 148 | help='Build all Windows packages', |
|
146 | 149 | ) |
|
147 | 150 | sp.add_argument( |
|
148 | 151 | '--revision', |
|
149 | 152 | help='Mercurial revision to build', |
|
150 | 153 | default='.', |
|
151 | 154 | ) |
|
155 | sp.add_argument( | |
|
156 | '--version', | |
|
157 | help='Mercurial version string to use', | |
|
158 | ) | |
|
152 | 159 | sp.set_defaults(func=build_all_windows_packages) |
|
153 | 160 | |
|
154 | 161 | sp = subparsers.add_parser( |
|
155 | 162 | 'build-inno', |
|
156 | 163 | help='Build Inno Setup installer(s)', |
|
157 | 164 | ) |
|
158 | 165 | sp.add_argument( |
|
159 | 166 | '--arch', |
|
160 | 167 | help='Architecture to build for', |
|
161 | 168 | choices={'x86', 'x64'}, |
|
162 | 169 | nargs='*', |
|
163 | 170 | default=['x64'], |
|
164 | 171 | ) |
|
165 | 172 | sp.add_argument( |
|
166 | 173 | '--revision', |
|
167 | 174 | help='Mercurial revision to build', |
|
168 | 175 | default='.', |
|
169 | 176 | ) |
|
170 | 177 | sp.add_argument( |
|
171 | 178 | '--version', |
|
172 | 179 | help='Mercurial version string to use in installer', |
|
173 | 180 | ) |
|
174 | 181 | sp.set_defaults(func=build_inno) |
|
175 | 182 | |
|
176 | 183 | sp = subparsers.add_parser( |
|
177 | 184 | 'build-windows-wheel', |
|
178 | 185 | help='Build Windows wheel(s)', |
|
179 | 186 | ) |
|
180 | 187 | sp.add_argument( |
|
181 | 188 | '--arch', |
|
182 | 189 | help='Architecture to build for', |
|
183 | 190 | choices={'x86', 'x64'}, |
|
184 | 191 | nargs='*', |
|
185 | 192 | default=['x64'], |
|
186 | 193 | ) |
|
187 | 194 | sp.add_argument( |
|
188 | 195 | '--revision', |
|
189 | 196 | help='Mercurial revision to build', |
|
190 | 197 | default='.', |
|
191 | 198 | ) |
|
192 | 199 | sp.set_defaults(func=build_windows_wheel) |
|
193 | 200 | |
|
194 | 201 | sp = subparsers.add_parser( |
|
195 | 202 | 'build-wix', |
|
196 | 203 | help='Build WiX installer(s)' |
|
197 | 204 | ) |
|
198 | 205 | sp.add_argument( |
|
199 | 206 | '--arch', |
|
200 | 207 | help='Architecture to build for', |
|
201 | 208 | choices={'x86', 'x64'}, |
|
202 | 209 | nargs='*', |
|
203 | 210 | default=['x64'], |
|
204 | 211 | ) |
|
205 | 212 | sp.add_argument( |
|
206 | 213 | '--revision', |
|
207 | 214 | help='Mercurial revision to build', |
|
208 | 215 | default='.', |
|
209 | 216 | ) |
|
210 | 217 | sp.add_argument( |
|
211 | 218 | '--version', |
|
212 | 219 | help='Mercurial version string to use in installer', |
|
213 | 220 | ) |
|
214 | 221 | sp.set_defaults(func=build_wix) |
|
215 | 222 | |
|
216 | 223 | sp = subparsers.add_parser( |
|
217 | 224 | 'terminate-ec2-instances', |
|
218 | 225 | help='Terminate all active EC2 instances managed by us', |
|
219 | 226 | ) |
|
220 | 227 | sp.set_defaults(func=terminate_ec2_instances) |
|
221 | 228 | |
|
222 | 229 | sp = subparsers.add_parser( |
|
223 | 230 | 'purge-ec2-resources', |
|
224 | 231 | help='Purge all EC2 resources managed by us', |
|
225 | 232 | ) |
|
226 | 233 | sp.set_defaults(func=purge_ec2_resources) |
|
227 | 234 | |
|
228 | 235 | sp = subparsers.add_parser( |
|
229 | 236 | 'run-tests-windows', |
|
230 | 237 | help='Run tests on Windows', |
|
231 | 238 | ) |
|
232 | 239 | sp.add_argument( |
|
233 | 240 | '--instance-type', |
|
234 | 241 | help='EC2 instance type to use', |
|
235 | 242 | default='t3.medium', |
|
236 | 243 | ) |
|
237 | 244 | sp.add_argument( |
|
238 | 245 | '--python-version', |
|
239 | 246 | help='Python version to use', |
|
240 | 247 | choices={'2.7', '3.5', '3.6', '3.7', '3.8'}, |
|
241 | 248 | default='2.7', |
|
242 | 249 | ) |
|
243 | 250 | sp.add_argument( |
|
244 | 251 | '--arch', |
|
245 | 252 | help='Architecture to test', |
|
246 | 253 | choices={'x86', 'x64'}, |
|
247 | 254 | default='x64', |
|
248 | 255 | ) |
|
249 | 256 | sp.add_argument( |
|
250 | 257 | '--test-flags', |
|
251 | 258 | help='Extra command line flags to pass to run-tests.py', |
|
252 | 259 | ) |
|
253 | 260 | sp.set_defaults(func=run_tests_windows) |
|
254 | 261 | |
|
255 | 262 | return parser |
|
256 | 263 | |
|
257 | 264 | |
|
258 | 265 | def main(): |
|
259 | 266 | parser = get_parser() |
|
260 | 267 | args = parser.parse_args() |
|
261 | 268 | |
|
262 | 269 | local_state_path = pathlib.Path(os.path.expanduser(args.state_path)) |
|
263 | 270 | automation = HGAutomation(local_state_path) |
|
264 | 271 | |
|
265 | 272 | if not hasattr(args, 'func'): |
|
266 | 273 | parser.print_help() |
|
267 | 274 | return |
|
268 | 275 | |
|
269 | 276 | kwargs = dict(vars(args)) |
|
270 | 277 | del kwargs['func'] |
|
271 | 278 | del kwargs['state_path'] |
|
272 | 279 | |
|
273 | 280 | args.func(automation, **kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now