summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile1
-rw-r--r--tools/bitdiff.py166
-rwxr-xr-xtools/check_commit.sh93
-rw-r--r--tools/cpep8.blacklist18
-rw-r--r--tools/cpep8.manifest144
-rwxr-xr-xtools/cpep8.py82
-rwxr-xr-xtools/fast-driver.py104
-rwxr-xr-xtools/icomsio.sh1
-rw-r--r--tools/img2thd72.py127
-rw-r--r--tools/py3_driver_progress.py164
-rw-r--r--tools/serialsniff.c2
11 files changed, 420 insertions, 482 deletions
diff --git a/tools/Makefile b/tools/Makefile
index a9f08af..df750f3 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -32,4 +32,3 @@ serialsniff: serialsniff.c
clean:
$(REMOVE) serialsniff *~ *.o *.bak core tags shar a.out
-
diff --git a/tools/bitdiff.py b/tools/bitdiff.py
deleted file mode 100644
index d06bdb2..0000000
--- a/tools/bitdiff.py
+++ /dev/null
@@ -1,166 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2013 Jens Jensen AF5MI <kd4tjx@yahoo.com>
-
-import sys
-import os
-import argparse
-import time
-
-
-def printDiff(pos, byte1, byte2, args):
- bits1 = '{0:08b}'.format(byte1)
- bits2 = '{0:08b}'.format(byte2)
- print "@%04Xh" % pos
- print "1:%02Xh, %sb" % (byte1, bits1)
- print "2:%02Xh, %sb" % (byte2, bits2)
- if args.csv:
- writeDiffCSV(pos, byte1, byte2, args)
-
-
-def writeDiffCSV(pos, byte1, byte2, args):
- bits1 = '{0:08b}'.format(byte1)
- bits2 = '{0:08b}'.format(byte2)
- csvline = '%s, %s, %04X, %02X, %s, %02X, %s, %s, %s' % \
- (args.file1, args.file2, pos, byte1, bits1,
- byte2, bits2, args.setting, args.value)
- if not os.path.isfile(args.csv):
- fh = open(args.csv, "w")
- header = "filename1, filename2, byte_offset, byte1, " \
- "bits1, byte2, bits2, item_msg, value_msg"
- fh.write(header + os.linesep)
- else:
- fh = open(args.csv, "a")
- fh.write(csvline + os.linesep)
- fh.close()
-
-
-def compareFiles(args):
- f1 = open(args.file1, "rb")
- f1.seek(args.offset)
- f2 = open(args.file2, "rb")
- f2.seek(args.offset)
-
- while True:
- pos = f1.tell() - args.offset
- c1 = f1.read(1)
- c2 = f2.read(1)
- if not (c1 and c2):
- break
- b1 = ord(c1)
- b2 = ord(c2)
- if b1 != b2:
- printDiff(pos, b1, b2, args)
-
- pos = f1.tell() - args.offset
- print "bytes read: %02d" % pos
- f1.close()
- f2.close()
-
-
-def compareFilesDat(args):
- f1 = open(args.file1, "r")
- f1contents = f1.read()
- f1.close()
- f2 = open(args.file2, "r")
- f2contents = f2.read()
- f2.close()
-
- f1strlist = f1contents.split()
- f1intlist = map(int, f1strlist)
- f2strlist = f2contents.split()
- f2intlist = map(int, f2strlist)
- f1bytes = bytearray(f1intlist)
- f2bytes = bytearray(f2intlist)
-
- length = len(f1intlist)
- for i in range(length):
- b1 = f1bytes[i]
- b2 = f2bytes[i]
- pos = i
- if b1 != b2:
- printDiff(pos, b1, b2, args)
-
- pos = length
- print "bytes read: %02d" % pos
-
-
-def convertFileToBin(args):
- f1 = open(args.file1, "r")
- f1contents = f1.read()
- f1.close()
- f1strlist = f1contents.split()
- f1intlist = map(int, f1strlist)
- f1bytes = bytearray(f1intlist)
- f2 = open(args.file2, "wb")
- f2.write(f1bytes)
- f2.close
-
-
-def convertFileToDat(args):
- f1 = open(args.file1, "rb")
- f1contents = f1.read()
- f1.close()
- f2 = open(args.file2, "w")
- for i in range(0, len(f1contents)):
- f2.write(" %d " % (ord(f1contents[i]), ))
- if i % 16 == 15:
- f2.write("\r\n")
- f2.close
-
-
-# main
-
-ap = argparse.ArgumentParser(description="byte-/bit- comparison of two files")
-ap.add_argument("file1", help="first (reference) file to parse")
-ap.add_argument("file2", help="second file to parse")
-
-mutexgrp1 = ap.add_mutually_exclusive_group()
-mutexgrp1.add_argument("-o", "--offset", default=0,
- help="offset (hex) to start comparison")
-mutexgrp1.add_argument("-d", "--dat", action="store_true",
- help="process input files from .DAT/.ADJ format "
- "(from 'jujumao' oem programming software "
- "for chinese radios)")
-mutexgrp1.add_argument("--convert2bin", action="store_true",
- help="convert file1 from .dat/.adj to "
- "binary image file2")
-mutexgrp1.add_argument("--convert2dat", action="store_true",
- help="convert file1 from bin to .dat/.adj file2")
-
-ap.add_argument("-w", "--watch", action="store_true",
- help="'watch' changes. runs in a loop")
-
-csvgrp = ap.add_argument_group("csv output")
-csvgrp.add_argument("-c", "--csv",
- help="file to append csv results. format: filename1, "
- "filename2, byte_offset, byte1, bits1, byte2, "
- "bits2, item_msg, value_msg")
-csvgrp.add_argument("-s", "--setting",
- help="user-meaningful field indicating setting/item "
- "modified, e.g. 'beep' or 'txtone'")
-csvgrp.add_argument("-v", "--value",
- help="user-meaningful field indicating values "
- "changed, e.g. 'true->false' or '110.9->100.0'")
-
-args = ap.parse_args()
-if args.offset:
- args.offset = int(args.offset, 16)
-
-print "f1:", args.file1, " f2:", args.file2
-if args.setting or args.value:
- print "setting:", args.setting, "- value:", args.value
-
-while True:
- if (args.dat):
- compareFilesDat(args)
- elif (args.convert2bin):
- convertFileToBin(args)
- elif (args.convert2dat):
- convertFileToDat(args)
- else:
- compareFiles(args)
- if not args.watch:
- break
- print "------"
- time.sleep(delay)
diff --git a/tools/check_commit.sh b/tools/check_commit.sh
new file mode 100755
index 0000000..c92c2b0
--- /dev/null
+++ b/tools/check_commit.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+BASE=${1:-origin/master}
+RETCODE=0
+
+RED='\033[1;31m'
+GREEN='\033[1;32m'
+NC='\033[0m'
+
+function fail() {
+ echo -e "${RED}$*${NC}"
+ RETCODE=1
+}
+
+echo -e "${GREEN}Checking from $(git rev-parse --short ${BASE}):${NC}"
+git log --pretty=oneline --no-merges --abbrev-commit ${BASE}..
+echo
+
+git diff ${BASE}.. '*.py' | grep '^+' > added_lines
+
+if grep -E '(from|import).*six' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '\wsix\w' added_lines; then
+ fail No new uses of six
+fi
+
+if grep -E '(from|import).*builtins' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '\wfuture\w' added_lines; then
+ fail No new uses of future
+fi
+
+if grep -E '(from|import).*past' added_lines; then
+ fail Use of past library not allowed
+fi
+
+if grep -E 'MemoryMap\(' added_lines; then
+ fail New uses of MemoryMap should be MemoryMapBytes
+fi
+
+if grep -E "[^_]_\([^\"']" added_lines; then
+ fail 'Translated strings must be literals!'
+fi
+
+if grep '/cpep8.manifest' added_lines; then
+ fail 'Do not add new files to cpep8.manifest; no longer needed'
+fi
+
+if grep '/cpep8.blacklist' added_lines; then
+ fail 'Do not add new files to cpep8.blacklist'
+fi
+
+grep -i 'license' added_lines > license_lines
+if grep -ivE '(GNU General Public License|Free Software Foundation|gnu.org.licenses)' license_lines; then
+ fail 'Files must be GPLv3 licensed (or not contain any license language)'
+fi
+
+for file in $(git diff --name-only ${BASE}..); do
+ if file $file | grep -q CRLF; then
+ fail "$file : Files should be LF (Unix) format, not CR (Mac) or CRLF (Windows)"
+ fi
+done
+
+if git log ${BASE}.. --merges | grep .; then
+ fail Please do not include merge commits in your PR
+fi
+
+make -C chirp/locale clean all >/dev/null 2>&1
+if git diff chirp/locale | grep '^\+[^#+]' | grep -v POT-Creation; then
+ fail Locale files need updating
+fi
+
+added_files=$(git diff --name-only --diff-filter=A ${BASE}.. 2>&1)
+if echo $added_files | grep -q chirp.drivers && ! echo $added_files | grep -q tests.images; then
+ fail All new drivers should include a test image
+fi
+
+existing_drivers=$(git ls-tree --name-only $BASE chirp/drivers/)
+limit=20
+for nf in $added_files; do
+ for of in $existing_drivers; do
+ change=$(wdiff -s $of $nf | grep $of | sed -r 's/.* ([0-9]+)% changed/\1/')
+ if [ "$change" -lt "$limit" ]; then
+ fail "New file $nf shares at least $((100 - $change))% with $of!"
+ fi
+ done
+done
+
+exit $RETCODE
diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist
index 6a98e72..7011690 100644
--- a/tools/cpep8.blacklist
+++ b/tools/cpep8.blacklist
@@ -1,3 +1,21 @@
# cpep8.blacklist: The list of files that do not meet PEP8 standards.
# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant.
# Over time, this list should shrink and (eventually) be eliminated.
+./chirp/drivers/kyd_IP620.py
+./chirp/drivers/kguv8dplus.py
+./chirp/drivers/ft450d.py
+./chirp/drivers/ft70.py
+./chirp/drivers/hg_uv98.py
+./chirp/drivers/hobbypcb.py
+./chirp/drivers/retevis_rb28.py
+./chirp/drivers/bj9900.py
+./chirp/drivers/th7800.py
+./chirp/drivers/icx90.py
+./chirp/drivers/kguv8e.py
+./chirp/drivers/rh5r_v2.py
+./chirp/drivers/puxing_px888k.py
+./chirp/drivers/ftlx011.py
+./chirp/drivers/icv86.py
+./chirp/drivers/fd268.py
+./chirp/drivers/tk270.py
+./chirp/drivers/bf_t1.py
diff --git a/tools/cpep8.manifest b/tools/cpep8.manifest
index 57a6982..4722d1f 100644
--- a/tools/cpep8.manifest
+++ b/tools/cpep8.manifest
@@ -1,85 +1,39 @@
-./chirp/__init__.py
-./chirp/bandplan.py
-./chirp/bandplan_au.py
-./chirp/bandplan_iaru_r1.py
-./chirp/bandplan_iaru_r2.py
-./chirp/bandplan_iaru_r3.py
-./chirp/bandplan_na.py
-./chirp/bitwise.py
-./chirp/bitwise_grammar.py
-./chirp/chirp_common.py
-./chirp/detect.py
-./chirp/directory.py
-./chirp/drivers/__init__.py
+#
+#
+# NOTE: Do not add files to this manifest anymore. New files will be run
+# under flake8 automatically if they are in the tree. Files in this manifest
+# will continue to run under cpep8's less-strict rules until they can be
+# fixed.
+#
+#
./chirp/drivers/alinco.py
-./chirp/drivers/anytone.py
-./chirp/drivers/anytone_ht.py
./chirp/drivers/anytone778uv.py
-./chirp/drivers/ap510.py
+./chirp/drivers/anytone_ht.py
+./chirp/drivers/anytone_iii.py
./chirp/drivers/baofeng_common.py
./chirp/drivers/baofeng_uv3r.py
-./chirp/drivers/baofeng_wp970i.py
-./chirp/drivers/bf-t8.py
-./chirp/drivers/bjuv55.py
+./chirp/drivers/bf_t8.py
./chirp/drivers/btech.py
-./chirp/drivers/ft1500m.py
-./chirp/drivers/ft1802.py
./chirp/drivers/ft1d.py
-./chirp/drivers/ft2800.py
./chirp/drivers/ft2900.py
-./chirp/drivers/ft4.py
-./chirp/drivers/ft50.py
./chirp/drivers/ft60.py
-./chirp/drivers/ft7100.py
./chirp/drivers/ft7800.py
-./chirp/drivers/ft817.py
-./chirp/drivers/ft818.py
-./chirp/drivers/ft857.py
./chirp/drivers/ft90.py
-./chirp/drivers/ftm350.py
./chirp/drivers/ga510.py
./chirp/drivers/generic_csv.py
-./chirp/drivers/generic_tpe.py
-./chirp/drivers/gmrsuv1.py
./chirp/drivers/gmrsv2.py
./chirp/drivers/h777.py
-./chirp/drivers/ic208.py
-./chirp/drivers/ic2100.py
-./chirp/drivers/ic2200.py
-./chirp/drivers/ic2720.py
./chirp/drivers/ic2730.py
-./chirp/drivers/ic2820.py
-./chirp/drivers/ic9x.py
-./chirp/drivers/ic9x_icf.py
-./chirp/drivers/ic9x_icf_ll.py
-./chirp/drivers/ic9x_ll.py
./chirp/drivers/icf.py
./chirp/drivers/icomciv.py
-./chirp/drivers/icq7.py
-./chirp/drivers/ict70.py
-./chirp/drivers/ict7h.py
-./chirp/drivers/ict8.py
-./chirp/drivers/icw32.py
-./chirp/drivers/icx8x.py
-./chirp/drivers/icx8x_ll.py
-./chirp/drivers/id31.py
-./chirp/drivers/id51.py
-./chirp/drivers/id800.py
-./chirp/drivers/id880.py
-./chirp/drivers/idrp.py
-./chirp/drivers/iradio_uv-5118.py
-./chirp/drivers/kenwood_hmk.py
-./chirp/drivers/kenwood_itm.py
+./chirp/drivers/iradio_uv_5118.py
./chirp/drivers/kenwood_live.py
./chirp/drivers/kg935g.py
-./chirp/drivers/kguv8d.py
./chirp/drivers/kguv920pa.py
./chirp/drivers/kguv9dplus.py
./chirp/drivers/kyd.py
./chirp/drivers/leixen.py
./chirp/drivers/lt725uv.py
-./chirp/drivers/mursv1.py
-./chirp/drivers/puxing.py
./chirp/drivers/radioddity_r2.py
./chirp/drivers/radtel_t18.py
./chirp/drivers/retevis_rb15.py
@@ -92,94 +46,24 @@
./chirp/drivers/retevis_rt76p.py
./chirp/drivers/retevis_rt87.py
./chirp/drivers/retevis_rt98.py
-./chirp/drivers/rfinder.py
./chirp/drivers/tdxone_tdq8a.py
-./chirp/drivers/template.py
-./chirp/drivers/tg_uv2p.py
-./chirp/drivers/th350.py
+./chirp/drivers/th9000.py
./chirp/drivers/th9800.py
./chirp/drivers/th_uv3r.py
./chirp/drivers/th_uv3r25.py
./chirp/drivers/th_uv8000.py
./chirp/drivers/th_uv88.py
-./chirp/drivers/th_uvf8d.py
-./chirp/drivers/th9000.py
-./chirp/drivers/th9800.py
./chirp/drivers/thd72.py
-./chirp/drivers/thuv1f.py
./chirp/drivers/tk760.py
-./chirp/drivers/tk8102.py
+./chirp/drivers/tk760g.py
./chirp/drivers/tk8180.py
./chirp/drivers/tmd710.py
-./chirp/drivers/tmv71.py
-./chirp/drivers/tmv71_ll.py
./chirp/drivers/ts480.py
./chirp/drivers/ts590.py
./chirp/drivers/uv5r.py
./chirp/drivers/uv5x3.py
-./chirp/drivers/uv6r.py
-./chirp/drivers/uvb5.py
./chirp/drivers/vgc.py
-./chirp/drivers/vx170.py
-./chirp/drivers/vx2.py
-./chirp/drivers/vx3.py
-./chirp/drivers/vx5.py
-./chirp/drivers/vx510.py
./chirp/drivers/vx6.py
./chirp/drivers/vx7.py
./chirp/drivers/vx8.py
-./chirp/drivers/vxa700.py
./chirp/drivers/wouxun.py
-./chirp/drivers/wouxun_common.py
-./chirp/drivers/yaesu_clone.py
-./chirp/elib_intl.py
-./chirp/errors.py
-./chirp/import_logic.py
-./chirp/logger.py
-./chirp/memmap.py
-./chirp/platform.py
-./chirp/pyPEG.py
-./chirp/radioreference.py
-./chirp/settings.py
-./chirp/ui/__init__.py
-./chirp/ui/bandplans.py
-./chirp/ui/bankedit.py
-./chirp/ui/clone.py
-./chirp/ui/cloneprog.py
-./chirp/ui/common.py
-./chirp/ui/config.py
-./chirp/ui/dstaredit.py
-./chirp/ui/editorset.py
-./chirp/ui/fips.py
-./chirp/ui/importdialog.py
-./chirp/ui/inputdialog.py
-./chirp/ui/mainapp.py
-./chirp/ui/memdetail.py
-./chirp/ui/memedit.py
-./chirp/ui/miscwidgets.py
-./chirp/ui/radiobrowser.py
-./chirp/ui/reporting.py
-./chirp/ui/settingsedit.py
-./chirp/ui/shiftdialog.py
-./chirp/util.py
-./chirpc
-./chirpw
-./locale/check_parameters.py
-./rpttool
-./setup.py
-./share/make_supported.py
-./tests/__init__.py
-./tests/run_tests
-./tests/unit/__init__.py
-./tests/unit/base.py
-./tests/unit/test_bitwise.py
-./tests/unit/test_chirp_common.py
-./tests/unit/test_import_logic.py
-./tests/unit/test_mappingmodel.py
-./tests/unit/test_memedit_edits.py
-./tests/unit/test_platform.py
-./tests/unit/test_settings.py
-./tests/unit/test_shiftdialog.py
-./tools/bitdiff.py
-./tools/cpep8.py
-./tools/img2thd72.py
diff --git a/tools/cpep8.py b/tools/cpep8.py
index b073f48..678281f 100755
--- a/tools/cpep8.py
+++ b/tools/cpep8.py
@@ -17,16 +17,24 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import warnings
+
import os
import sys
-import logging
import argparse
-import pep8
+import subprocess
+
+# pep8 has a FutureWarning about nested sets. This isn't our problem, so
+# squelch it here during import.
+with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ import pep8
+
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", action="store_true",
help="Check all files, ignoring blacklist")
-parser.add_argument("-d", "--dir", action="store", default=".",
+parser.add_argument("-d", "--dir", action="append", default=['chirp', 'tests'],
help="Root directory of source tree")
parser.add_argument("-s", "--stats", action="store_true",
help="Only show statistics")
@@ -48,7 +56,7 @@ def file_to_lines(name):
lines = fh.read().split("\n")
lines.pop()
fh.close()
- return lines
+ return [x for x in lines if not x.startswith('#')]
scriptdir = os.path.dirname(sys.argv[0])
@@ -56,20 +64,21 @@ manifest_filename = os.path.join(scriptdir, "cpep8.manifest")
blacklist_filename = os.path.join(scriptdir, "cpep8.blacklist")
exceptions_filename = os.path.join(scriptdir, "cpep8.exceptions")
-manifest = []
-if args.scan:
- for root, dirs, files in os.walk(args.dir):
+cpep8_manifest = set(file_to_lines(manifest_filename))
+flake8_manifest = set()
+for src_dir in [os.path.join('.', d) for d in args.dir]:
+ for root, dirs, files in os.walk(src_dir):
for f in files:
filename = os.path.join(root, f)
+ if filename.replace('\\', '/') in cpep8_manifest:
+ continue
if f.endswith('.py'):
- manifest.append(filename)
+ flake8_manifest.add(filename)
continue
- with open(filename, "r") as fh:
+ with open(filename, "rb") as fh:
shebang = fh.readline()
- if shebang.startswith("#!/usr/bin/env python"):
- manifest.append(filename)
-else:
- manifest += file_to_lines(manifest_filename)
+ if shebang.startswith(b"#!/usr/bin/env python"):
+ flake8_manifest.add(filename)
# unless we are being --strict, load per-file style exceptions
@@ -89,37 +98,25 @@ def get_exceptions(f):
ignore = None
return ignore
-if args.update:
- print("Starting update of %d files" % len(manifest))
- bad = []
- for f in manifest:
- checker = pep8.StyleGuide(quiet=True, ignore=get_exceptions(f))
- results = checker.check_files([f])
- if results.total_errors:
- bad.append(f)
- print("%s: %s" % (results.total_errors and "FAIL" or "PASS", f))
-
- with open(blacklist_filename, "w") as fh:
- fh.write("""\
-# cpep8.blacklist: The list of files that do not meet PEP8 standards.
-# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant.
-# Over time, this list should shrink and (eventually) be eliminated.""")
- fh.write("\n".join(sorted(bad)))
-
- if args.scan:
- with open(manifest_filename, "w") as fh:
- fh.write("\n".join(sorted(manifest)))
- sys.exit(0)
if args.files:
- manifest = args.files
+ old_files = cpep8_manifest
+ cpep8_manifest = []
+ flake8_manifest = []
+ for fn in args.files:
+ if not fn.startswith('./'):
+ fn = './' + fn
+ if fn in old_files:
+ cpep8_manifest.append(fn)
+ else:
+ flake8_manifest.append(fn)
# read the blacklisted source files
blacklist = file_to_lines(blacklist_filename)
check_list = []
-for f in manifest:
- if args.all or f not in blacklist:
+for f in cpep8_manifest:
+ if args.all or f.replace('\\', '/') not in blacklist:
check_list.append(f)
check_list = sorted(check_list)
@@ -134,4 +131,15 @@ for f in check_list:
checker.report.print_statistics()
total_errors += results
+flake8_manifest = [f for f in flake8_manifest
+ if f.replace('\\', '/') not in blacklist]
+
+for i in range(0, len(flake8_manifest), 10):
+ files = flake8_manifest[i:i + 10]
+ if args.verbose:
+ print('Checking %s' % files)
+ r = subprocess.call(['flake8', '--builtins=_'] + files)
+ if r != 0:
+ total_errors += r
+
sys.exit(total_errors and 1 or 0)
diff --git a/tools/fast-driver.py b/tools/fast-driver.py
new file mode 100755
index 0000000..669a5e1
--- /dev/null
+++ b/tools/fast-driver.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env Python3
+
+import glob
+import os
+import subprocess
+import sys
+
+
+def parse_import_line(line):
+ pieces = line.split()
+ if line.startswith('from'):
+ base = pieces[1]
+ if 'drivers.' in base:
+ imports = [base.split('.')[-1]]
+ return imports
+ else:
+ imports = pieces[3:]
+ if pieces[-1].endswith(','):
+ raise Exception('Failed to parse multi-line import')
+ return [x.strip().strip(',') for x in imports]
+ elif 'drivers' in line:
+ raise Exception('Unhandled bare import driver line: %s' % line)
+ else:
+ return []
+
+
+def find_imports(of_modules):
+ driver_imports = []
+ for fn in glob.glob('chirp/drivers/*.py'):
+ with open(fn) as f:
+ lines = [ln for ln in f.readlines()
+ if 'import ' in ln and 'drivers' in ln]
+ imports = []
+ for line in lines:
+ imports.extend(parse_import_line(line))
+ if set(imports) & of_modules:
+ driver_imports.append(os.path.splitext(os.path.basename(fn))[0])
+ return driver_imports
+
+
+files = subprocess.check_output(
+ ['git', 'diff', 'origin/master', '--name-only', '.']).decode().split()
+
+# A list of modules and their parent [(chirp/drivers, tk8180)]
+files_by_module = [x.rsplit('/', 1) for x in files if '/' in x and '.py' in x]
+
+# Grab just the drivers
+driver_modules = set([os.path.splitext(os.path.basename(mod))[0]
+ for parent, mod in files_by_module
+ if parent == 'chirp/drivers'])
+
+# Determine which are live drivers that we don't test with these tests
+live_drivers = set()
+for driver in driver_modules:
+ try:
+ with open(os.path.join('chirp', 'drivers', '%s.py' % driver)) as f:
+ content = f.read()
+ except FileNotFoundError:
+ # File must have been removed
+ continue
+ if 'LiveRadio' in content:
+ live_drivers.add(driver)
+
+print('Touched drivers: %s' % ','.join(driver_modules))
+# Find deps before we remove live modules in case there are any changed
+# modules that depend on the bases that have live drivers in them (i.e. icf or
+# kenwood_live)
+deps = find_imports(driver_modules)
+print('Found deps of touched modules: %s' % ','.join(deps))
+# Remove live drivers from driver_modules before we add in the deps of changed
+# modules, as they may imply some shared code (like icf)
+driver_modules -= live_drivers
+driver_modules.update(set(deps))
+
+# Determine if any base modules have been changed that would necessitate
+# running all the driver tests
+exclude_mods = ('chirp/wxui', 'chirp/cli', 'chirp/sources', 'chirp/drivers',
+ 'chirp/locale', 'chirp/share', 'chirp/stock_configs',
+ 'tools')
+base_modules = [mod for parent, mod in files_by_module
+ if parent not in exclude_mods]
+
+if base_modules:
+ print('Base modules touched; running all drivers: %s' % base_modules)
+ driver_exp = []
+elif driver_modules:
+ driver_exp = ' or '.join(f for f in driver_modules)
+else:
+ print('No driver tests necessary for changes in %s' % ','.join(
+ files))
+ sys.exit(0)
+
+args = ['pytest']
+if driver_exp:
+ args += ['-k', driver_exp]
+args += sys.argv[1:]
+print(args)
+rc = subprocess.call(args)
+if rc == 5:
+ # This means no tests were found likely because we generated a bad
+ # tag, so just run the full set
+ print('Running full driver set')
+ rc = subprocess.call(['pytest'] + sys.argv[1:])
+sys.exit(rc)
diff --git a/tools/icomsio.sh b/tools/icomsio.sh
index f5f126d..8b11107 100755
--- a/tools/icomsio.sh
+++ b/tools/icomsio.sh
@@ -92,4 +92,3 @@ for usbserial in /sys/class/tty/ttyUSB*; do
break
fi
done
-
diff --git a/tools/img2thd72.py b/tools/img2thd72.py
deleted file mode 100644
index 2ed1082..0000000
--- a/tools/img2thd72.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env python
-# coding=utf-8
-# ex: set tabstop=4 expandtab shiftwidth=4 softtabstop=4:
-#
-# © Copyright Vernon Mauery <vernon@mauery.com>, 2010. All Rights Reserved
-#
-# This is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or (at
-# your option) any later version.
-#
-# This software is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this software. If not, see <http://www.gnu.org/licenses/>.
-
-
-import sys
-import getopt
-from PIL import Image as im
-
-
-def die(msg):
- print msg
- sys.exit(1)
-
-
-def thd72bitmap(fname, invert):
- img = im.open(ifname)
- if img.size != (120, 48):
- die("Image has wrong dimensions: must be 120x48")
-
- colors = img.getcolors()
- if len(colors) != 2:
- die("Image must be 1 bits per pixel (black and white)")
-
- if ('-i', '') in opts:
- c, black = colors[0]
- c, white = colors[1]
- else:
- c, white = colors[0]
- c, black = colors[1]
-
- colors = {black: 1, white: 0}
- data = img.getdata()
- buf = ''
- for y in range(6):
- for x in range(120):
- b = 0
- for i in range(8):
- b |= colors[data[x + 120 * (y * 8 + i)]] << i
- buf += chr(b)
- return buf
-
-
-def display_thd72(buf):
- dots = {0: '*', 1: ' '}
- lines = []
- for y in range(48):
- line = ''
- for x in range(120):
- byte = y/8*120 + x
- line += dots[(ord(buf[byte]) >> (y % 8)) & 0x01]
- lines.append(line)
- for l in lines:
- print l
-
-
-def usage():
- print "\nUsage: %s <-s|-g> [-i] [-d] " \
- "<image-file> <thd72-nvram-file>" % sys.argv[0]
- print "\nThis program will modify whatever nvram file provided or will"
- print "create a new one if the file does not exist. After using this to"
- print "modify the image, you can use that file to upload all or part of"
- print "it to your radio"
- print "\nOption explanations:"
- print " -s Save as the startup image"
- print " -g Save as the GPS logger image"
- print " -i Invert colors (black for white)"
- print " Depending on the file format the bits may be inverted."
- print " If your bitmap file turns out to be inverted, use -i."
- print " -d Display the bitmap as dots (for confirmation)"
- print " Each black pixel is '*' and each white pixel is ' '"
- print " This will print up to 120 dots wide, so beware your"
- print " terminal size."
- sys.exit(1)
-
-if __name__ == "__main__":
- opts, args = getopt.getopt(sys.argv[1:], "idgs")
- if len(args) != 2:
- usage()
- ifname = args[0]
- ofname = args[1]
- invert = ('-i', '') in opts
- gps = ('-g', '') in opts
- startup = ('-s', '') in opts
- if (gps and startup) or not (gps or startup):
- usage()
- if gps:
- imgpos = 0xe800
- tagpos = 18
- else:
- imgpos = 0xe500
- tagpos = 17
-
- buf = thd72bitmap(ifname, invert)
- imgfname = ifname + '\xff' * (48-len(ifname))
- of = file(ofname, "rb+")
- of.seek(tagpos)
- of.write('\x01')
- of.seek(imgpos)
- of.write(buf)
- of.write(imgfname)
- of.seek(65536)
- of.close()
-
- if ('-d', '') in opts:
- display_thd72(buf)
-
- blocks = [0, ]
- blocks.append(imgpos/256)
- blocks.append(1+imgpos/256)
- blocks.append(2+imgpos/256)
- print "Modified block list:", blocks
diff --git a/tools/py3_driver_progress.py b/tools/py3_driver_progress.py
index 52a9e2f..bd0f22a 100644
--- a/tools/py3_driver_progress.py
+++ b/tools/py3_driver_progress.py
@@ -2,11 +2,13 @@
import argparse
import csv
+import os
import sys
+import textwrap
from chirp import directory
-directory.safe_import_drivers()
+directory.import_drivers()
def tester_link(text):
@@ -16,26 +18,47 @@ def tester_link(text):
assert text[1:] in directory.DRV_TO_RADIO, \
'%s is not in the driver directory' % text[1:]
return '[Implied by %s](#user-content-%s)' % (text[1:], text[1:])
+ elif text.startswith('*'):
+ assert os.path.exists(os.path.join('chirp', 'drivers',
+ text[1:] + '.py'))
+ return ('[Probably works]('
+ 'https://github.com/kk7ds/chirp'
+ '/blob/py3/chirp/drivers/%s.py)' % (
+ text[1:]))
+ elif text.startswith('#') and text[1:].isdigit():
+ return ('[Reported working]'
+ '(https://chirp.danplanet.com/issues/%i)' % int(text[1:]))
else:
return text
-def main():
- p = argparse.ArgumentParser()
- p.add_argument('testers')
- p.add_argument('-o', '--output', default='-')
- args = p.parse_args()
+def read_stats(statsfile):
+ with open(statsfile) as f:
+ lines = f.readlines()
+
+ models = {}
+ total = 0
+ skip = ['Repeaterbook', 'Radio Reference', 'CHIRP', 'CSV']
+ for line in lines[1:]:
+ model, count = line.strip().split('\t')
+ model = model.replace(' ', '_').\
+ replace('(', '').\
+ replace(')', '').\
+ replace('/', '_')
+ if any(s in model for s in skip):
+ continue
+ count = int(count)
+ models[model] = count
+ total += count
- headers = ['Driver', 'Tester', 'Tested']
- testers = {}
+ return total, models
- if args.output == '-':
- output = sys.stdout
- else:
- output = open(args.output, 'w')
+def read_testers(testersfile):
+ headers = ['Driver', 'Tester', 'Tested']
line = 0
- for fields in csv.reader(open(args.testers)):
+ testers = {}
+ for fields in csv.reader(open(testersfile)):
line += 1
if fields[0][0] == '#':
continue
@@ -53,31 +76,76 @@ def main():
testers[fields[0]] = fields[1:]
+ return testers
+
+
+def get_share_for_radio(stats, stats_total, parent_cls):
+ count = 0
+ for cls in [parent_cls] + parent_cls.ALIASES:
+ driver = directory.radio_class_id(cls)
+ simple_driver = '%s_%s' % (cls.VENDOR, cls.MODEL)
+ if driver in stats:
+ count += stats.pop(driver, 0)
+ elif simple_driver in stats:
+ count += stats.pop(simple_driver, 0)
+
+ if count == 0:
+ share = ''
+ else:
+ pct = (count * 100 / stats_total)
+ share = '%.2f%%' % pct
+ if pct > 1:
+ share = '**%s**' % share
+ return count, share
+
+
+def main():
+ p = argparse.ArgumentParser()
+ p.add_argument('testers')
+ p.add_argument('stats')
+ p.add_argument('-o', '--output', default='-')
+ args = p.parse_args()
+
+ testers = read_testers(args.testers)
+ stats_total, stats = read_stats(args.stats)
+
+ if args.output == '-':
+ output = sys.stdout
+ else:
+ output = open(args.output, 'w')
+
print('## Status', file=output)
- print('| Driver | Tester | Tested | Byte Clean |', file=output)
- print('| ------ | ------ | ------ | ---------- |', file=output)
+ print('| Driver | Tester | Tested | Byte Clean | "Market Share" |',
+ file=output)
+ print('| ------ | ------ | ------ | ---------- | -------------- |',
+ file=output)
drivers = sorted([ident for ident in directory.DRV_TO_RADIO])
drvstested = 0
byteclean = 0
+ tested_stats = 0
for driver in drivers:
cls = directory.get_radio(driver)
tester, tested = testers.pop(driver, ('', ''))
if tester:
drvstested += 1
+ count, share = get_share_for_radio(stats, stats_total, cls)
+ if tester:
+ tested_stats += count
if not cls.NEEDS_COMPAT_SERIAL:
byteclean += 1
- print('| <a name="%s"></a> %s | %s | %s | %s |' % (
+ print('| <a name="%s"></a> %s | %s | %s | %s | %s |' % (
driver, driver, tester_link(tester), tested,
- '' if cls.NEEDS_COMPAT_SERIAL else 'Yes'),
+ '' if cls.NEEDS_COMPAT_SERIAL else 'Yes', share),
file=output)
print('## Stats', file=output)
print('\n**Drivers:** %i' % (len(drivers)), file=output)
- print('\n**Tested:** %i%% (%i/%i)' % (
+ print('\n**Tested:** %i%% (%i/%i) (%i%% of usage stats)' % (
drvstested / len(drivers) * 100,
- drvstested, len(drivers) - drvstested),
+ drvstested, len(drivers) - drvstested,
+ tested_stats * 100 / stats_total),
file=output)
print('\n**Byte clean:** %i%% (%i/%i)' % (
byteclean / len(drivers) * 100,
@@ -85,6 +153,64 @@ def main():
len(drivers) - byteclean),
file=output)
+ print(textwrap.dedent("""
+ ## Meaning of this testing
+
+ The goal here is not necessarily to test the drivers themselves in terms of
+ actual functionality, but rather to validate the Python 3 conversion
+ work required of nearly all drivers. Thus, we are not trying to
+ comprehensively test these models so much as make sure they work at least
+ as well as they do on the Python 2 branch. Uncovering and reporting new
+ bugs is definitely welcome, but for the purpoes of this effort, "no worse
+ than the legacy branch" is good enough. There are multiple levels of
+ confirmation in the matrix above:
+ * Tested with real hardware (i.e. a person listed in the "Tester" column)
+ using roughly the procedure below.
+ * An "implied by (model)" link means that another model was tested, and it
+ is so similar, that the model on that line can be considered tested as
+ well.
+ * A "probably works" link means that the driver has not been tested with
+ real hardware, nor is it substantially similar to another model, but
+ shares a common base that entirely provides the cloning routines with
+ other drivers that have been tested with real hardware, such that
+ confidence is high that it will work. Only drivers with test images in
+ the tree (or live drivers) should be marked with this class.
+ * A "unit tested" link means that the driver has not been tested with
+ real hardware, nor does it share common cloning routines with another
+ radio. However, synthetic simulation tests have been added to exercise
+ the parts of the cloning routines that are likely to fail under python3.
+ This is the lowest-confidence status and a real confirmation is needed.
+
+ If you have a model listed in this matrix with either "implied" or
+ "probably works" status, an actual confirmation with real hardware is
+ welcome and can replace the weaker reference.
+
+ ## Minimal test procedure
+ For the purposes of the Python 3 effort, a "tested" radio means
+ at least the following procedure was followed:
+ 1. Download from the radio
+ 1. Make some change to a memory
+ 1. If the radio has settings support, make sure settings load and tweak
+ one setting
+ 1. Upload to the radio
+ 1. Confirm that the changes stick and look correct, or at least are not a
+ regression from the master py2 branch.
+
+ The drivers are all passing the automated tests, but tests with real
+ hardware and serial ports is important, especially around bytes-vs-string
+ safety.
+
+ To update this document, add/edit entries in `tests/py3_driver_testers.txt`
+ and then run `tox -e makesupported`. Commit the result (including the
+ changes to this `.md` file) and submit a PR.
+
+ The "Byte Clean" flag refers to whether or not the radio has set the
+ `NEEDS_COMPAT_SERIAL = False` flag on the radio class, and thus uses
+ `MemoryMapBytes` exclusively internally. Whenever possible, all radios
+ that are fixed for py3 should do so with this flag set to False and with
+ the byte-native memory map."""),
+ file=output)
+
for driver, (tester, tested) in testers.items():
print('Error in testers file; driver %s by %s on %s unknown' % (
driver, tester, tested), file=sys.stderr)
diff --git a/tools/serialsniff.c b/tools/serialsniff.c
index 02037d7..2454484 100644
--- a/tools/serialsniff.c
+++ b/tools/serialsniff.c
@@ -146,7 +146,7 @@ int saferead(int fd, char *buf, int len)
if ((val.it_value.tv_sec == 0) &&
(val.it_value.tv_usec == 0)) {
if (!quiescent)
- printf("Timeout\n");
+ printf("Timeout\n");
break;
}