mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 1 | #!/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 | |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 11 | import os, sys, dircache, string, dialog, time |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 12 | |
| 13 | def 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 | |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 19 | def handle_exit_code(d, code): |
| 20 | if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 21 | if d.yesno("Do you want to exit Autotest Control Center?") == d.DIALOG_OK: |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 22 | sys.exit(0) |
| 23 | return 0 |
| 24 | else: |
| 25 | return 1 |
| 26 | |
| 27 | def atcc_t_menu(test_type): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 28 | dir_ls = dircache.listdir(at_dir + '/' + test_type) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 29 | |
| 30 | u = [] |
| 31 | |
| 32 | for i in dir_ls: |
| 33 | k = i, "", 0 |
| 34 | if i != ".svn": |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 35 | u.append(k) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 36 | |
| 37 | while 1: |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 38 | (code, tag) = d.checklist(text = test_type + ":", choices = u, title = test_type + " menu") |
| 39 | break |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 40 | return tag |
| 41 | |
| 42 | def atcc_t_run(res, test_type): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 43 | os.system('if [ ! -e /tmp/.at/ ]; then mkdir /tmp/.at; fi') |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 44 | for i in res: |
| 45 | print i |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 46 | 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 | |
| 52 | def 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 | |
| 74 | def 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 | |
| 99 | def 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) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 116 | |
| 117 | def atcc_main_menu(): |
| 118 | while 1: |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 119 | (code, tag) = d.menu("Main menu", |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 120 | choices=[("1", "Tests"), |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 121 | ("2", "Profilers"), |
| 122 | ("3", "Tests' results"), |
| 123 | ("4", "Configure tests")]) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 124 | if handle_exit_code(d, code): |
| 125 | break |
| 126 | return tag |
| 127 | |
| 128 | def main(): |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 129 | 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) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 143 | |
| 144 | check_python_version() |
| 145 | |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 146 | menu_dir = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 147 | at_dir = os.path.dirname(menu_dir) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 148 | |
| 149 | d = dialog.Dialog(dialog="dialog") |
mbligh | 2615f97 | 2006-09-30 15:19:48 +0000 | [diff] [blame^] | 150 | d.add_persistent_args(["--backtitle", "Autotest Control Center v0.03"]) |
mbligh | be2ac85 | 2006-09-28 04:44:30 +0000 | [diff] [blame] | 151 | |
| 152 | main() |