1 import string
2 import sys
3
4 from teamwork.shell.PsychShell import *
5
7 """An interactive terminal version of the base L{PsychShell} class."""
8
9 - def __init__(self,entities=None,
10 classes=None,
11 agentClass=None,
12 multiagentClass=None,
13 file=None,
14 progress=None,
15 debug=0,
16 compileDynamics=True,
17 compilePolicies=None,
18 ):
38
40 """Interactive creation of entities for initial scenario"""
41 entityList = []
42 setupDone = None
43
44 while not setupDone:
45 cmd = self.getCommand()
46 if cmd == 'quit':
47
48 self.done = 1
49 setupDone = 1
50 elif cmd == 'done':
51
52 if len(entityList) > 0:
53 self.displayResult(cmd,'Entering simulation phase...')
54 setupDone = 1
55 else:
56 self.displayResult(cmd,'No entities created yet!')
57 elif cmd == 'entities':
58
59 self.displayResult(cmd,
60 map(lambda e:(e.name,e.__class__.__name__),
61 entityList))
62 else:
63
64 commands = string.split(cmd)
65 try:
66 entityClass = commands[0]
67 name = commands[1]
68 except IndexError:
69 self.displayResult(cmd,'Usage: <class> <name>')
70 entityClass = None
71 if entityClass:
72 entity = createEntity(entityClass,name,self.classes,
73 self.agentClass)
74 if entity:
75 entityList.append(entity)
76 self.displayResult(cmd,entity.name)
77 else:
78 self.displayResult(cmd,'Unknown entity class: '+entityClass)
79 return entityList
80
82 """Terminal version of command entry. Prints a prompt
83 (currently assumes turn-based execution) and reads the command
84 entry from the input file."""
85 if self.phase == 'setup':
86 prompt = '?'
87 else:
88 next = self.entities.next()
89 prompt = '%s (%d)> ' % (next[0]['name'],
90 self.entities.time)
91 print prompt,
92 try:
93 cmd = string.strip(self.file.readline())
94 except KeyboardInterrupt:
95 cmd = 'quit'
96 return cmd
97
99 """Terminal version of the output display method. Uses
100 standard output."""
101 print result
102
103 sys.stdout.flush()
104