kete/prompt: implement fetch

pull/36/head
Benjamin Tissoires 2018-01-26 13:05:15 +01:00 committed by Peter Hutterer
parent 60252f8649
commit c1a11280c0
1 changed files with 49 additions and 0 deletions

View File

@ -628,6 +628,55 @@ class TuhiKeteShell(cmd.Cmd):
wargs.address = address
self.start_worker(Listener, wargs)
def help_fetch(self):
self.do_fetch('-h')
def do_fetch(self, args):
'''Fetches one or all drawing(s) from a specific device.'''
def is_index_or_all(string):
try:
n = int(string)
except ValueError:
if string == 'all':
return string
raise argparse.ArgumentTypeError(f'"{string}" is neither a timestamp nor "all"')
else:
return n
parser = argparse.ArgumentParser(prog='fetch',
description='Fetches a drawing or all drawings from a specific device.',
add_help=False)
parser.add_argument('-h', action='help', help=argparse.SUPPRESS)
parser.add_argument('address', metavar='12:34:56:AB:CD:EF',
type=TuhiKeteDevice.is_device_address,
default=None,
help='the address of the device to fetch drawing from')
parser.add_argument('index', metavar='{<index>|all}',
type=is_index_or_all,
const='all', nargs='?', default='all',
help='the index of the drawing to fetch or a literal "all"')
try:
parsed_args = parser.parse_args(args.split())
except SystemExit:
return
address = parsed_args.address
index = parsed_args.index
if index != 'all':
try:
int(index)
except ValueError:
print(self._fetch_usage)
return
wargs = Args()
wargs.address = address
wargs.index = index
self.start_worker(Fetcher, wargs)
class TuhiKeteShellWorker(Worker):
def __init__(self, manager, args):