Skip to content

Commit 26278f1

Browse files
authored
Merge pull request #137 from kneasle/rr-integration
Reimplement RR integration
2 parents cdd919a + cd97357 commit 26278f1

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

CHANGE_LOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Moved some overly verbose `INFO` messages into `DEBUG`.
1111
- Capped all numbers to 3 decimal places.
1212
- Made debug 'wait' logging slightly less verbose.
13+
- Fix broken version string (`Wheatley vv0.6.0` will now be `Wheatley v0.6.0`)
1314

1415
## Technical changes
1516

@@ -18,6 +19,8 @@
1819
- Change place notation parsing to comply with CompLib and the XML specification.
1920
- Add full static typing, and fix some `None`-related bugs.
2021
- Prevent installing the wrong version of socketio to work with RingingRoom.
22+
- Reimplement the Ringing Rom integration code, and fix buggy expansion of PN when running on the
23+
server.
2124

2225
# 0.5.2
2326
- Bump numpy version to exactly `1.19.3` on Windows to fix

wheatley/bot.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class Bot:
3434

3535
def __init__(self, tower: RingingRoomTower, row_generator: RowGenerator, do_up_down_in: bool,
3636
stop_at_rounds: bool, rhythm: Rhythm, user_name: Optional[str] = None,
37-
server_mode: bool = False) -> None:
37+
server_instance_id: Optional[int] = None) -> None:
3838
""" Initialise a Bot with all the parts it needs to run. """
39-
self._server_mode = server_mode
39+
# If this is None then Wheatley is in client mode, otherwise Wheatley is in server mode
40+
self._server_instance_id = server_instance_id
4041
self._last_activity_time = time.time()
4142

4243
self._rhythm = rhythm
@@ -91,6 +92,10 @@ def number_of_bells(self) -> int:
9192
""" Convenient property to find the number of bells in the current tower. """
9293
return self._tower.number_of_bells
9394

95+
@property
96+
def _server_mode(self) -> bool:
97+
return self._server_instance_id is not None
98+
9499
# Callbacks
95100
def _on_setting_change(self, key: str, value: Any) -> None:
96101
def log_invalid_key(message: str) -> None:
@@ -144,6 +149,9 @@ def _check_number_of_bells(self) -> bool:
144149
def _on_look_to(self) -> None:
145150
if self._check_number_of_bells():
146151
self.look_to_has_been_called(time.time())
152+
# All Wheatley instances should return a 'Roll Call' message after `Look To` is called.
153+
if self._server_instance_id is not None:
154+
self._tower.emit_roll_call(self._server_instance_id)
147155

148156
# This has to be made public, because the server's main function might have to call it
149157
def look_to_has_been_called(self, call_time: float) -> None:

wheatley/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ def server_main(override_args: Optional[List[str]], stop_on_join_tower: bool) ->
156156
help="Set to the time when 'Look to' was called if Wheatley was spawned because 'look to' was \
157157
called and Wheatley is needed."
158158
)
159+
parser.add_argument(
160+
"-i", "--id",
161+
type=int,
162+
help="The instance ID of this Wheatley process."
163+
)
159164
parser.add_argument(
160165
"-v", "--verbose",
161166
action="count",
@@ -179,14 +184,14 @@ def server_main(override_args: Optional[List[str]], stop_on_join_tower: bool) ->
179184
configure_logging(args.verbose, args.quiet)
180185

181186
# Log the version string to 'DEBUG'
182-
logging.debug(f"Running Wheatley v{__version__}")
187+
logging.debug(f"Running Wheatley {__version__}")
183188

184189
# Args that we are currently 'missing'
185190
use_up_down_in = True
186191
stop_at_rounds = True
187192
peal_speed = 180
188193
inertia = 1
189-
initial_inertia = 1
194+
initial_inertia = 0
190195
max_bells_in_dataset = 15
191196
handstroke_gap = 1
192197
use_wait = True
@@ -197,7 +202,7 @@ def server_main(override_args: Optional[List[str]], stop_on_join_tower: bool) ->
197202
rhythm = create_rhythm(peal_speed, inertia, max_bells_in_dataset, handstroke_gap, use_wait,
198203
initial_inertia)
199204
bot = Bot(tower, PlaceHolderGenerator(), use_up_down_in, stop_at_rounds, rhythm, user_name="Wheatley",
200-
server_mode=True)
205+
server_instance_id=args.id)
201206

202207
with tower:
203208
tower.wait_loaded()
@@ -371,7 +376,7 @@ def console_main(override_args: Optional[List[str]], stop_on_join_tower: bool) -
371376
parser.add_argument(
372377
"--version",
373378
action="version",
374-
version=f"Wheatley v{__version__}"
379+
version=f"Wheatley {__version__}"
375380
)
376381
parser.add_argument(
377382
"-v", "--verbose",

wheatley/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def json_to_call(name: str) -> Optional[CallDef]:
209209
raise_error('stage', "'stage' is not defined", e)
210210
except ValueError as e:
211211
raise_error('stage', f"'{json['stage']}' is not a valid integer", e)
212-
return PlaceNotationGenerator(stage, "&" + json['notation'], json_to_call('bob'),
212+
return PlaceNotationGenerator(stage, json['notation'], json_to_call('bob'),
213213
json_to_call('single'))
214214

215215
if json['type'] == "composition":

wheatley/tower.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def set_is_ringing(self, value: bool) -> None:
127127
self.logger.info(f"(EMIT): Telling RR clients to set is_ringing to {value}")
128128
self._emit("c_wheatley_is_ringing", {"is_ringing": value, "tower_id": self.tower_id})
129129

130+
def emit_roll_call(self, instance_id: int) -> None:
131+
""" Broadcasts a 'roll call' reply to the Ringing Room server. """
132+
self.logger.info("(EMIT): Replying to roll call")
133+
self._emit("c_roll_call", {"tower_id": self.tower_id, "instance_id": instance_id})
134+
130135
def wait_loaded(self) -> None:
131136
""" Pause the thread until the socket-io connection is open and stable. """
132137
if self._socket_io_client is None or not self._socket_io_client.connected:

0 commit comments

Comments
 (0)