blob: d5b9fc0cd38cc0d8ad6631db82bb178cb86238fb [file] [log] [blame]
mblighbe2ac852006-09-28 04:44:30 +00001#!/usr/bin/python
2
3# Copyright (C) 2006 Michal Piotrowski <michal.k.k.piotrowski@gmail.com>
4# Linux Testers Group
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10
mbligh2615f972006-09-30 15:19:48 +000011import os, sys, dircache, string, dialog, time
mblighbe2ac852006-09-28 04:44:30 +000012
13def check_python_version():
14 version = string.split(string.split(sys.version)[0], ".")
15 if map(int, version) < [2, 4, 0]:
16 print "Python 2.4 or newer is needed"
17 sys.exit(1)
18
mblighbe2ac852006-09-28 04:44:30 +000019def handle_exit_code(d, code):
20 if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
mbligh2615f972006-09-30 15:19:48 +000021 if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK:
mblighbe2ac852006-09-28 04:44:30 +000022 sys.exit(0)
23 return 0
24 else:
25 return 1
26
27def atcc_t_menu(test_type):
mbligh2615f972006-09-30 15:19:48 +000028 dir_ls = dircache.listdir(at_dir + '/' + test_type)
mblighbe2ac852006-09-28 04:44:30 +000029
30 u = []
31
32 for i in dir_ls:
33 k = i, "", 0
34 if i != ".svn":
mbligh2615f972006-09-30 15:19:48 +000035 u.append(k)
mblighbe2ac852006-09-28 04:44:30 +000036
37 while 1:
mbligh2615f972006-09-30 15:19:48 +000038 (code, tag) = d.checklist(text = test_type + ":", choices = u, title = test_type + " menu")
39 break
mblighbe2ac852006-09-28 04:44:30 +000040 return tag
41
42def atcc_t_run(res, test_type):
mbligh2615f972006-09-30 15:19:48 +000043 os.system('if [ ! -e /tmp/.at/ ]; then mkdir /tmp/.at; fi')
mblighbe2ac852006-09-28 04:44:30 +000044 for i in res:
45 print i
mbligh2615f972006-09-30 15:19:48 +000046 os.system(at_dir + '/bin/autotest ' + at_dir + '/' + test_type + '/' + i + '/control')
47
48 os.system('cp ' + at_dir + '/results/default/status /tmp/.at/' + i + '.status')
49 os.system('cp ' + at_dir + '/results/default/' + i + '/debug/stderr /tmp/.at/' + i + '.stderr' )
50 os.system('cp ' + at_dir + '/results/default/' + i + '/debug/stdout /tmp/.at/' + i + '.stdout' )
51
52def atcc_tests_results():
53 if os.path.exists('/tmp/.at/'):
54 dir_ls=dircache.listdir('/tmp/.at/')
55 else:
56 d.infobox("/tmp/.at/ doesn't exist")
57 time.sleep(5)
58 return -1
59
60 u = []
61
62 for i in dir_ls:
63 k = i, ""
64 u.append(k)
65
66 while 1:
67 (code, tag) = d.menu("Results:", choices=u, title="Results menu")
68
69 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
70 break
71 else:
72 d.textbox('/tmp/.at/' + tag)
73
74def atcc_configure_set(tag, test_type):
75# file = (at_dir + '/' + test_type + '/' + tag + '/control')
76# f = open(file, 'r+')
77# print f
78# f.seek(11)
79# z = f.readline()
80# f.close()
81
82 while 1:
83 (code, answer) = d.inputbox("Config options", init="")
84
85 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
86 break
87 else:
88 file = (at_dir + '/' + test_type + '/' + tag + '/control')
89 f = open(file, 'w')
90 print f
91 value = ("job.runtest(None, \'" + tag + "\', " + answer + ")")
92 s = str(value)
93 f.seek(0)
94 z = f.write(s)
95 print z
96 f.close()
97 break
98
99def atcc_configure(test_type):
100 dir_ls = dircache.listdir(at_dir + '/' + test_type)
101
102 u = []
103
104 for i in dir_ls:
105 k = i, ""
106 if i != ".svn":
107 u.append(k)
108
109 while 1:
110 (code, tag) = d.menu(test_type + ":", choices=u, title = test_type + " configuration menu")
111
112 if code == d.DIALOG_CANCEL or code == d.DIALOG_ESC:
113 break
114 else:
115 atcc_configure_set(tag, test_type)
mblighbe2ac852006-09-28 04:44:30 +0000116
117def atcc_main_menu():
118 while 1:
mbligh2615f972006-09-30 15:19:48 +0000119 (code, tag) = d.menu("Main menu",
mblighbe2ac852006-09-28 04:44:30 +0000120 choices=[("1", "Tests"),
mbligh2615f972006-09-30 15:19:48 +0000121 ("2", "Profilers"),
122 ("3", "Tests' results"),
123 ("4", "Configure tests")])
mblighbe2ac852006-09-28 04:44:30 +0000124 if handle_exit_code(d, code):
125 break
126 return tag
127
128def main():
mbligh2615f972006-09-30 15:19:48 +0000129 while 1:
130 res=int(atcc_main_menu())
131 if res == 1:
132 res=atcc_t_menu(test_type = 'tests')
133 atcc_t_run(res, test_type = 'tests')
134 elif res == 2:
135 res=atcc_t_menu(test_type = 'profilers')
136 atcc_t_run(res, test_type = 'profilers')
137 elif res == 3:
138 atcc_tests_results()
139 elif res == 4:
140 atcc_configure(test_type = 'tests')
141 elif res == 0:
142 sys.exit(1)
mblighbe2ac852006-09-28 04:44:30 +0000143
144check_python_version()
145
mbligh2615f972006-09-30 15:19:48 +0000146menu_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
147at_dir = os.path.dirname(menu_dir)
mblighbe2ac852006-09-28 04:44:30 +0000148
149d = dialog.Dialog(dialog="dialog")
mbligh2615f972006-09-30 15:19:48 +0000150d.add_persistent_args(["--backtitle", "Autotest Control Center v0.03"])
mblighbe2ac852006-09-28 04:44:30 +0000151
152main()