kete: clean up the Searcher class

now that there is no more standalone commands, the Searcher can be striped
off of its interactive bits.
This commit is contained in:
Benjamin Tissoires 2018-01-31 16:05:03 +01:00
parent c2ceba7483
commit a164ea291e
1 changed files with 0 additions and 28 deletions

View File

@ -21,7 +21,6 @@ import json
import logging import logging
import re import re
import readline import readline
import select
import threading import threading
import time import time
import svgwrite import svgwrite
@ -354,12 +353,8 @@ class Worker(GObject.Object):
class Searcher(Worker): class Searcher(Worker):
interactive = True
def __init__(self, manager, args): def __init__(self, manager, args):
super(Searcher, self).__init__(manager) super(Searcher, self).__init__(manager)
self.address = args.address
self.is_pairing = False
def run(self): def run(self):
if self.manager.searching: if self.manager.searching:
@ -388,31 +383,10 @@ class Searcher(Worker):
def _on_notify_search(self, manager, pspec): def _on_notify_search(self, manager, pspec):
if not manager.searching: if not manager.searching:
logger.info('Search cancelled') logger.info('Search cancelled')
if not self.is_pairing and self.interactive:
self.stop()
def _on_pairable_device_interactive(self, manager, device):
if self.address is None:
print('Connect to device? [y/N] ', end='')
sys.stdout.flush()
i, o, e = select.select([sys.stdin], [], [], 5)
if i:
answer = sys.stdin.readline().strip()
if answer.lower() == 'y':
self.address = device.address
else:
print('timed out')
if device.address == self.address:
self.is_pairing = True
device.pair()
def _on_pairable_device(self, manager, device): def _on_pairable_device(self, manager, device):
logger.info(f'Pairable device: {device}') logger.info(f'Pairable device: {device}')
if self.interactive:
self._on_pairable_device_interactive(manager, device)
class Listener(Worker): class Listener(Worker):
def __init__(self, manager, args): def __init__(self, manager, args):
@ -824,8 +798,6 @@ class TuhiKeteShell(cmd.Cmd):
self._manager.stop_search() self._manager.stop_search()
return return
Searcher.interactive = False
parsed_args.address = None
self.start_worker(Searcher, parsed_args) self.start_worker(Searcher, parsed_args)
def help_pair(self): def help_pair(self):