style: some of the suggestions from flake8 and pylint
diff --git a/serial/tools/list_ports.py b/serial/tools/list_ports.py
index 81600f4..8041c70 100644
--- a/serial/tools/list_ports.py
+++ b/serial/tools/list_ports.py
@@ -54,24 +54,24 @@
parser = argparse.ArgumentParser(description='Serial port enumeration')
parser.add_argument(
- 'regexp',
- nargs='?',
- help='only show ports that match this regex')
+ 'regexp',
+ nargs='?',
+ help='only show ports that match this regex')
parser.add_argument(
- '-v', '--verbose',
- action='store_true',
- help='show more messages')
+ '-v', '--verbose',
+ action='store_true',
+ help='show more messages')
parser.add_argument(
- '-q', '--quiet',
- action='store_true',
- help='suppress all messages')
+ '-q', '--quiet',
+ action='store_true',
+ help='suppress all messages')
parser.add_argument(
- '-n',
- type=int,
- help='only output the N-th entry')
+ '-n',
+ type=int,
+ help='only output the N-th entry')
args = parser.parse_args()
diff --git a/serial/tools/list_ports_common.py b/serial/tools/list_ports_common.py
index ae43d2d..e5935c9 100644
--- a/serial/tools/list_ports_common.py
+++ b/serial/tools/list_ports_common.py
@@ -44,6 +44,7 @@
self.interface = None
def usb_description(self):
+ """return a short string to name the port based on USB info"""
if self.interface is not None:
return '{} - {}'.format(self.product, self.interface)
elif self.product is not None:
@@ -52,11 +53,12 @@
return self.name
def usb_info(self):
+ """return a string with USB related information about device"""
return 'USB VID:PID={:04X}:{:04X}{}{}'.format(
- self.vid,
- self.pid,
- ' SER={}'.format(self.serial_number) if self.serial_number is not None else '',
- ' LOCATION={}'.format(self.location) if self.location is not None else '')
+ self.vid,
+ self.pid,
+ ' SER={}'.format(self.serial_number) if self.serial_number is not None else '',
+ ' LOCATION={}'.format(self.location) if self.location is not None else '')
def apply_usb_info(self):
"""update description and hwid from USB data"""
diff --git a/serial/tools/list_ports_windows.py b/serial/tools/list_ports_windows.py
index 5346405..81fbf59 100644
--- a/serial/tools/list_ports_windows.py
+++ b/serial/tools/list_ports_windows.py
@@ -8,6 +8,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause
+# pylint: disable=invalid-name,too-few-public-methods
import re
import ctypes
from ctypes.wintypes import BOOL
@@ -158,10 +159,10 @@
# repeat for all possible GUIDs
for index in range(guids_size.value):
g_hdi = SetupDiGetClassDevs(
- ctypes.byref(GUIDs[index]),
- None,
- NULL,
- DIGCF_PRESENT) # was DIGCF_PRESENT|DIGCF_DEVICEINTERFACE which misses CDC ports
+ ctypes.byref(GUIDs[index]),
+ None,
+ NULL,
+ DIGCF_PRESENT) # was DIGCF_PRESENT|DIGCF_DEVICEINTERFACE which misses CDC ports
devinfo = SP_DEVINFO_DATA()
devinfo.cbSize = ctypes.sizeof(devinfo)
@@ -171,21 +172,21 @@
# get the real com port name
hkey = SetupDiOpenDevRegKey(
- g_hdi,
- ctypes.byref(devinfo),
- DICS_FLAG_GLOBAL,
- 0,
- DIREG_DEV, # DIREG_DRV for SW info
- KEY_READ)
+ g_hdi,
+ ctypes.byref(devinfo),
+ DICS_FLAG_GLOBAL,
+ 0,
+ DIREG_DEV, # DIREG_DRV for SW info
+ KEY_READ)
port_name_buffer = byte_buffer(250)
port_name_length = ULONG(ctypes.sizeof(port_name_buffer))
RegQueryValueEx(
- hkey,
- PortName,
- None,
- None,
- ctypes.byref(port_name_buffer),
- ctypes.byref(port_name_length))
+ hkey,
+ PortName,
+ None,
+ None,
+ ctypes.byref(port_name_buffer),
+ ctypes.byref(port_name_length))
RegCloseKey(hkey)
# unfortunately does this method also include parallel ports.
diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py
index b55c3bb..e82cc9b 100644
--- a/serial/tools/miniterm.py
+++ b/serial/tools/miniterm.py
@@ -36,6 +36,8 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class ConsoleBase(object):
+ """OS abstraction for console (input/output codec, no echo)"""
+
def __init__(self):
if sys.version_info >= (3, 0):
self.byte_output = sys.stdout.buffer
@@ -44,19 +46,22 @@
self.output = sys.stdout
def setup(self):
- pass
+ """Set console to read single characters, no echo"""
def cleanup(self):
- pass
+ """Restore default console settings"""
def getkey(self):
+ """Read a single key from the console"""
return None
def write_bytes(self, s):
+ """Write bytes (already encoded)"""
self.byte_output.write(s)
self.byte_output.flush()
def write(self, s):
+ """Write string"""
self.output.write(s)
self.output.flush()
@@ -145,7 +150,8 @@
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
else:
- raise NotImplementedError("Sorry no implementation for your platform (%s) available." % sys.platform)
+ raise NotImplementedError(
+ 'Sorry no implementation for your platform ({}) available.'.format(sys.platform))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -326,6 +332,11 @@
self.update_transformations()
self.exit_character = 0x1d # GS/CTRL+]
self.menu_character = 0x14 # Menu: CTRL+T
+ self.alive = None
+ self._reader_alive = None
+ self.receiver_thread = None
+ self.rx_decoder = None
+ self.tx_decoder = None
def _start_reader(self):
"""Start reader thread"""
@@ -358,7 +369,8 @@
self.receiver_thread.join()
def update_transformations(self):
- transformations = [EOL_TRANSFORMATIONS[self.eol]] + [TRANSFORMATIONS[f] for f in self.filters]
+ transformations = [EOL_TRANSFORMATIONS[self.eol]] + [TRANSFORMATIONS[f]
+ for f in self.filters]
self.tx_transformations = [t() for t in transformations]
self.rx_transformations = list(reversed(self.tx_transformations))
@@ -372,17 +384,17 @@
def dump_port_settings(self):
sys.stderr.write("\n--- Settings: {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits}\n".format(
- p=self.serial))
+ p=self.serial))
sys.stderr.write('--- RTS: {:8} DTR: {:8} BREAK: {:8}\n'.format(
- ('active' if self.serial.rts else 'inactive'),
- ('active' if self.serial.dtr else 'inactive'),
- ('active' if self.serial.break_condition else 'inactive')))
+ ('active' if self.serial.rts else 'inactive'),
+ ('active' if self.serial.dtr else 'inactive'),
+ ('active' if self.serial.break_condition else 'inactive')))
try:
sys.stderr.write('--- CTS: {:8} DSR: {:8} RI: {:8} CD: {:8}\n'.format(
- ('active' if self.serial.cts else 'inactive'),
- ('active' if self.serial.dsr else 'inactive'),
- ('active' if self.serial.ri else 'inactive'),
- ('active' if self.serial.cd else 'inactive')))
+ ('active' if self.serial.cts else 'inactive'),
+ ('active' if self.serial.dsr else 'inactive'),
+ ('active' if self.serial.ri else 'inactive'),
+ ('active' if self.serial.cd else 'inactive')))
except serial.SerialException:
# on RFC 2217 ports, it can happen if no modem state notification was
# yet received. ignore this error.
@@ -494,8 +506,8 @@
elif c == '\x06': # CTRL+F -> edit filters
sys.stderr.write('\n--- Available Filters:\n')
sys.stderr.write('\n'.join(
- '--- {:<10} = {.__doc__}'.format(k, v)
- for k, v in sorted(TRANSFORMATIONS.items())))
+ '--- {:<10} = {.__doc__}'.format(k, v)
+ for k, v in sorted(TRANSFORMATIONS.items())))
sys.stderr.write('\n--- Enter new filter name(s) [{}]: '.format(' '.join(self.filters)))
with self.console:
new_filters = sys.stdin.readline().lower().split()
@@ -661,124 +673,124 @@
import argparse
parser = argparse.ArgumentParser(
- description="Miniterm - A simple terminal program for the serial port.")
+ description="Miniterm - A simple terminal program for the serial port.")
parser.add_argument(
- "port",
- nargs='?',
- help="serial port name ('-' to show port list)",
- default=default_port)
+ "port",
+ nargs='?',
+ help="serial port name ('-' to show port list)",
+ default=default_port)
parser.add_argument(
- "baudrate",
- nargs='?',
- type=int,
- help="set baud rate, default: %(default)s",
- default=default_baudrate)
+ "baudrate",
+ nargs='?',
+ type=int,
+ help="set baud rate, default: %(default)s",
+ default=default_baudrate)
group = parser.add_argument_group("port settings")
group.add_argument(
- "--parity",
- choices=['N', 'E', 'O', 'S', 'M'],
- type=lambda c: c.upper(),
- help="set parity, one of {N E O S M}, default: N",
- default='N')
+ "--parity",
+ choices=['N', 'E', 'O', 'S', 'M'],
+ type=lambda c: c.upper(),
+ help="set parity, one of {N E O S M}, default: N",
+ default='N')
group.add_argument(
- "--rtscts",
- action="store_true",
- help="enable RTS/CTS flow control (default off)",
- default=False)
+ "--rtscts",
+ action="store_true",
+ help="enable RTS/CTS flow control (default off)",
+ default=False)
group.add_argument(
- "--xonxoff",
- action="store_true",
- help="enable software flow control (default off)",
- default=False)
+ "--xonxoff",
+ action="store_true",
+ help="enable software flow control (default off)",
+ default=False)
group.add_argument(
- "--rts",
- type=int,
- help="set initial RTS line state (possible values: 0, 1)",
- default=default_rts)
+ "--rts",
+ type=int,
+ help="set initial RTS line state (possible values: 0, 1)",
+ default=default_rts)
group.add_argument(
- "--dtr",
- type=int,
- help="set initial DTR line state (possible values: 0, 1)",
- default=default_dtr)
+ "--dtr",
+ type=int,
+ help="set initial DTR line state (possible values: 0, 1)",
+ default=default_dtr)
group.add_argument(
- "--ask",
- action="store_true",
- help="ask again for port when open fails",
- default=False)
+ "--ask",
+ action="store_true",
+ help="ask again for port when open fails",
+ default=False)
group = parser.add_argument_group("data handling")
group.add_argument(
- "-e", "--echo",
- action="store_true",
- help="enable local echo (default off)",
- default=False)
+ "-e", "--echo",
+ action="store_true",
+ help="enable local echo (default off)",
+ default=False)
group.add_argument(
- "--encoding",
- dest="serial_port_encoding",
- metavar="CODEC",
- help="set the encoding for the serial port (e.g. hexlify, Latin1, UTF-8), default: %(default)s",
- default='UTF-8')
+ "--encoding",
+ dest="serial_port_encoding",
+ metavar="CODEC",
+ help="set the encoding for the serial port (e.g. hexlify, Latin1, UTF-8), default: %(default)s",
+ default='UTF-8')
group.add_argument(
- "-f", "--filter",
- action="append",
- metavar="NAME",
- help="add text transformation",
- default=[])
+ "-f", "--filter",
+ action="append",
+ metavar="NAME",
+ help="add text transformation",
+ default=[])
group.add_argument(
- "--eol",
- choices=['CR', 'LF', 'CRLF'],
- type=lambda c: c.upper(),
- help="end of line mode",
- default='CRLF')
+ "--eol",
+ choices=['CR', 'LF', 'CRLF'],
+ type=lambda c: c.upper(),
+ help="end of line mode",
+ default='CRLF')
group.add_argument(
- "--raw",
- action="store_true",
- help="Do no apply any encodings/transformations",
- default=False)
+ "--raw",
+ action="store_true",
+ help="Do no apply any encodings/transformations",
+ default=False)
group = parser.add_argument_group("hotkeys")
group.add_argument(
- "--exit-char",
- type=int,
- metavar='NUM',
- help="Unicode of special character that is used to exit the application, default: %(default)s",
- default=0x1d) # GS/CTRL+]
+ "--exit-char",
+ type=int,
+ metavar='NUM',
+ help="Unicode of special character that is used to exit the application, default: %(default)s",
+ default=0x1d) # GS/CTRL+]
group.add_argument(
- "--menu-char",
- type=int,
- metavar='NUM',
- help="Unicode code of special character that is used to control miniterm (menu), default: %(default)s",
- default=0x14) # Menu: CTRL+T
+ "--menu-char",
+ type=int,
+ metavar='NUM',
+ help="Unicode code of special character that is used to control miniterm (menu), default: %(default)s",
+ default=0x14) # Menu: CTRL+T
group = parser.add_argument_group("diagnostics")
group.add_argument(
- "-q", "--quiet",
- action="store_true",
- help="suppress non-error messages",
- default=False)
+ "-q", "--quiet",
+ action="store_true",
+ help="suppress non-error messages",
+ default=False)
group.add_argument(
- "--develop",
- action="store_true",
- help="show Python traceback on error",
- default=False)
+ "--develop",
+ action="store_true",
+ help="show Python traceback on error",
+ default=False)
args = parser.parse_args()
@@ -789,8 +801,8 @@
if 'help' in args.filter:
sys.stderr.write('Available filters:\n')
sys.stderr.write('\n'.join(
- '{:<10} = {.__doc__}'.format(k, v)
- for k, v in sorted(TRANSFORMATIONS.items())))
+ '{:<10} = {.__doc__}'.format(k, v)
+ for k, v in sorted(TRANSFORMATIONS.items())))
sys.stderr.write('\n')
sys.exit(1)
filters = args.filter
@@ -810,13 +822,13 @@
parser.error('port is not given')
try:
serial_instance = serial.serial_for_url(
- args.port,
- args.baudrate,
- parity=args.parity,
- rtscts=args.rtscts,
- xonxoff=args.xonxoff,
- timeout=1,
- do_not_open=True)
+ args.port,
+ args.baudrate,
+ parity=args.parity,
+ rtscts=args.rtscts,
+ xonxoff=args.xonxoff,
+ timeout=1,
+ do_not_open=True)
if args.dtr is not None:
if not args.quiet:
@@ -840,10 +852,10 @@
break
miniterm = Miniterm(
- serial_instance,
- echo=args.echo,
- eol=args.eol.lower(),
- filters=filters)
+ serial_instance,
+ echo=args.echo,
+ eol=args.eol.lower(),
+ filters=filters)
miniterm.exit_character = unichr(args.exit_char)
miniterm.menu_character = unichr(args.menu_char)
miniterm.raw = args.raw
@@ -852,12 +864,12 @@
if not args.quiet:
sys.stderr.write('--- Miniterm on {p.name} {p.baudrate},{p.bytesize},{p.parity},{p.stopbits} ---\n'.format(
- p=miniterm.serial))
+ p=miniterm.serial))
sys.stderr.write('--- Quit: {} | Menu: {} | Help: {} followed by {} ---\n'.format(
- key_description(miniterm.exit_character),
- key_description(miniterm.menu_character),
- key_description(miniterm.menu_character),
- key_description('\x08')))
+ key_description(miniterm.exit_character),
+ key_description(miniterm.menu_character),
+ key_description(miniterm.menu_character),
+ key_description('\x08')))
miniterm.start()
try: