python 3 fixes

This commit is contained in:
Daniel Pavel 2012-11-29 12:34:20 +02:00
parent 84540fb087
commit d6b18cd426
10 changed files with 27 additions and 25 deletions

View File

@ -16,7 +16,7 @@ class _DUMMY_RECEIVER(object):
__slots__ = ['name', 'max_devices', 'status']
name = _lur.Receiver.name
max_devices = _lur.Receiver.max_devices
status = 'Receiver not found'
status = 'Receiver not found.'
__bool__ = __nonzero__ = lambda self: False
__str__ = lambda self: 'DUMMY'
DUMMY = _DUMMY_RECEIVER()

View File

@ -7,11 +7,11 @@ GObject.threads_init()
from solaar import NAME
_APP_ICONS = (NAME + '-fail', NAME + '-init', NAME)
_APP_ICONS = (NAME + '-init', NAME + '-fail', NAME)
def appicon(receiver_status):
return (_APP_ICONS[0] if receiver_status < 0 else
_APP_ICONS[1] if receiver_status < 1 else
_APP_ICONS[2])
return (_APP_ICONS[1] if type(receiver_status) == str else
_APP_ICONS[2] if receiver_status else
_APP_ICONS[0])
_ICON_THEME = Gtk.IconTheme.get_default()

View File

@ -47,13 +47,13 @@ def _show_about_window(action):
about.set_comments('Shows status of devices connected\nto a Logitech Unifying Receiver.')
about.set_license_type(Gtk.License.GPL_2_0)
about.set_copyright('\xC2\xA9 2012 Daniel Pavel')
about.set_copyright(b'\xC2\xA9'.decode('utf-8') + ' 2012 Daniel Pavel')
about.set_authors(('Daniel Pavel http://github.com/pwr',))
try:
about.add_credit_section('Testing', ('Douglas Wagner',))
except Exception as e:
print e
except Exception:
pass
about.set_website('http://github.com/pwr/Solaar/wiki')
about.set_website_label('Solaar Wiki')

View File

@ -4,5 +4,5 @@ Z=`readlink -f "$0"`
LIB=`readlink -f $(dirname "$Z")/../lib`
export PYTHONPATH=$LIB
PYTHON=`which python python2 python3 | head -n 1`
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
exec $PYTHON -u -m hidapi.hidconsole "$@"

View File

@ -4,5 +4,5 @@ Z=`readlink -f "$0"`
LIB=`readlink -f $(dirname "$Z")/../lib`
export PYTHONPATH=$LIB
PYTHON=`which python python2 python3 | head -n 1`
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
exec $PYTHON -u -m logitech.scanner "$@"

View File

@ -8,5 +8,5 @@ SHARE=`readlink -f $(dirname "$Z")/../share`
export PYTHONPATH=$APP:$LIB
export XDG_DATA_DIRS=${SHARE}_override:$SHARE:$XDG_DATA_DIRS
PYTHON=`which python python2 python3 | head -n 1`
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
exec $PYTHON -u -m solaar "$@"

View File

@ -19,7 +19,7 @@ def print_receiver(receiver):
print (" Reported %d paired device(s)." % len(receiver))
activity = receiver.request(0x83B3)
if activity:
activity = [(d, ord(activity[d - 1])) for d in range(1, receiver.max_devices)]
activity = [(d, ord(activity[d - 1:d])) for d in range(1, receiver.max_devices)]
print(" Device activity counters: %s" % ', '.join(('%d=%d' % (d, a)) for d, a in activity if a > 0))
def scan_devices(receiver):

View File

@ -12,8 +12,8 @@ _log = getLogger('LUR.base')
del getLogger
from .common import strhex as _strhex, KwException as _KwException
import hidpp10 as _hidpp10
import hidpp20 as _hidpp20
from . import hidpp10 as _hidpp10
from . import hidpp20 as _hidpp20
import hidapi as _hid
#
@ -45,7 +45,7 @@ class NoReceiver(_KwException):
class NoSuchDevice(_KwException):
"""Raised when trying to reach a device number not paired to the receiver."""
pass
pass
class DeviceUnreachable(_KwException):
@ -135,14 +135,14 @@ def write(handle, devnumber, data):
else:
wdata = _pack('!BB5s', 0x10, devnumber, data)
if _log.isEnabledFor(_DEBUG):
_log.debug("(%s) <= w[%02X %02X %s %s]", handle, ord(wdata[0]), devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:]))
_log.debug("(%s) <= w[%02X %02X %s %s]", handle, ord(wdata[:1]), devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:]))
try:
_hid.write(int(handle), wdata)
except Exception as reason:
_log.error("write failed, assuming handle %s no longer available", repr(handle))
close(handle)
raise NoReceiver(reason)
raise NoReceiver(reason=reason)
def read(handle, timeout=DEFAULT_TIMEOUT):
@ -167,7 +167,7 @@ def _read(handle, timeout):
except Exception as reason:
_log.error("read failed, assuming handle %s no longer available", repr(handle))
close(handle)
raise NoReceiver(reason)
raise NoReceiver(reason=reason)
if data:
report_id = ord(data[:1])
@ -192,7 +192,7 @@ def _skip_incoming(handle):
except Exception as reason:
_log.error("read failed, assuming receiver %s no longer available", handle)
close(handle)
raise NoReceiver(reason)
raise NoReceiver(reason=reason)
if data:
report_id = ord(data[:1])
@ -320,7 +320,8 @@ def request(handle, devnumber, request_id, *params):
if delta >= timeout:
_log.warn("timeout on device %d request {%04X} params[%s]", devnumber, request_id, _strhex(params))
raise DeviceUnreachable(number=devnumber, request=request_id)
break
# raise DeviceUnreachable(number=devnumber, request=request_id)
def ping(handle, devnumber):
@ -362,14 +363,15 @@ def ping(handle, devnumber):
return 1.0
if error == _hidpp10.ERROR.resource_error: # device unreachable
raise DeviceUnreachable(number=devnumber, request=request_id)
# raise DeviceUnreachable(number=devnumber, request=request_id)
break
if error == _hidpp10.ERROR.unknown_device: # no paired device with that number
_log.error("(%s) device %d error on ping request: unknown device", handle, devnumber)
raise NoSuchDevice(devnumber)
raise NoSuchDevice(number=devnumber, request=request_id)
_unhandled(report_id, number, data)
if delta >= _PING_TIMEOUT:
_log.warn("(%s) timeout on device %d ping", handle, devnumber)
raise DeviceUnreachable(number=devnumber, request=request_id)
# raise DeviceUnreachable(number=devnumber, request=request_id)

View File

@ -8,7 +8,7 @@ from struct import pack as _pack
class NamedInt(int):
"""An integer with an attached name."""
__slots__ = ['name']
# __slots__ = ['name']
def __new__(cls, value, name):
obj = int.__new__(cls, value)

View File

@ -110,7 +110,7 @@ class EventsListener(_threading.Thread):
self.has_started()
last_tick = _timestamp() if self.tick_period else 0
last_tick = 0
while self._active:
if self._queued_events.empty():