kete: stop listening when pairing a device
Or the internal state of kete is that the device is listening while tuhi says it is not.
This commit is contained in:
parent
3f75c927dc
commit
277523c7d5
|
@ -578,7 +578,8 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def _on_name_vanished(self, manager):
|
def _on_name_vanished(self, manager):
|
||||||
logger.debug('Tuhi daemon went away, I should stop the current workers')
|
logger.debug('Tuhi daemon went away, terminating the current workers')
|
||||||
|
self.terminate_workers()
|
||||||
|
|
||||||
def emptyline(self):
|
def emptyline(self):
|
||||||
# make sure we do not re-enter the last typed command
|
# make sure we do not re-enter the last typed command
|
||||||
|
@ -590,8 +591,7 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
|
|
||||||
def do_exit(self, args):
|
def do_exit(self, args):
|
||||||
'''Leave the shell'''
|
'''Leave the shell'''
|
||||||
for worker in self._workers:
|
self.terminate_workers()
|
||||||
worker.stop()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def precmd(self, line):
|
def precmd(self, line):
|
||||||
|
@ -620,6 +620,15 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
worker.run()
|
worker.run()
|
||||||
self._workers.append(worker)
|
self._workers.append(worker)
|
||||||
|
|
||||||
|
def terminate_worker(self, worker):
|
||||||
|
worker.stop()
|
||||||
|
self._workers.remove(worker)
|
||||||
|
|
||||||
|
def terminate_workers(self):
|
||||||
|
for worker in self._workers:
|
||||||
|
worker.stop()
|
||||||
|
self._workers = []
|
||||||
|
|
||||||
def do_devices(self, arg):
|
def do_devices(self, arg):
|
||||||
'''List known devices. These are devices previously paired with the daemon.'''
|
'''List known devices. These are devices previously paired with the daemon.'''
|
||||||
logger.debug('Listing available devices:')
|
logger.debug('Listing available devices:')
|
||||||
|
@ -687,8 +696,7 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
if mode == 'off':
|
if mode == 'off':
|
||||||
for worker in [w for w in self._workers if isinstance(w, Listener)]:
|
for worker in [w for w in self._workers if isinstance(w, Listener)]:
|
||||||
if worker.device.address == address:
|
if worker.device.address == address:
|
||||||
worker.stop()
|
self.terminate_worker(worker)
|
||||||
self._workers.remove(worker)
|
|
||||||
break
|
break
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -832,8 +840,7 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
self.start_worker(Searcher, parsed_args)
|
self.start_worker(Searcher, parsed_args)
|
||||||
else:
|
else:
|
||||||
if parsed_args.mode == 'off':
|
if parsed_args.mode == 'off':
|
||||||
current_searcher.stop()
|
self.terminate_worker(current_searcher)
|
||||||
self._workers.remove(current_searcher)
|
|
||||||
else:
|
else:
|
||||||
logger.info('Already searching')
|
logger.info('Already searching')
|
||||||
|
|
||||||
|
@ -881,6 +888,11 @@ class TuhiKeteShell(cmd.Cmd):
|
||||||
|
|
||||||
device = None
|
device = None
|
||||||
|
|
||||||
|
# make sure we do not keep a listener on the device
|
||||||
|
for worker in [w for w in self._workers if isinstance(w, Listener)]:
|
||||||
|
if worker.device.address == address:
|
||||||
|
self.terminate_worker(worker)
|
||||||
|
|
||||||
for d in self._manager.devices + self._manager.pairable_devices:
|
for d in self._manager.devices + self._manager.pairable_devices:
|
||||||
if d.address == address:
|
if d.address == address:
|
||||||
device = d
|
device = d
|
||||||
|
|
Loading…
Reference in New Issue