Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions hathor/cli/events_simulator/events_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@ def create_parser() -> ArgumentParser:
from hathor.cli.util import create_parser

parser = create_parser()
possible_scenarios = [scenario.value for scenario in Scenario]
possible_scenarios = [scenario.name for scenario in Scenario]

parser.add_argument('--scenario', help=f'One of {possible_scenarios}', type=Scenario, required=True)
parser.add_argument('--scenario', help=f'One of {possible_scenarios}', type=str, required=True)
parser.add_argument('--port', help='Port to run the WebSocket server', type=int, default=DEFAULT_PORT)

return parser


def execute(args: Namespace) -> None:
from hathor.cli.events_simulator.scenario import Scenario
from hathor.event.storage import EventMemoryStorage
from hathor.event.websocket import EventWebsocketFactory
from hathor.util import reactor

try:
scenario = Scenario[args.scenario]
except KeyError as e:
possible_scenarios = [scenario.name for scenario in Scenario]
raise ValueError(f'Invalid scenario "{args.scenario}". Choose one of {possible_scenarios}') from e

storage = EventMemoryStorage()

for event in args.scenario.value:
for event in scenario.value:
storage.save_event(event)

factory = EventWebsocketFactory(reactor, storage)
Expand Down