diff --git a/open-lst/tools/openlst_tools/bootload_radio.py b/open-lst/tools/openlst_tools/bootload_radio.py
index f86902c..a19b6d4 100644
--- a/open-lst/tools/openlst_tools/bootload_radio.py
+++ b/open-lst/tools/openlst_tools/bootload_radio.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+from builtins import range
import os
import argparse
import logging
@@ -106,7 +107,7 @@ def main():
pass
time.sleep(1.5)
# Load pages
- for page in xrange(FLASH_APP_START, FLASH_APP_END + 1, FLASH_PAGE_SIZE):
+ for page in range(FLASH_APP_START, FLASH_APP_END + 1, FLASH_PAGE_SIZE):
page_number = page // FLASH_PAGE_SIZE
page_data = app_section[page:page + FLASH_PAGE_SIZE]
if all(b == 0xff for b in page_data):
diff --git a/open-lst/tools/openlst_tools/commands.py b/open-lst/tools/openlst_tools/commands.py
index da7af4d..1f174c3 100644
--- a/open-lst/tools/openlst_tools/commands.py
+++ b/open-lst/tools/openlst_tools/commands.py
@@ -14,11 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+from __future__ import print_function
+import six
import abc
import time
import logging
from threading import Thread, Lock
-from Queue import Queue, Empty
+from queue import Queue, Empty
from .translator import Translator
from .radio_mux import DEFAULT_RX_SOCKET, DEFAULT_TX_SOCKET
@@ -52,7 +54,7 @@ class CommandHandler(object):
__metaclass__ = abc.ABCMeta
def __init__(self, hwid):
- if isinstance(hwid, basestring):
+ if isinstance(hwid, six.string_types):
self.hwid = int(hwid, 16)
else:
self.hwid = hwid
@@ -238,7 +240,7 @@ def flush(self):
def poll_message(self, timeout):
msgs = dict(self.poller.poll(timeout * 1000))
- for sock, msg in msgs.iteritems():
+ for sock, msg in six.iteritems(msgs):
if sock == self.rx:
return self.rx.recv()
return None
diff --git a/open-lst/tools/openlst_tools/get_telem.py b/open-lst/tools/openlst_tools/get_telem.py
index 6001049..bb80846 100644
--- a/open-lst/tools/openlst_tools/get_telem.py
+++ b/open-lst/tools/openlst_tools/get_telem.py
@@ -79,9 +79,9 @@ def main():
con = get_handler(args.hwid, args.rx_path, args.tx_path)
resp = con.send_cmd("lst get_telem")
- print resp
+ print(resp)
for field, val in zip(TELEM_FIELDS, resp.split()[2:]):
- print field, val
+ print(field, val)
if __name__ == '__main__':
main()
diff --git a/open-lst/tools/openlst_tools/intel_hex.py b/open-lst/tools/openlst_tools/intel_hex.py
index 56c9be5..3342961 100644
--- a/open-lst/tools/openlst_tools/intel_hex.py
+++ b/open-lst/tools/openlst_tools/intel_hex.py
@@ -15,6 +15,7 @@
# along with this program. If not, see .
from binascii import hexlify
+from builtins import range
def parse_hex_file(hex_data, mem_size=0x8000):
@@ -28,7 +29,7 @@ def parse_hex_file(hex_data, mem_size=0x8000):
It returns a 32KB bytearray with empty/unused bytes set to 0xFF
(flash empty)
"""
- outbuff = bytearray(0xff for _ in xrange(mem_size))
+ outbuff = bytearray(0xff for _ in range(mem_size))
line_count = 0
total_data = 0
for line in hex_data.splitlines():
@@ -49,7 +50,7 @@ def parse_hex_file(hex_data, mem_size=0x8000):
if record_type == 0: # Data
data = [
int(line[(9 + 2 * i):(9 + 2 * i + 2)], 16)
- for i in xrange(byte_count)]
+ for i in range(byte_count)]
checksum = int(
line[(9 + 2 * byte_count):(9 + 2 * byte_count + 2)],
16)
@@ -72,7 +73,7 @@ def parse_hex_file(hex_data, mem_size=0x8000):
def dump_hex_file(data, line_size=32, skip_lines=True,
truncate_lines=False):
lines = []
- for addr in xrange(0, len(data), line_size):
+ for addr in range(0, len(data), line_size):
line_data = data[addr:addr + line_size]
if truncate_lines:
line_data = line_data.rstrip('\xff')
diff --git a/open-lst/tools/openlst_tools/radio_cmd.py b/open-lst/tools/openlst_tools/radio_cmd.py
index faf22e4..47081c7 100644
--- a/open-lst/tools/openlst_tools/radio_cmd.py
+++ b/open-lst/tools/openlst_tools/radio_cmd.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+from __future__ import print_function
import os
import argparse
import logging
@@ -48,7 +49,7 @@ def main():
con = get_handler(args.hwid, args.rx_path, args.tx_path)
resp = con.send_cmd(args.command)
- print resp
+ print(resp)
if __name__ == '__main__':
main()
diff --git a/open-lst/tools/openlst_tools/radio_mux.py b/open-lst/tools/openlst_tools/radio_mux.py
index 06af078..5613d9f 100644
--- a/open-lst/tools/openlst_tools/radio_mux.py
+++ b/open-lst/tools/openlst_tools/radio_mux.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+from __future__ import print_function
import argparse
import pwd
import grp
@@ -24,7 +25,7 @@
import zmq
from binascii import hexlify
from threading import Thread, Event, Lock
-from Queue import Queue
+from queue import Queue
ESP_START_BYTE_0 = '\x22'
ESP_START_BYTE_1 = '\x69'
@@ -188,7 +189,7 @@ def main():
rtscts=False,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE)
- print serial_port
+ print(serial_port)
zmq_poller = ZMQPoller(
tx_socket=args.tx_socket,
rx_socket=args.rx_socket,
diff --git a/open-lst/tools/openlst_tools/terminal.py b/open-lst/tools/openlst_tools/terminal.py
index 64435fb..f017771 100644
--- a/open-lst/tools/openlst_tools/terminal.py
+++ b/open-lst/tools/openlst_tools/terminal.py
@@ -15,6 +15,8 @@
# along with this program. If not, see .
from __future__ import print_function
+import six
+from builtins import input, range
import argparse
import zmq
from blessed import Terminal
@@ -88,7 +90,7 @@ def _zmq_watcher_thread(self):
self._connect_zmq()
while self.running:
msgs = dict(self.poller.poll(50))
- for sock, msg in msgs.iteritems():
+ for sock, msg in six.iteritems(msgs):
if sock == self.rx:
msg = self.rx.recv()
self.insert_msg("<", self._process_zmq_msg(msg))
@@ -108,7 +110,7 @@ def _process_zmq_msg(self, msg):
def insert_msg(self, prompt, msg):
''' Clear the current line, print some text, then reprint the line '''
- if type(msg) == str:
+ if isinstance(msg, six.string_types):
msg = bytearray(msg)
if self.raw:
msg = ' '.join('{:02x}'.format(x) for x in msg)
@@ -146,7 +148,7 @@ def clear_line(self):
def _input_loop(self):
try:
- self.user_buffer = raw_input('> ')
+ self.user_buffer = input('> ')
self._command_preprocessor()
except (KeyboardInterrupt, EOFError):
if readline.get_line_buffer() != '':
@@ -229,7 +231,7 @@ def _pretty_list_print(l, width=80):
nrow = len(l) / ncol
lrow = len(l) - (nrow * ncol)
pstr = "{{:<{nchar}}}".format(nchar=nchar) * ncol
- pstr = "\n".join([pstr for i in xrange(nrow)])
+ pstr = "\n".join([pstr for i in range(nrow)])
if lrow != 0:
pstr += "\n" + "{{:<{nchar}}}".format(nchar=nchar) * lrow
print(pstr.format(*l))
@@ -240,7 +242,7 @@ def _navigate_tree(cmd_list, tree):
Last level should be a list '''
cmd = cmd_list.pop(0)
if len(cmd_list) == 0:
- flat_level = tree if type(tree) == list else tree.keys()
+ flat_level = tree if isinstance(tree, list) else tree.keys()
if cmd in flat_level:
return [cmd]
else:
diff --git a/open-lst/tools/openlst_tools/time_sync.py b/open-lst/tools/openlst_tools/time_sync.py
index b09572b..129ad74 100644
--- a/open-lst/tools/openlst_tools/time_sync.py
+++ b/open-lst/tools/openlst_tools/time_sync.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+from __future__ import print_function
import os
import argparse
import logging
@@ -58,7 +59,7 @@ def main():
nanoseconds=dt.microseconds * 1000),
timeout=0.5
)
- print resp
+ print(resp)
if __name__ == '__main__':
main()