better logging in cli tools
This commit is contained in:
parent
ecf3539ba2
commit
c6427ab4a6
|
@ -11,7 +11,8 @@ def read_next(handle, timeout=1000, ignore_nodata=False):
|
||||||
print "!! Read failed, aborting"
|
print "!! Read failed, aborting"
|
||||||
raise Exception()
|
raise Exception()
|
||||||
if reply:
|
if reply:
|
||||||
print ">> %s %s" % (hexlify(reply), repr(reply))
|
hexs = hexlify(reply)
|
||||||
|
print ">> [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(reply))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not ignore_nodata:
|
if not ignore_nodata:
|
||||||
|
@ -25,7 +26,7 @@ def console_cycle(handle):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
line = raw_input('!! Enter packet to send (hex bytes) or ^C to abort: ')
|
line = raw_input('!! Enter packet to send (hex bytes) or ^C to abort: ')
|
||||||
line = line.strip()
|
line = line.strip().replace(' ', '').replace('-', '')
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
if len(line) % 2 == 1:
|
if len(line) % 2 == 1:
|
||||||
|
@ -36,7 +37,8 @@ def console_cycle(handle):
|
||||||
except:
|
except:
|
||||||
print "!! Invalid input."
|
print "!! Invalid input."
|
||||||
continue
|
continue
|
||||||
print "<< %s %s" % (hexlify(data), repr(data))
|
hexs = hexlify(data)
|
||||||
|
print "<< [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data))
|
||||||
hidapi.write(handle, data)
|
hidapi.write(handle, data)
|
||||||
read_next(handle)
|
read_next(handle)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ def scan_devices(receiver):
|
||||||
|
|
||||||
for devinfo in devices:
|
for devinfo in devices:
|
||||||
print "Device [%d] %s (%s)" % (devinfo.number, devinfo.name, devinfo.type)
|
print "Device [%d] %s (%s)" % (devinfo.number, devinfo.name, devinfo.type)
|
||||||
|
print " Protocol %s" % devinfo.protocol
|
||||||
|
|
||||||
for fw in devinfo.firmware:
|
for fw in devinfo.firmware:
|
||||||
print " %s firmware: %s version %s build %d" % (fw.type, fw.name, fw.version, fw.build)
|
print " %s firmware: %s version %s build %d" % (fw.type, fw.name, fw.version, fw.build)
|
||||||
|
|
||||||
|
@ -51,11 +53,12 @@ if __name__ == '__main__':
|
||||||
log_level = logging.root.level - 10 * args.verbose
|
log_level = logging.root.level - 10 * args.verbose
|
||||||
logging.root.setLevel(log_level if log_level > 0 else 1)
|
logging.root.setLevel(log_level if log_level > 0 else 1)
|
||||||
|
|
||||||
receiver = api.open()
|
for rawdevice in api._base.list_receiver_devices():
|
||||||
if receiver:
|
receiver = api._base.try_open(rawdevice.path)
|
||||||
print "!! Logitech Unifying Receiver found."
|
if receiver:
|
||||||
scan_devices(receiver)
|
print "!! Logitech Unifying Receiver found (%s)." % rawdevice.path
|
||||||
|
scan_devices(receiver)
|
||||||
|
api.close(receiver)
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
print "!! Logitech Unifying Receiver not found."
|
print "!! Logitech Unifying Receiver not found."
|
||||||
|
|
||||||
api.close(receiver)
|
|
||||||
|
|
Loading…
Reference in New Issue