-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
339 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
"""Simple FTDI EEPROM configurator. | ||
""" | ||
|
||
# Copyright (c) 2019-2022, Emmanuel Blot <[email protected]> | ||
# Copyright (c) 2019-2024, Emmanuel Blot <[email protected]> | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from argparse import ArgumentParser, FileType | ||
from io import StringIO | ||
from logging import Formatter, StreamHandler, DEBUG, ERROR | ||
from sys import modules, stderr, stdout | ||
from sys import exit as sys_exit, modules, stderr, stdout | ||
from textwrap import fill | ||
from traceback import format_exc | ||
from pyftdi import FtdiLogger | ||
|
@@ -86,9 +86,9 @@ def main(): | |
|
||
extra = argparser.add_argument_group(title='Extras') | ||
extra.add_argument('-v', '--verbose', action='count', default=0, | ||
help='increase verbosity') | ||
help='increase verbosity') | ||
extra.add_argument('-d', '--debug', action='store_true', | ||
help='enable debug mode') | ||
help='enable debug mode') | ||
args = argparser.parse_args() | ||
debug = args.debug | ||
|
||
|
@@ -138,13 +138,12 @@ def main(): | |
helpstr = ', '.join(sorted(eeprom.properties)) | ||
print(fill(helpstr, initial_indent=' ', | ||
subsequent_indent=' ')) | ||
exit(1) | ||
sys_exit(1) | ||
for sep in ':=': | ||
if sep in conf: | ||
name, value = conf.split(sep, 1) | ||
if not value: | ||
argparser.error('Configuration %s without value' % | ||
conf) | ||
argparser.error(f'Configuration {conf} without value') | ||
if value == 'help': | ||
value = '?' | ||
helpio = StringIO() | ||
|
@@ -153,10 +152,10 @@ def main(): | |
if helpstr: | ||
print(fill(helpstr, initial_indent=' ', | ||
subsequent_indent=' ')) | ||
exit(1) | ||
sys_exit(1) | ||
break | ||
else: | ||
argparser.error('Missing name:value separator in %s' % conf) | ||
argparser.error(f'Missing name:value separator in {conf}') | ||
if args.vid: | ||
eeprom.set_property('vendor_id', args.vid) | ||
if args.pid: | ||
|
@@ -166,7 +165,7 @@ def main(): | |
if args.hexblock is not None: | ||
indent = ' ' * args.hexblock | ||
for pos in range(0, len(eeprom.data), 16): | ||
hexa = ' '.join(['%02x' % x for x in eeprom.data[pos:pos+16]]) | ||
hexa = ' '.join([f'{x:02x}' for x in eeprom.data[pos:pos+16]]) | ||
print(indent, hexa, sep='') | ||
if args.update: | ||
if eeprom.commit(False, no_crc=args.full_erase): | ||
|
@@ -181,12 +180,12 @@ def main(): | |
eeprom.save_config(ofp) | ||
|
||
except (ImportError, IOError, NotImplementedError, ValueError) as exc: | ||
print('\nError: %s' % exc, file=stderr) | ||
print(f'\nError: {exc}', file=stderr) | ||
if debug: | ||
print(format_exc(chain=False), file=stderr) | ||
exit(1) | ||
sys_exit(1) | ||
except KeyboardInterrupt: | ||
exit(2) | ||
sys_exit(2) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2019-2022, Emmanuel Blot <[email protected]> | ||
# Copyright (c) 2019-2024, Emmanuel Blot <[email protected]> | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
@@ -9,7 +9,7 @@ | |
|
||
from argparse import ArgumentParser, FileType | ||
from logging import Formatter, StreamHandler, DEBUG, ERROR | ||
from sys import modules, stderr | ||
from sys import exit as sys_exit, modules, stderr | ||
from traceback import format_exc | ||
from pyftdi import FtdiLogger | ||
from pyftdi.ftdi import Ftdi | ||
|
@@ -62,12 +62,12 @@ def main(): | |
Ftdi.show_devices() | ||
|
||
except (ImportError, IOError, NotImplementedError, ValueError) as exc: | ||
print('\nError: %s' % exc, file=stderr) | ||
print(f'\nError: {exc}', file=stderr) | ||
if debug: | ||
print(format_exc(chain=False), file=stderr) | ||
exit(1) | ||
sys_exit(1) | ||
except KeyboardInterrupt: | ||
exit(2) | ||
sys_exit(2) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.