summaryrefslogtreecommitdiff
path: root/ui/menu
blob: 01c4cede71a5e795459aa17727789cc8140c79b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/python

# Copyright (C) 2006 - 2007  Michal Piotrowski <michal.k.k.piotrowski@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import os, sys, dircache, string, dialog, time
from menu_lib import *

def handle_exit_code(d, code):
	if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
		if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK:
			sys.exit(0)
			return 0
	else:
		return 1

def atcc_t_menu(test_type, t):
	u = atcc_list_control_files(test_type, at_dir)

	(code, tag) = d.checklist(text = test_type + ":", choices = u, title = t)

	return tag

def atcc_t_run(res, test_type):
	if len(res) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	for i in res:
		os.system(at_dir + '/bin/autotest ' + at_dir + '/' + test_type + '/' + i)
		atcc_save_results1(i, at_dir, menu_dir)

def atcc_t_p_run(res, test_type):
	if len(res) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	file = (menu_dir + '/tmp/parallel')
	f = open(file, 'w')
	
	for i in res:
		z = i.split('/')
		line = ("def " + z[0] + "():\n")
		z = str(line)
		f.write(z)
		
		file = (at_dir + '/' + test_type + '/' + i)
		f2 = open(file, 'r')
		k = f2.readlines()

		for i in k:
			x = ("\t" + i + "\n")
			z = str(x)
			f.write(z)

		f2.close()

	f.write('job.parallel(')

	for i in range(len(res)):
		z = res[i].split('/')
		z = ('[' + z[0] + '],')
		z = str(z)
		f.write(z)

	f.write(')')

	f.close()
	
	os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/parallel')
	atcc_save_results1("", at_dir, menu_dir)

def atcc_profilers_run(res1, res2):
	if len(res1) == 0 or len(res2) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	file = (menu_dir + '/tmp/profilers')
	f = open(file, 'w')

	f.write('for profiler in (')

	for i in range(len(res1)):
		z = res1[i].split('/')
		z = ('\'' + z[0] + '\', ')
		z = str(z)
		f.write(z)

	f.write('):\n')

	f.write('\ttry:\n')
	f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
	f.write('\t\tjob.profilers.add(profiler)\n')

	for i in range(len(res2)):
		z = atcc_control_file_read(res2[i], 'tests', at_dir)
		n = res2[i].split('/')
		k = ('\t\tjob.run_test(\'' + n[0] + '\',' + z + ')\n')
		k = str(k)
		f.write(k)

	f.write('\t\tjob.profilers.delete(profiler)\n')
	f.write('\texcept:\n')
	f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
	f.write('\t\traise\n')

	f.close()

	os.system(at_dir + '/bin/autotest ' + menu_dir + '/tmp/profilers')
	atcc_save_results2(res1, res2, at_dir, menu_dir)

def atcc_remote_get_ip():
	while 1:
		(code, answer) = d.inputbox("IP address of remote host", init = "192.168.0.1")

		if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
			break
		return answer

def atcc_t_remote_run(ip, res, test_type):
	if len(res) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	file = (menu_dir + '/tmp/remote_test')
	f = open(file, 'w')

	st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
	f.write(st + "\n")
	st = str("at = autotest.Autotest()")
	f.write(st + "\n")

	file2 = (menu_dir + '/tmp/remote_control')
	f2 = open(file2, 'w')

	for i in res:
		print i
		file3 =  (at_dir + '/' + test_type + '/' + i)
		f3 = open(file3, 'r')
		k = f3.readlines()
		for i in k:
			x = (i + "\n")
			z = str(x)
			f2.write(z)
		f3.close()

	f2.close()
	st = str("at.run(\"" +  menu_dir + "/tmp/remote_control\",\"results\", remote_host)")
	f.write(st + "\n")
	f.close()

	os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_test')

def atcc_t_p_remote_run(ip, res, test_type):
	if len(res) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	file = (menu_dir + '/tmp/remote_parallel_control')
	f = open(file, 'w')
	
	for i in res:
		z = i.split('/')
		line = ("def " + z[0] + "():\n")
		z = str(line)
		f.write(z)
		
		file = (at_dir + '/' + test_type + '/' + i)
		f2 = open(file, 'r')
		k = f2.readlines()

		for i in k:
			x = ("\t" + i + "\n")
			z = str(x)
			f.write(z)

		f2.close()

	f.write('job.parallel(')

	for i in range(len(res)):
		z = res[i].split('/')
		z = ('[' + z[0] + '],')
		z = str(z)
		f.write(z)

	f.write(')')

	f.close()

	file = (menu_dir + '/tmp/remote_parallel_test')
	f = open(file, 'w')

	st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
	f.write(st + "\n")
	st = str("at = autotest.Autotest()")
	f.write(st + "\n")

	st = str("at.run(\"" +  menu_dir + "/tmp/remote_parallel_control\",\"results\", remote_host)")
	f.write(st + "\n")
	f.close()

	os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_parallel_test')

