-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulator.py
executable file
·79 lines (60 loc) · 1.83 KB
/
simulator.py
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
#!/usr/bin/env python
from simulator.simulator import Simulator
from lib.logger import Logger
from lib.util.commandshell import CommandShell
from controllers.plugincontroller import PluginController
from optparse import OptionParser
import sys
@CommandShell.expander
def get_available_plugins():
result = {}
for path, candidate in PluginController().plugin_candidates():
result[candidate] = None
return result
@CommandShell.expander
def get_loaded_plugins():
result = {}
for name in PluginController().get_loaded_plugins():
result[name] = None
return result
parser = OptionParser()
parser.add_option("-p", "--plugins", dest="plugins", help="List of plugins to load separated by commas")
parser.add_option("-d", "--debug", default=False, action="store_true", dest="debug", help="Enable debug log")
(options, args) = parser.parse_args()
if options.debug:
Logger.set_loglevel("DEBUGL2")
sim = Simulator()
sim.load_plugin("corecommands", "core")
sim.load_plugin("aclcommands", "core")
if options.plugins:
plugins = options.plugins.split(",")
for plugin in plugins:
Logger.info("Loading %s" % plugin)
try:
sim.load_plugin(plugin)
except Exception as e:
Logger.log_traceback(sim)
sys.exit(1)
command_tree = {
"!load": get_available_plugins,
"!unload": get_loaded_plugins,
"!reload": get_loaded_plugins,
}
shell = CommandShell()
shell.set_parse_tree(command_tree)
# Start simulator and wait for the initialization events to finish
sim.start()
sim.wait_for_events()
sim.flush()
while True:
try:
input = shell.input("Simulator# > ")
except (EOFError, KeyboardInterrupt):
print "quit"
break
if input == "quit":
break
sim.msg_channel(input)
sim.wait_for_events()
sim.flush()
sim.stop()