forked from gson1703/anita
/
anita
executable file
·151 lines (134 loc) · 5.67 KB
/
anita
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
#!/usr/pkg/bin/python2.4
import sys
import re
import anita
import os
import optparse
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def main(argv = None):
if argv is None:
argv = sys.argv
dtb_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'share', 'dtb', 'arm', 'vexpress-v2p-ca15-tc1.dtb')
parser = optparse.OptionParser(
usage = "usage: %prog [options] install|boot|interact distribution")
parser.add_option("--workdir",
help="store work files in DIR", metavar="DIR")
parser.add_option("--vmm",
help="use VMM (qemu or xen) as the virtual machine monitor",
metavar="VMM")
parser.add_option("--vmm-args",
help="pass ARGS as extra arguments to virtual machine monitor",
metavar="ARGS", default="")
# Deprecated
parser.add_option("--qemu-args",
help=optparse.SUPPRESS_HELP, default="")
parser.add_option("--disk-size",
help="use a virtual disk of SIZE bytes (k/M/G/T suffix accepted)",
metavar="SIZE")
parser.add_option("--memory-size",
help="use a virtual RAM size of SIZE bytes (k/M/G/T suffix accepted)",
metavar="SIZE")
parser.add_option("--run",
help="run COMMAND on the virtual machine after boot", metavar="COMMAND")
parser.add_option("--sets",
help="install the distribution SETS (e.g., base,games)",
metavar="SETS")
parser.add_option("--test-timeout",
help="allow TIMEOUT seconds for the ATF tests", metavar="TIMEOUT",
type="int", default=86400)
parser.add_option("--run-timeout",
help="allow TIMEOUT seconds for command run using the --run option", metavar="TIMEOUT",
type="int", default=3600)
parser.add_option("--persist",
help="make changes to disk contents persistent", action="store_true")
parser.add_option("--boot-from",
help="boot from MEDIA (floppy/cdrom)", metavar="MEDIA")
parser.add_option("--structured-log", action="store_true",
help="log console traffic in a structured format, to stdout")
parser.add_option("--structured-log-file", metavar="FILE",
help="log console traffic in a structured format, to FILE")
parser.add_option("--no-install", action="store_true",
help="in boot/test/interact mode, assume system is already installed", default=False)
parser.add_option("--version", action="store_true",
help="print the anita version number and exit")
parser.add_option("--tests", help='select the tests to run in test mode: \"atf\" or \"kyua\"', type="string", default="atf")
parser.add_option("--dtb", help='use the Device Tree Blob (.dtb) PATH_TO_DTB', type="string", metavar="PATH_TO_DTB", default=dtb_path)
(options, args) = parser.parse_args()
if options.version:
print anita.__version__
sys.exit(0)
if len(args) < 2:
raise Usage("not enough arguments")
distarg = args[1]
vmm_args = options.vmm_args.split() + options.qemu_args.split()
if options.sets:
sets = options.sets.split(",")
else:
sets = None
if re.search(r'\.iso$', distarg):
dist = anita.ISO(distarg, sets = sets)
elif re.match(r'/', distarg):
if not re.search(r'/$', distarg):
raise Usage("distribution directory should end in a slash")
dist = anita.LocalDirectory(distarg, sets = sets)
elif re.match(r'[a-z0-9\.0-]+:', distarg):
if not re.search(r'/$', distarg):
raise Usage("distribution URL should end in a slash")
dist = anita.URL(distarg, sets = sets)
else:
raise Usage("expected distribution URL or directory, got " + distarg)
if dist.arch() == 'evbarm-earmv7hf':
if not os.path.exists(options.dtb):
raise IOError("The Device Tree Blob %s does not exist." % options.dtb)
a = anita.Anita(dist,
workdir = options.workdir,
vmm = options.vmm,
vmm_args = vmm_args,
disk_size = options.disk_size,
memory_size = options.memory_size,
persist = options.persist,
boot_from = options.boot_from,
structured_log = options.structured_log,
structured_log_file = options.structured_log_file,
no_install = options.no_install,
tests = options.tests,
dtb = options.dtb
)
def maybe_run_command(a):
if options.run:
return a.shell_cmd(options.run, options.run_timeout)
else:
return 0
status = 0
mode = args[0]
if mode != 'print-workdir':
print "This is anita version", anita.__version__
sys.stdout.flush()
if mode == 'install':
a.install()
elif mode == 'boot':
child = a.boot()
status = maybe_run_command(a)
a.halt()
elif mode == 'interact':
child = a.boot()
status = maybe_run_command(a)
anita.console_interaction(child)
elif mode == 'test':
status = a.run_tests(timeout = options.test_timeout)
a.halt()
elif mode == 'print-workdir':
print a.workdir
else:
raise Usage("unknown mode: " + mode)
return status
if __name__ == "__main__":
try:
status = main()
sys.exit(status)
except Usage, err:
print >>sys.stderr, "%s: %s" % (os.path.basename(sys.argv[0]), err.msg)
print >>sys.stderr, "for help use --help"
sys.exit(1)