Python 2.7 compatibility

This commit is contained in:
Josh Marshall
2018-07-23 17:07:18 +10:00
parent 3e1cfcaf5b
commit b8d0337b6c
11 changed files with 53 additions and 22 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
from .discovery import find_any, find_all
from .utils import Event, Logger
from .utils import Event, Logger, TimeoutError
from .protocol import ChannelBrokenException, ChannelDamagedException
from .shell import launch_shell
+9 -8
View File
@@ -11,7 +11,7 @@ import fibre.protocol
import fibre.utils
import fibre.remote_object
from fibre.utils import Event, Logger
from fibre.protocol import ChannelBrokenException
from fibre.protocol import ChannelBrokenException, TimeoutError
# Load all installed transport layers
@@ -20,25 +20,25 @@ channel_types = {}
try:
import fibre.usbbulk_transport
channel_types['usb'] = fibre.usbbulk_transport.discover_channels
except ModuleNotFoundError:
except ImportError:
pass
try:
import fibre.serial_transport
channel_types['serial'] = fibre.serial_transport.discover_channels
except ModuleNotFoundError:
except ImportError:
pass
try:
import fibre.tcp_transport
channel_types['tcp'] = fibre.tcp_transport.discover_channels
except ModuleNotFoundError:
except ImportError:
pass
try:
import fibre.udp_transport
channel_types['udp'] = fibre.udp_transport.discover_channels
except ModuleNotFoundError:
except ImportError:
pass
def noprint(text):
@@ -102,9 +102,10 @@ def find_all(path, serial_number,
prefix = search_spec.split(':')[0]
the_rest = ':'.join(search_spec.split(':')[1:])
if prefix in channel_types:
threading.Thread(target=channel_types[prefix],
args=(the_rest, serial_number, did_discover_channel, search_cancellation_token, channel_termination_token, logger),
daemon=True).start()
t = threading.Thread(target=channel_types[prefix],
args=(the_rest, serial_number, did_discover_channel, search_cancellation_token, channel_termination_token, logger))
t.daemon = True
t.start()
else:
raise Exception("Invalid path spec \"{}\"".format(search_spec))
+4 -3
View File
@@ -6,7 +6,7 @@ import sys
import threading
import traceback
#import fibre.utils
from fibre.utils import Event, wait_any
from fibre.utils import Event, wait_any, TimeoutError
import abc
if sys.version_info >= (3, 4):
@@ -65,7 +65,6 @@ def calc_crc16(remainder, value):
#print(hex(calc_crc8(0x12, [1, 2, 3, 4, 5, 0x10, 0x13, 0x37])))
#print(hex(calc_crc16(0xfeef, [1, 2, 3, 4, 5, 0x10, 0x13, 0x37])))
class DeviceInitException(Exception):
pass
@@ -256,7 +255,9 @@ class Channel(PacketSink):
self._logger.debug("receiver thread is exiting: " + traceback.format_exc())
finally:
self._channel_broken.set()
threading.Thread(target=receiver_thread, daemon=True).start()
t = threading.Thread(target=receiver_thread)
t.daemon = True
t.start()
def remote_endpoint_operation(self, endpoint_id, input, expect_ack, output_length):
if input is None:
@@ -10,6 +10,7 @@ import traceback
import serial
import serial.tools.list_ports
import fibre
from fibre.utils import TimeoutError
# TODO: make this customizable
DEFAULT_BAUDRATE = 115200
+1 -1
View File
@@ -4,7 +4,7 @@ import socket
import time
import traceback
import fibre.protocol
from fibre.utils import wait_any
from fibre.utils import wait_any, TimeoutError
def noprint(x):
pass
@@ -8,6 +8,7 @@ import time
import fibre.protocol
import traceback
import platform
from fibre.utils import TimeoutError
# Currently we identify fibre-enabled devices by VID,PID
# TODO: identify by USB descriptors
+11 -2
View File
@@ -12,10 +12,16 @@ try:
# TODO: we should win32console anyway so we could just omit colorama
import colorama
colorama.init()
except ModuleNotFoundError:
except ImportError:
print("Could not init terminal features.")
sys.stdout.flush()
pass
if sys.version_info < (3, 3):
class TimeoutError(Exception):
pass
else:
TimeoutError = TimeoutError
def get_serial_number_str(device):
if hasattr(device, 'serial_number'):
@@ -92,7 +98,10 @@ class Event():
def delayed_trigger():
if not self.wait(timeout=timeout):
self.set()
threading.Thread(target=delayed_trigger, daemon=True).start()
threading.Thread(target=delayed_trigger)
t.daemon = True
t.start()
def wait_any(timeout=None, *events):
"""