def atcc_profilers_remote_run(ip, res1, res2):
	if len(res1) == 0 or len(res2) == 0:
		return -1

	atcc_setup_tmp_dirs_files(menu_dir)

	file = (menu_dir + '/tmp/remote_profilers_control')
	f = open(file, 'w')

	f.write('for profiler in (')

	for i in range(len(res1)):
		z = res1[i].split('/')
		z = ('\'' + z[0] + '\', ')
		z = str(z)
		f.write(z)

	f.write('):\n')

	f.write('\ttry:\n')
	f.write('\t\tprint "Testing profiler %s ..." % profiler\n')
	f.write('\t\tjob.profilers.add(profiler)\n')

	for i in range(len(res2)):
		z = atcc_control_file_read(res2[i], 'tests', at_dir)
		n = res2[i].split('/')
		k = ('\t\tjob.run_test(\'' + n[0] + '\',' + z + ')\n')
		k = str(k)
		f.write(k)

	f.write('\t\tjob.profilers.delete(profiler)\n')
	f.write('\texcept:\n')
	f.write('\t\tprint "Test of profiler %s failed" % profiler\n')
	f.write('\t\traise\n')

	f.close()

	file = (menu_dir + '/tmp/remote_profilers')
	f = open(file, 'w')

	st = str("remote_host = hosts.SSHHost(\"" + ip +"\")")
	f.write(st + "\n")
	st = str("at = autotest.Autotest()")
	f.write(st + "\n")

	st = str("at.run(\"" +  menu_dir + "/tmp/remote_profilers_control\",\"results\", remote_host)")
	f.write(st + "\n")
	f.close()

	os.system(srv_dir + '/autoserv ' + menu_dir + '/tmp/remote_profilers')

def atcc_tests_results(t):
	if os.path.exists(menu_dir + "/tmp/"):
		dir_ls = dircache.listdir(menu_dir + "/tmp/")
	else:
		d.infobox(menu_dir + "/tmp/ doesn't exist")
		time.sleep(5)
		return -1

	if len(dir_ls) == 0:
		return -1

	u = []

	for i in dir_ls:
		k = i, ""
		u.append(k)

	while 1:
		(code, tag) = d.menu("Results:", choices = u, title = t)

		if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
			break
		else:
			d.textbox(menu_dir + '/tmp/' + tag, width = -1)

def atcc_config_show_help(tag, test_type):
	tag = tag.split('/')
	tag = tag[0]
	if os.path.exists(at_dir + '/' + test_type + '/' + tag + '/help'):
		d.textbox(at_dir + '/' + test_type + '/' + tag + '/help', width = -1)
	else:
		d.infobox(at_dir + '/' + test_type + '/' + tag + '/help' " doesn't exist")
		time.sleep(5)

def atcc_config_edit(tag, test_type, ed):
	os.system(ed + " " + at_dir + '/' + test_type + '/' + tag)

def atcc_config_help_or_edit(tag, test_type):
	ed = "vim"
	while 1:
		(code, answer) = d.inputbox("Type 'help' to see documentation, or name of favourite text editor", init = ed)

		if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
			break
		elif answer == "help":
			atcc_config_show_help(tag, test_type)
			continue
		else:
			ed = answer
			atcc_config_edit(tag, test_type, ed)
			break

def atcc_config_choose_control_file(test_type, t):
	u_tmp = atcc_list_control_files(test_type, at_dir)
	u = []
	for i in u_tmp:
		k = i[0], ""
		u.append(k)

	while 1:
		(code, tag) = d.menu(test_type + ":", choices = u, title = t)

		if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
			break
		else:
			atcc_config_help_or_edit(tag, test_type)

def atcc_upgrade():
	os.system("svn checkout svn://test.kernel.org/autotest/trunk " + at_dir + "/../")

def atcc_rsync_mirror():
	os.system(at_dir + "/../mirror/mirror")

def atcc_main_menu():
	while 1:
		(code, tag) = d.menu("Main menu",
			choices = [("1", "Tests (local)"),
			("2", "Parallel tests (local)"),
			("3", "Profilers (local)"),
			("4", "Tests (remote)"),
			("5", "Parallel tests (remote)"),
			("6", "Profilers (remote)"),
			("7", "Tests' results"),
			("8", "Configure tests"),
			("9", "Upgrade Autotest"),
			("10", "Sync local kernel.org mirror")])
		if handle_exit_code(d, code):
			break
	return tag

def main():
	while 1:
		res = int(atcc_main_menu())
		if res == 1:
			res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
			atcc_t_run(res, test_type = 'tests')
		elif res == 2:
			res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
			atcc_t_p_run(res, test_type = 'tests')
		elif res == 3:
			res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
			res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
			atcc_profilers_run(res1, res2)
		elif res == 4:
			ip = atcc_remote_get_ip()
			res = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
			atcc_t_remote_run(ip, res, test_type = 'tests')
		elif res == 5:
			ip = atcc_remote_get_ip()
			res = atcc_t_menu(test_type = 'tests', t = 'Parallel tests selection menu')
			atcc_t_p_remote_run(ip, res, test_type = 'tests')
		elif res == 6:
			ip = atcc_remote_get_ip()
			res1 = atcc_t_menu(test_type = 'profilers', t = 'Profilers selection menu')
			res2 = atcc_t_menu(test_type = 'tests', t = 'Tests selection menu')
			atcc_profilers_remote_run(ip, res1, res2)
		elif res == 7:
			atcc_tests_results(t = 'Tests\' results menu')
		elif res == 8:
			atcc_config_choose_control_file(test_type = 'tests', t = 'Tests configuration menu')
		elif res == 9:
			atcc_upgrade()
		elif res == 10:
			atcc_rsync_mirror()
		elif res == 0:
			sys.exit(1)

check_python_version()

menu_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
at_dir = os.path.dirname(menu_dir + "/../client/")
srv_dir = os.path.dirname(menu_dir + "/../server/")

d = dialog.Dialog(dialog = "dialog")
d.add_persistent_args(["--backtitle", "Autotest Control Center v0.07"])

main()