small logging fixes for repr()
This commit is contained in:
parent
345bab3a99
commit
216928f904
|
@ -121,11 +121,11 @@ def _open(device, hidpp):
|
||||||
if not handle:
|
if not handle:
|
||||||
sys.exit("!! Failed to open %s, aborting." % device)
|
sys.exit("!! Failed to open %s, aborting." % device)
|
||||||
|
|
||||||
print (".. Opened handle %s, vendor %s product %s serial %s." % (
|
print (".. Opened handle %r, vendor %r product %r serial %r." % (
|
||||||
repr(handle),
|
handle,
|
||||||
repr(hidapi.get_manufacturer(handle)),
|
hidapi.get_manufacturer(handle),
|
||||||
repr(hidapi.get_product(handle)),
|
hidapi.get_product(handle),
|
||||||
repr(hidapi.get_serial(handle))))
|
hidapi.get_serial(handle)))
|
||||||
if hidpp:
|
if hidpp:
|
||||||
if hidapi.get_manufacturer(handle) != b'Logitech':
|
if hidapi.get_manufacturer(handle) != b'Logitech':
|
||||||
sys.exit("!! Only Logitech devices support the HID++ protocol.")
|
sys.exit("!! Only Logitech devices support the HID++ protocol.")
|
||||||
|
@ -208,7 +208,7 @@ def main():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print ('%s: %s' % (type(e).__name__, e))
|
print ('%s: %s' % (type(e).__name__, e))
|
||||||
|
|
||||||
print (".. Closing handle", repr(handle))
|
print (".. Closing handle %r" % handle)
|
||||||
hidapi.close(handle)
|
hidapi.close(handle)
|
||||||
if interactive:
|
if interactive:
|
||||||
readline.write_history_file(args.history)
|
readline.write_history_file(args.history)
|
||||||
|
|
|
@ -108,10 +108,10 @@ def close(handle):
|
||||||
_hid.close(handle)
|
_hid.close(handle)
|
||||||
else:
|
else:
|
||||||
handle.close()
|
handle.close()
|
||||||
# _log.info("closed receiver handle %s", repr(handle))
|
# _log.info("closed receiver handle %r", handle)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
# _log.exception("closing receiver handle %s", repr(handle))
|
# _log.exception("closing receiver handle %r", handle)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -141,7 +141,7 @@ def write(handle, devnumber, data):
|
||||||
try:
|
try:
|
||||||
_hid.write(int(handle), wdata)
|
_hid.write(int(handle), wdata)
|
||||||
except Exception as reason:
|
except Exception as reason:
|
||||||
_log.error("write failed, assuming handle %s no longer available", repr(handle))
|
_log.error("write failed, assuming handle %r no longer available", handle)
|
||||||
close(handle)
|
close(handle)
|
||||||
raise NoReceiver(reason=reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ def _read(handle, timeout):
|
||||||
try:
|
try:
|
||||||
data = _hid.read(int(handle), _MAX_READ_SIZE, timeout)
|
data = _hid.read(int(handle), _MAX_READ_SIZE, timeout)
|
||||||
except Exception as reason:
|
except Exception as reason:
|
||||||
_log.error("read failed, assuming handle %s no longer available", repr(handle))
|
_log.error("read failed, assuming handle %r no longer available", handle)
|
||||||
close(handle)
|
close(handle)
|
||||||
raise NoReceiver(reason=reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class NamedInt(int):
|
||||||
def __new__(cls, value, name):
|
def __new__(cls, value, name):
|
||||||
assert isinstance(name, str) or isinstance(name, unicode)
|
assert isinstance(name, str) or isinstance(name, unicode)
|
||||||
obj = int.__new__(cls, value)
|
obj = int.__new__(cls, value)
|
||||||
obj.name = name
|
obj.name = unicode(name)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def bytes(self, count=2):
|
def bytes(self, count=2):
|
||||||
|
@ -40,12 +40,11 @@ class NamedInt(int):
|
||||||
return int(self)
|
return int(self)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name)
|
return self.name
|
||||||
def __unicode__(self):
|
__unicode__ = __str__
|
||||||
return unicode(self.name)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'NamedInt(%d, %s)' % (int(self), repr(self.name))
|
return 'NamedInt(%d, %r)' % (int(self), self.name)
|
||||||
|
|
||||||
|
|
||||||
class NamedInts(object):
|
class NamedInts(object):
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ThreadedHandle(object):
|
||||||
def __init__(self, initial_handle, path):
|
def __init__(self, initial_handle, path):
|
||||||
assert initial_handle
|
assert initial_handle
|
||||||
if type(initial_handle) != int:
|
if type(initial_handle) != int:
|
||||||
raise TypeError('expected int as initial handle, got %s' % repr(initial_handle))
|
raise TypeError('expected int as initial handle, got %r' % initial_handle)
|
||||||
|
|
||||||
assert path
|
assert path
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
|
@ -125,7 +125,7 @@ class ReceiverListener(_listener.EventsListener):
|
||||||
dev = self.receiver[n.devnumber]
|
dev = self.receiver[n.devnumber]
|
||||||
|
|
||||||
if not dev:
|
if not dev:
|
||||||
_log.warn("received %s for invalid device %d: %s", n, n.devnumber, repr(dev))
|
_log.warn("received %s for invalid device %d: %r", n, n.devnumber, dev)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not already_known:
|
if not already_known:
|
||||||
|
|
Loading…
Reference in New Issue