[chirp_devel] [PATCH 0/9] assorted CLI improvements
These patches begin to make improvements to CHIRP's CLI. Several of them are repeats from the series earlier this week, though all have been modified extensively to accomodate feedback.
Zach Welch (9): Use argparse in chirpw (#2349) Rename chirp.py as chirpc (#2343) Update chirpc argument parsing (#2343) chirpc: add --list-radios option (#2343) Refactor version display into chirp module (#2343) Add chirp.logger module (#2347) Use new logger module (#2347) Suppress startup debugging messages (#2347) Fix style issues (#2355)
chirp.py | 297 ---------------------------------------------- chirp/anytone.py | 13 +-- chirp/baofeng_uv3r.py | 5 - chirp/bjuv55.py | 5 - chirp/directory.py | 7 +- chirp/ft1d.py | 13 ++- chirp/ft2800.py | 18 ++- chirp/ft60.py | 7 +- chirp/ft7800.py | 27 ++--- chirp/ft817.py | 30 +++-- chirp/ft857.py | 9 +- chirp/ft90.py | 53 +++------ chirp/ftm350.py | 7 +- chirp/h777.py | 16 ++- chirp/icomciv.py | 12 +- chirp/idrp.py | 13 +-- chirp/kenwood_live.py | 11 +- chirp/kguv8d.py | 42 +++---- chirp/kyd.py | 26 ++--- chirp/leixen.py | 5 - chirp/logger.py | 127 ++++++++++++++++++++ chirp/puxing.py | 5 - chirp/th9800.py | 34 +++--- chirp/th_uv3r.py | 5 - chirp/thd72.py | 10 +- chirp/tk8102.py | 8 +- chirp/tmv71_ll.py | 10 +- chirp/uv5r.py | 26 ++--- chirp/version.py | 34 ++++++ chirp/vx170.py | 5 - chirp/vx2.py | 29 ++--- chirp/vx3.py | 31 ++--- chirp/vx8.py | 11 +- chirp/wouxun.py | 13 ++- chirp/wouxun_common.py | 9 +- chirp/yaesu_clone.py | 13 +-- chirpc | 312 +++++++++++++++++++++++++++++++++++++++++++++++++ chirpui/mainapp.py | 5 +- chirpui/reporting.py | 32 +++-- chirpw | 68 +++++------ 40 files changed, 732 insertions(+), 671 deletions(-) delete mode 100755 chirp.py create mode 100644 chirp/logger.py create mode 100644 chirp/version.py create mode 100755 chirpc
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Use argparse in chirpw (#2349)
This patch rewrites the argument processing in chirpw to use the standard Python argparse.
diff --git a/chirpw b/chirpw index 88b8e4b..a3a316c 100755 --- a/chirpw +++ b/chirpw @@ -28,6 +28,7 @@ import sys import os import locale import gettext +import argparse
p = platform.get_platform() if hasattr(sys, "frozen"): @@ -124,29 +125,21 @@ else: from chirp import * from chirpui import mainapp, config
-a = mainapp.ChirpMain() +parser = argparse.ArgumentParser() +parser.add_argument("files", metavar="file", nargs='*', help="File to open") +parser.add_argument("--profile", action="store_true", + help="Enable profiling") +args = parser.parse_args()
-profile = False -if len(sys.argv) > 1: - arg = sys.argv[1] - index = 2 - if arg == "--profile": - profile = True - elif arg == "--help": - print "Usage: %s [file...]" % sys.argv[0] - sys.exit(0) - else: - index = 1 -else: - index = 1 +a = mainapp.ChirpMain()
-for i in sys.argv[index:]: +for i in args.files: print "Opening %s" % i a.do_open(i)
a.show()
-if profile: +if args.profile: import cProfile, pstats cProfile.run("gtk.main()", "chirpw.stats") p = pstats.Stats("chirpw.stats")
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Rename chirp.py as chirpc (#2343)
The chirp CLI needs a better name if it ever will be installed in PATH. It is better to do that early on rather than later.
diff --git a/chirp.py b/chirp.py deleted file mode 100755 index 9e5c59c..0000000 --- a/chirp.py +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008 Dan Smith dsmith@danplanet.com -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# 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 serial -import sys -from optparse import OptionParser -import optparse - -from chirp import * -from chirp import chirp_common, errors, idrp, directory, util - -def fail_unsupported(): - print "Operation not supported by selected radio" - sys.exit(1) - -def fail_missing_mmap(): - print "mmap-only operation requires specification of an mmap file" - sys.exit(1) - -RADIOS = directory.DRV_TO_RADIO - -def store_tone(option, opt, value, parser): - if value in chirp_common.TONES: - setattr(parser.values, option.dest, value) - else: - raise optparse.OptionValueError("Invalid tone value: %.1f" % value) - -def store_dtcs(option, opt, value, parser): - try: - value = int(value, 10) - except ValueError: - raise optparse.OptionValueError("Invalid DTCS value: %s" % value) - - if value in chirp_common.DTCS_CODES: - setattr(parser.values, option.dest, value) - else: - raise optparse.OptionValueError("Invalid DTCS value: %03i" % value) - -def store_dtcspol(option, opt, value, parser): - if value not in ["NN", "RN", "NR", "RR"]: - raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value) - - setattr(parser.values, option.dest, value) -if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-s", "--serial", dest="serial", - default="mmap", - help="Serial port (default: mmap)") - - parser.add_option("-i", "--id", dest="id", - default=False, - action="store_true", - help="Request radio ID string") - parser.add_option("", "--raw", dest="raw", - default=False, - action="store_true", - help="Dump raw memory location") - - parser.add_option("", "--get-mem", dest="get_mem", - default=False, - action="store_true", - help="Get and print memory location") - parser.add_option("", "--set-mem-name", dest="set_mem_name", - default=None, - help="Set memory name") - parser.add_option("", "--set-mem-freq", dest="set_mem_freq", - type="float", - default=None, - help="Set memory frequency") - - parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon", - default=False, - action="store_true", - help="Set tone encode enabled flag") - parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff", - default=False, - action="store_true", - help="Set tone decode disabled flag") - parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon", - default=False, - action="store_true", - help="Set tone squelch enabled flag") - parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff", - default=False, - action="store_true", - help="Set tone squelch disabled flag") - parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson", - default=False, - action="store_true", - help="Set DTCS enabled flag") - parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff", - default=False, - action="store_true", - help="Set DTCS disabled flag") - - parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc", - type="float", - action="callback", callback=store_tone, nargs=1, - help="Set memory encode tone") - parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql", - type="float", - action="callback", callback=store_tone, nargs=1, - help="Set memory squelch tone") - parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs", - type="string", - action="callback", callback=store_dtcs, nargs=1, - help="Set memory DTCS code") - - parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol", - type="string", - action="callback", callback=store_dtcspol, nargs=1, - help="Set memory DTCS polarity (NN, NR, RN, RR)") - - parser.add_option("", "--set-mem-dup", dest="set_mem_dup", - help="Set memory duplex (+,-, or blank)") - parser.add_option("", "--set-mem-offset", dest="set_mem_offset", - type="float", - help="Set memory duplex offset (in MHz)") - - parser.add_option("", "--set-mem-mode", dest="set_mem_mode", - default=None, - help="Set mode (%s)" % ",".join(chirp_common.MODES)) - parser.add_option("-r", "--radio", dest="radio", - default=None, - help="Radio model (one of %s)" % ",".join(RADIOS.keys())) - - parser.add_option("", "--mmap", dest="mmap", - default=None, - help="Radio memory map file location") - parser.add_option("", "--download-mmap", dest="download_mmap", - action="store_true", - default=False, - help="Download memory map from radio") - parser.add_option("", "--upload-mmap", dest="upload_mmap", - action="store_true", - default=False, - help="Upload memory map to radio") - if len(sys.argv) <= 1: - parser.print_help() - sys.exit(0) - (options, args) = parser.parse_args() - - if options.id: - from chirp import icf - - s = serial.Serial(port=options.serial, - baudrate=9600, - timeout=0.5) - - md = icf.get_model_data(s) - - print "Model:\n%s" % util.hexprint(md) - - sys.exit(0) - - if not options.radio: - if options.mmap: - rclass = directory.get_radio_by_image(options.mmap).__class__ - else: - print "Must specify a radio model" - sys.exit(1) - else: - rclass = directory.get_radio(options.radio) - - if options.serial == "mmap": - if options.mmap: - s = options.mmap - else: - s = options.radio + ".img" - else: - print "opening %s at %i" % (options.serial, rclass.BAUD_RATE) - s = serial.Serial(port=options.serial, - baudrate=rclass.BAUD_RATE, - timeout=0.5) - - radio = rclass(s) - - if options.raw: - data = radio.get_raw_memory(int(args[0])) - for i in data: - if ord(i) > 0x7F: - print "Memory location %i (%i):\n%s" % (int(args[0]), - len(data), - util.hexprint(data)) - sys.exit(0) - print data - sys.exit(0) - - if options.set_mem_dup is not None: - if options.set_mem_dup != "+" and \ - options.set_mem_dup != "-" and \ - options.set_mem_dup != "": - print "Invalid duplex value `%s'" % options.set_mem_dup - print "Valid values are: '+', '-', ''" - sys.exit(1) - else: - _dup = options.set_mem_dup - else: - _dup = None - - if options.set_mem_mode: - print "Set mode: %s" % options.set_mem_mode - if options.set_mem_mode not in chirp_common.MODES: - print "Invalid mode `%s'" - sys.exit(1) - else: - _mode = options.set_mem_mode - else: - _mode = None - - if options.set_mem_name or options.set_mem_freq or \ - options.set_mem_tencon or options.set_mem_tencoff or \ - options.set_mem_tsqlon or options.set_mem_tsqloff or \ - options.set_mem_dtcson or options.set_mem_dtcsoff or \ - options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\ - options.set_mem_dup is not None or \ - options.set_mem_mode or options.set_mem_dtcspol or\ - options.set_mem_offset: - try: - mem = radio.get_memory(int(args[0])) - except errors.InvalidMemoryLocation: - mem = chirp_common.Memory() - mem.number = int(args[0]) - - mem.name = options.set_mem_name or mem.name - mem.freq = options.set_mem_freq or mem.freq - mem.rtone = options.set_mem_tenc or mem.rtone - mem.ctone = options.set_mem_tsql or mem.ctone - mem.dtcs = options.set_mem_dtcs or mem.dtcs - mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity - if _dup is not None: - mem.duplex = _dup - mem.offset = options.set_mem_offset or mem.offset - mem.mode = _mode or mem.mode - - if options.set_mem_tencon: - mem.tencEnabled = True - elif options.set_mem_tencoff: - mem.tencEnabled = False - - if options.set_mem_tsqlon: - mem.tsqlEnabled = True - elif options.set_mem_tsqloff: - mem.tsqlEnabled = False - - if options.set_mem_dtcson: - mem.dtcsEnabled = True - elif options.set_mem_dtcsoff: - mem.dtcsEnabled = False - - radio.set_memory(mem) - - if options.get_mem: - try: - pos = int(args[0]) - except ValueError: - pos = args[0] - - try: - mem = radio.get_memory(pos) - except errors.InvalidMemoryLocation, e: - mem = chirp_common.Memory() - mem.number = pos - - print mem - - if options.download_mmap: - #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() - radio.sync_in() - radio.save_mmap(options.mmap) - - if options.upload_mmap: - #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() - radio.load_mmap(options.mmap) - if radio.sync_out(): - print "Clone successful" - else: - print "Clone failed" - - if options.mmap and isinstance(radio, chirp_common.CloneModeRadio): - radio.save_mmap(options.mmap) - diff --git a/chirpc b/chirpc new file mode 100755 index 0000000..9e5c59c --- /dev/null +++ b/chirpc @@ -0,0 +1,297 @@ +#!/usr/bin/env python +# +# Copyright 2008 Dan Smith dsmith@danplanet.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# 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 serial +import sys +from optparse import OptionParser +import optparse + +from chirp import * +from chirp import chirp_common, errors, idrp, directory, util + +def fail_unsupported(): + print "Operation not supported by selected radio" + sys.exit(1) + +def fail_missing_mmap(): + print "mmap-only operation requires specification of an mmap file" + sys.exit(1) + +RADIOS = directory.DRV_TO_RADIO + +def store_tone(option, opt, value, parser): + if value in chirp_common.TONES: + setattr(parser.values, option.dest, value) + else: + raise optparse.OptionValueError("Invalid tone value: %.1f" % value) + +def store_dtcs(option, opt, value, parser): + try: + value = int(value, 10) + except ValueError: + raise optparse.OptionValueError("Invalid DTCS value: %s" % value) + + if value in chirp_common.DTCS_CODES: + setattr(parser.values, option.dest, value) + else: + raise optparse.OptionValueError("Invalid DTCS value: %03i" % value) + +def store_dtcspol(option, opt, value, parser): + if value not in ["NN", "RN", "NR", "RR"]: + raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value) + + setattr(parser.values, option.dest, value) +if __name__ == "__main__": + parser = OptionParser() + parser.add_option("-s", "--serial", dest="serial", + default="mmap", + help="Serial port (default: mmap)") + + parser.add_option("-i", "--id", dest="id", + default=False, + action="store_true", + help="Request radio ID string") + parser.add_option("", "--raw", dest="raw", + default=False, + action="store_true", + help="Dump raw memory location") + + parser.add_option("", "--get-mem", dest="get_mem", + default=False, + action="store_true", + help="Get and print memory location") + parser.add_option("", "--set-mem-name", dest="set_mem_name", + default=None, + help="Set memory name") + parser.add_option("", "--set-mem-freq", dest="set_mem_freq", + type="float", + default=None, + help="Set memory frequency") + + parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon", + default=False, + action="store_true", + help="Set tone encode enabled flag") + parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff", + default=False, + action="store_true", + help="Set tone decode disabled flag") + parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon", + default=False, + action="store_true", + help="Set tone squelch enabled flag") + parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff", + default=False, + action="store_true", + help="Set tone squelch disabled flag") + parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson", + default=False, + action="store_true", + help="Set DTCS enabled flag") + parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff", + default=False, + action="store_true", + help="Set DTCS disabled flag") + + parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc", + type="float", + action="callback", callback=store_tone, nargs=1, + help="Set memory encode tone") + parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql", + type="float", + action="callback", callback=store_tone, nargs=1, + help="Set memory squelch tone") + parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs", + type="string", + action="callback", callback=store_dtcs, nargs=1, + help="Set memory DTCS code") + + parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol", + type="string", + action="callback", callback=store_dtcspol, nargs=1, + help="Set memory DTCS polarity (NN, NR, RN, RR)") + + parser.add_option("", "--set-mem-dup", dest="set_mem_dup", + help="Set memory duplex (+,-, or blank)") + parser.add_option("", "--set-mem-offset", dest="set_mem_offset", + type="float", + help="Set memory duplex offset (in MHz)") + + parser.add_option("", "--set-mem-mode", dest="set_mem_mode", + default=None, + help="Set mode (%s)" % ",".join(chirp_common.MODES)) + parser.add_option("-r", "--radio", dest="radio", + default=None, + help="Radio model (one of %s)" % ",".join(RADIOS.keys())) + + parser.add_option("", "--mmap", dest="mmap", + default=None, + help="Radio memory map file location") + parser.add_option("", "--download-mmap", dest="download_mmap", + action="store_true", + default=False, + help="Download memory map from radio") + parser.add_option("", "--upload-mmap", dest="upload_mmap", + action="store_true", + default=False, + help="Upload memory map to radio") + if len(sys.argv) <= 1: + parser.print_help() + sys.exit(0) + (options, args) = parser.parse_args() + + if options.id: + from chirp import icf + + s = serial.Serial(port=options.serial, + baudrate=9600, + timeout=0.5) + + md = icf.get_model_data(s) + + print "Model:\n%s" % util.hexprint(md) + + sys.exit(0) + + if not options.radio: + if options.mmap: + rclass = directory.get_radio_by_image(options.mmap).__class__ + else: + print "Must specify a radio model" + sys.exit(1) + else: + rclass = directory.get_radio(options.radio) + + if options.serial == "mmap": + if options.mmap: + s = options.mmap + else: + s = options.radio + ".img" + else: + print "opening %s at %i" % (options.serial, rclass.BAUD_RATE) + s = serial.Serial(port=options.serial, + baudrate=rclass.BAUD_RATE, + timeout=0.5) + + radio = rclass(s) + + if options.raw: + data = radio.get_raw_memory(int(args[0])) + for i in data: + if ord(i) > 0x7F: + print "Memory location %i (%i):\n%s" % (int(args[0]), + len(data), + util.hexprint(data)) + sys.exit(0) + print data + sys.exit(0) + + if options.set_mem_dup is not None: + if options.set_mem_dup != "+" and \ + options.set_mem_dup != "-" and \ + options.set_mem_dup != "": + print "Invalid duplex value `%s'" % options.set_mem_dup + print "Valid values are: '+', '-', ''" + sys.exit(1) + else: + _dup = options.set_mem_dup + else: + _dup = None + + if options.set_mem_mode: + print "Set mode: %s" % options.set_mem_mode + if options.set_mem_mode not in chirp_common.MODES: + print "Invalid mode `%s'" + sys.exit(1) + else: + _mode = options.set_mem_mode + else: + _mode = None + + if options.set_mem_name or options.set_mem_freq or \ + options.set_mem_tencon or options.set_mem_tencoff or \ + options.set_mem_tsqlon or options.set_mem_tsqloff or \ + options.set_mem_dtcson or options.set_mem_dtcsoff or \ + options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\ + options.set_mem_dup is not None or \ + options.set_mem_mode or options.set_mem_dtcspol or\ + options.set_mem_offset: + try: + mem = radio.get_memory(int(args[0])) + except errors.InvalidMemoryLocation: + mem = chirp_common.Memory() + mem.number = int(args[0]) + + mem.name = options.set_mem_name or mem.name + mem.freq = options.set_mem_freq or mem.freq + mem.rtone = options.set_mem_tenc or mem.rtone + mem.ctone = options.set_mem_tsql or mem.ctone + mem.dtcs = options.set_mem_dtcs or mem.dtcs + mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity + if _dup is not None: + mem.duplex = _dup + mem.offset = options.set_mem_offset or mem.offset + mem.mode = _mode or mem.mode + + if options.set_mem_tencon: + mem.tencEnabled = True + elif options.set_mem_tencoff: + mem.tencEnabled = False + + if options.set_mem_tsqlon: + mem.tsqlEnabled = True + elif options.set_mem_tsqloff: + mem.tsqlEnabled = False + + if options.set_mem_dtcson: + mem.dtcsEnabled = True + elif options.set_mem_dtcsoff: + mem.dtcsEnabled = False + + radio.set_memory(mem) + + if options.get_mem: + try: + pos = int(args[0]) + except ValueError: + pos = args[0] + + try: + mem = radio.get_memory(pos) + except errors.InvalidMemoryLocation, e: + mem = chirp_common.Memory() + mem.number = pos + + print mem + + if options.download_mmap: + #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() + radio.sync_in() + radio.save_mmap(options.mmap) + + if options.upload_mmap: + #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() + radio.load_mmap(options.mmap) + if radio.sync_out(): + print "Clone successful" + else: + print "Clone failed" + + if options.mmap and isinstance(radio, chirp_common.CloneModeRadio): + radio.save_mmap(options.mmap) +
Not really keen on this change; its not as intuitive to me as the original.
%> python chirp.py
Feels pretty good.
From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Date: Tue, 24 Feb 2015 23:26:46 -0800 Subject: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
# HG changeset patch # User Zach Welch
Rename chirp.py as chirpc (#2343)
The chirp CLI needs a better name if it ever will be installed in PATH. It is better to do that early on rather than later.
diff --git a/chirp.py b/chirp.py deleted file mode 100755 index 9e5c59c..0000000 --- a/chirp.py +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008 Dan Smith -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see .
-import serial -import sys -from optparse import OptionParser -import optparse
-from chirp import * -from chirp import chirp_common, errors, idrp, directory, util
-def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
-def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
-RADIOS = directory.DRV_TO_RADIO
-def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
-def store_dtcs(option, opt, value, parser):
- try:
- value = int(value, 10)
- except ValueError:
- raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
-def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
- raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
-if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
- default="mmap",
- help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
- default=False,
- action="store_true",
- help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
- default=False,
- action="store_true",
- help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
- default=False,
- action="store_true",
- help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
- default=None,
- help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
- type="float",
- default=None,
- help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
- default=False,
- action="store_true",
- help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
- default=False,
- action="store_true",
- help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
- default=False,
- action="store_true",
- help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
- default=False,
- action="store_true",
- help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
- default=False,
- action="store_true",
- help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
- default=False,
- action="store_true",
- help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
- type="string",
- action="callback", callback=store_dtcs, nargs=1,
- help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
- type="string",
- action="callback", callback=store_dtcspol, nargs=1,
- help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
- help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
- type="float",
- help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
- default=None,
- help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
- default=None,
- help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
- default=None,
- help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
- action="store_true",
- default=False,
- help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
- action="store_true",
- default=False,
- help="Upload memory map to radio")
- if len(sys.argv) <= 1:
- parser.print_help()
- sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
- from chirp import icf
- s = serial.Serial(port=options.serial,
- baudrate=9600,
- timeout=0.5)
- md = icf.get_model_data(s)
- print "Model:\n%s" % util.hexprint(md)
- sys.exit(0)
- if not options.radio:
- if options.mmap:
- rclass = directory.get_radio_by_image(options.mmap).__class__
- else:
- print "Must specify a radio model"
- sys.exit(1)
- else:
- rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
- if options.mmap:
- s = options.mmap
- else:
- s = options.radio + ".img"
- else:
- print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
- s = serial.Serial(port=options.serial,
- baudrate=rclass.BAUD_RATE,
- timeout=0.5)
- radio = rclass(s)
- if options.raw:
- data = radio.get_raw_memory(int(args[0]))
- for i in data:
- if ord(i)> 0x7F:
- print "Memory location %i (%i):\n%s" % (int(args[0]),
- len(data),
- util.hexprint(data))
- sys.exit(0)
- print data
- sys.exit(0)
- if options.set_mem_dup is not None:
- if options.set_mem_dup != "+" and \
- options.set_mem_dup != "-" and \
- options.set_mem_dup != "":
- print "Invalid duplex value `%s'" % options.set_mem_dup
- print "Valid values are: '+', '-', ''"
- sys.exit(1)
- else:
- _dup = options.set_mem_dup
- else:
- _dup = None
- if options.set_mem_mode:
- print "Set mode: %s" % options.set_mem_mode
- if options.set_mem_mode not in chirp_common.MODES:
- print "Invalid mode `%s'"
- sys.exit(1)
- else:
- _mode = options.set_mem_mode
- else:
- _mode = None
- if options.set_mem_name or options.set_mem_freq or \
- options.set_mem_tencon or options.set_mem_tencoff or \
- options.set_mem_tsqlon or options.set_mem_tsqloff or \
- options.set_mem_dtcson or options.set_mem_dtcsoff or \
- options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
- options.set_mem_dup is not None or \
- options.set_mem_mode or options.set_mem_dtcspol or\
- options.set_mem_offset:
- try:
- mem = radio.get_memory(int(args[0]))
- except errors.InvalidMemoryLocation:
- mem = chirp_common.Memory()
- mem.number = int(args[0])
- mem.name = options.set_mem_name or mem.name
- mem.freq = options.set_mem_freq or mem.freq
- mem.rtone = options.set_mem_tenc or mem.rtone
- mem.ctone = options.set_mem_tsql or mem.ctone
- mem.dtcs = options.set_mem_dtcs or mem.dtcs
- mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
- if _dup is not None:
- mem.duplex = _dup
- mem.offset = options.set_mem_offset or mem.offset
- mem.mode = _mode or mem.mode
- if options.set_mem_tencon:
- mem.tencEnabled = True
- elif options.set_mem_tencoff:
- mem.tencEnabled = False
- if options.set_mem_tsqlon:
- mem.tsqlEnabled = True
- elif options.set_mem_tsqloff:
- mem.tsqlEnabled = False
- if options.set_mem_dtcson:
- mem.dtcsEnabled = True
- elif options.set_mem_dtcsoff:
- mem.dtcsEnabled = False
- radio.set_memory(mem)
- if options.get_mem:
- try:
- pos = int(args[0])
- except ValueError:
- pos = args[0]
- try:
- mem = radio.get_memory(pos)
- except errors.InvalidMemoryLocation, e:
- mem = chirp_common.Memory()
- mem.number = pos
- print mem
- if options.download_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.sync_in()
- radio.save_mmap(options.mmap)
- if options.upload_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.load_mmap(options.mmap)
- if radio.sync_out():
- print "Clone successful"
- else:
- print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
- radio.save_mmap(options.mmap)
diff --git a/chirpc b/chirpc new file mode 100755 index 0000000..9e5c59c --- /dev/null +++ b/chirpc @@ -0,0 +1,297 @@ +#!/usr/bin/env python +# +# Copyright 2008 Dan Smith +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see .
+import serial +import sys +from optparse import OptionParser +import optparse
+from chirp import * +from chirp import chirp_common, errors, idrp, directory, util
+def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
+def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
+RADIOS = directory.DRV_TO_RADIO
+def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
+def store_dtcs(option, opt, value, parser):
- try:
- value = int(value, 10)
- except ValueError:
- raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
+def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
- raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
+if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
- default="mmap",
- help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
- default=False,
- action="store_true",
- help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
- default=False,
- action="store_true",
- help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
- default=False,
- action="store_true",
- help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
- default=None,
- help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
- type="float",
- default=None,
- help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
- default=False,
- action="store_true",
- help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
- default=False,
- action="store_true",
- help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
- default=False,
- action="store_true",
- help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
- default=False,
- action="store_true",
- help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
- default=False,
- action="store_true",
- help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
- default=False,
- action="store_true",
- help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
- type="string",
- action="callback", callback=store_dtcs, nargs=1,
- help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
- type="string",
- action="callback", callback=store_dtcspol, nargs=1,
- help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
- help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
- type="float",
- help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
- default=None,
- help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
- default=None,
- help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
- default=None,
- help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
- action="store_true",
- default=False,
- help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
- action="store_true",
- default=False,
- help="Upload memory map to radio")
- if len(sys.argv) <= 1:
- parser.print_help()
- sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
- from chirp import icf
- s = serial.Serial(port=options.serial,
- baudrate=9600,
- timeout=0.5)
- md = icf.get_model_data(s)
- print "Model:\n%s" % util.hexprint(md)
- sys.exit(0)
- if not options.radio:
- if options.mmap:
- rclass = directory.get_radio_by_image(options.mmap).__class__
- else:
- print "Must specify a radio model"
- sys.exit(1)
- else:
- rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
- if options.mmap:
- s = options.mmap
- else:
- s = options.radio + ".img"
- else:
- print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
- s = serial.Serial(port=options.serial,
- baudrate=rclass.BAUD_RATE,
- timeout=0.5)
- radio = rclass(s)
- if options.raw:
- data = radio.get_raw_memory(int(args[0]))
- for i in data:
- if ord(i)> 0x7F:
- print "Memory location %i (%i):\n%s" % (int(args[0]),
- len(data),
- util.hexprint(data))
- sys.exit(0)
- print data
- sys.exit(0)
- if options.set_mem_dup is not None:
- if options.set_mem_dup != "+" and \
- options.set_mem_dup != "-" and \
- options.set_mem_dup != "":
- print "Invalid duplex value `%s'" % options.set_mem_dup
- print "Valid values are: '+', '-', ''"
- sys.exit(1)
- else:
- _dup = options.set_mem_dup
- else:
- _dup = None
- if options.set_mem_mode:
- print "Set mode: %s" % options.set_mem_mode
- if options.set_mem_mode not in chirp_common.MODES:
- print "Invalid mode `%s'"
- sys.exit(1)
- else:
- _mode = options.set_mem_mode
- else:
- _mode = None
- if options.set_mem_name or options.set_mem_freq or \
- options.set_mem_tencon or options.set_mem_tencoff or \
- options.set_mem_tsqlon or options.set_mem_tsqloff or \
- options.set_mem_dtcson or options.set_mem_dtcsoff or \
- options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
- options.set_mem_dup is not None or \
- options.set_mem_mode or options.set_mem_dtcspol or\
- options.set_mem_offset:
- try:
- mem = radio.get_memory(int(args[0]))
- except errors.InvalidMemoryLocation:
- mem = chirp_common.Memory()
- mem.number = int(args[0])
- mem.name = options.set_mem_name or mem.name
- mem.freq = options.set_mem_freq or mem.freq
- mem.rtone = options.set_mem_tenc or mem.rtone
- mem.ctone = options.set_mem_tsql or mem.ctone
- mem.dtcs = options.set_mem_dtcs or mem.dtcs
- mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
- if _dup is not None:
- mem.duplex = _dup
- mem.offset = options.set_mem_offset or mem.offset
- mem.mode = _mode or mem.mode
- if options.set_mem_tencon:
- mem.tencEnabled = True
- elif options.set_mem_tencoff:
- mem.tencEnabled = False
- if options.set_mem_tsqlon:
- mem.tsqlEnabled = True
- elif options.set_mem_tsqloff:
- mem.tsqlEnabled = False
- if options.set_mem_dtcson:
- mem.dtcsEnabled = True
- elif options.set_mem_dtcsoff:
- mem.dtcsEnabled = False
- radio.set_memory(mem)
- if options.get_mem:
- try:
- pos = int(args[0])
- except ValueError:
- pos = args[0]
- try:
- mem = radio.get_memory(pos)
- except errors.InvalidMemoryLocation, e:
- mem = chirp_common.Memory()
- mem.number = pos
- print mem
- if options.download_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.sync_in()
- radio.save_mmap(options.mmap)
- if options.upload_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.load_mmap(options.mmap)
- if radio.sync_out():
- print "Clone successful"
- else:
- print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
- radio.save_mmap(options.mmap)
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 12:29 AM, Kosta Arvanitis wrote:
Not really keen on this change; its not as intuitive to me as the original. %> python chirp.py Feels pretty good.
My intention is to clean up the CLI tool such that it can be installed alongside chirpw (e.g. in /usr/bin). At that point, you would simply run 'chirpc', and that sounds a lot more polished than 'chirp.py'.
Is 'chirpc' a compiler?
----------------------------------------
Date: Wed, 25 Feb 2015 00:34:21 -0800 From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
On 02/25/2015 12:29 AM, Kosta Arvanitis wrote:
Not really keen on this change; its not as intuitive to me as the original. %> python chirp.py Feels pretty good.
My intention is to clean up the CLI tool such that it can be installed alongside chirpw (e.g. in /usr/bin). At that point, you would simply run 'chirpc', and that sounds a lot more polished than 'chirp.py'.
-- Zach Welch Mandolin Creek Farm www.mandolincreekfarm.com farm: 541-453-4131 cell: 541-740-3410 _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
what about a symlink for chirpc -> chirp.py ? From: Kosta Arvanitis kosta@alumni.uvic.ca To: "chirp_devel@intrepid.danplanet.com" chirp_devel@intrepid.danplanet.com Sent: Wednesday, February 25, 2015 2:53 AM Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
Is 'chirpc' a compiler?
----------------------------------------
Date: Wed, 25 Feb 2015 00:34:21 -0800 From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
On 02/25/2015 12:29 AM, Kosta Arvanitis wrote:
Not really keen on this change; its not as intuitive to me as the original. %> python chirp.py Feels pretty good.
My intention is to clean up the CLI tool such that it can be installed alongside chirpw (e.g. in /usr/bin). At that point, you would simply run 'chirpc', and that sounds a lot more polished than 'chirp.py'.
-- Zach Welch Mandolin Creek Farm www.mandolincreekfarm.com farm: 541-453-4131 cell: 541-740-3410 _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
_______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
Kosta, just FYI, your emails continue to look very rough on this end:
Not really keen on this change; its not as intuitive to me as the original.
It's really not reasonable to install something ending in .py into $PATH, IMHO. Further, renaming on install doesn't seem like the right thing to do either (and it'd be very unconventional).
Right now, chirpw becomes the installed binary for the windowed version. We can't really use "chirp" unless we put it in a different directory, as it conflicts with the package name. IMHO, chirpc is a reasonable alternative. I don't think it's likely to be confused as a compiler to anyone other than java folk. The other option in my mind would be "chirpcli", but then it would be different from "chirpw" and I'm really not in favor of renaming that to "chirpwindowed" :)
--Dan
Sorry (again) about the emails, its my lot in life to suffer from this I suppose. I probably should switch to using Thunderbird, but that's on me.
I noticed that the history in the online repository has now been lost on this chirpc.py; this may be a bigger issue if further renames (radios) occurs as I find the online repository helpful at times.
As it was pointed out utilizing hg log --follow; does display the entire history but it appears that redmine is not accounting for this flag.
---------------------------------------- Date: Wed, 25 Feb 2015 08:23:13 -0800 From: dsmith@danplanet.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
Kosta, just FYI, your emails continue to look very rough on this end:
Not really keen on this change; its not as intuitive to me as the original.
It's really not reasonable to install something ending in .py into $PATH, IMHO. Further, renaming on install doesn't seem like the right thing to do either (and it'd be very unconventional).
Right now, chirpw becomes the installed binary for the windowed version. We can't really use "chirp" unless we put it in a different directory, as it conflicts with the package name. IMHO, chirpc is a reasonable alternative. I don't think it's likely to be confused as a compiler to anyone other than java folk. The other option in my mind would be "chirpcli", but then it would be different from "chirpw" and I'm really not in favor of renaming that to "chirpwindowed" :)
--Dan
_______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
Sorry but ... this doesn't look as a rename to me, I think we can loose connection to old history of file
73 de IZ3GME Marco
On 25/02/2015 08:26, Zach Welch wrote:
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Rename chirp.py as chirpc (#2343)
The chirp CLI needs a better name if it ever will be installed in PATH. It is better to do that early on rather than later.
diff --git a/chirp.py b/chirp.py deleted file mode 100755 index 9e5c59c..0000000 --- a/chirp.py +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008 Dan Smith dsmith@danplanet.com -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# 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 serial -import sys -from optparse import OptionParser -import optparse
-from chirp import * -from chirp import chirp_common, errors, idrp, directory, util
-def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
-def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
-RADIOS = directory.DRV_TO_RADIO
-def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
setattr(parser.values, option.dest, value)
- else:
raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
-def store_dtcs(option, opt, value, parser):
- try:
value = int(value, 10)
- except ValueError:
raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
setattr(parser.values, option.dest, value)
- else:
raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
-def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
-if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
default="mmap",
help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
default=False,
action="store_true",
help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
default=False,
action="store_true",
help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
default=False,
action="store_true",
help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
default=None,
help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
type="float",
default=None,
help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
default=False,
action="store_true",
help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
default=False,
action="store_true",
help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
default=False,
action="store_true",
help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
default=False,
action="store_true",
help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
default=False,
action="store_true",
help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
default=False,
action="store_true",
help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
type="float",
action="callback", callback=store_tone, nargs=1,
help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
type="float",
action="callback", callback=store_tone, nargs=1,
help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
type="string",
action="callback", callback=store_dtcs, nargs=1,
help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
type="string",
action="callback", callback=store_dtcspol, nargs=1,
help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
type="float",
help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
default=None,
help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
default=None,
help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
default=None,
help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
action="store_true",
default=False,
help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
action="store_true",
default=False,
help="Upload memory map to radio")
- if len(sys.argv) <= 1:
parser.print_help()
sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
from chirp import icf
s = serial.Serial(port=options.serial,
baudrate=9600,
timeout=0.5)
md = icf.get_model_data(s)
print "Model:\n%s" % util.hexprint(md)
sys.exit(0)
- if not options.radio:
if options.mmap:
rclass = directory.get_radio_by_image(options.mmap).__class__
else:
print "Must specify a radio model"
sys.exit(1)
- else:
rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
if options.mmap:
s = options.mmap
else:
s = options.radio + ".img"
- else:
print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
s = serial.Serial(port=options.serial,
baudrate=rclass.BAUD_RATE,
timeout=0.5)
- radio = rclass(s)
- if options.raw:
data = radio.get_raw_memory(int(args[0]))
for i in data:
if ord(i) > 0x7F:
print "Memory location %i (%i):\n%s" % (int(args[0]),
len(data),
util.hexprint(data))
sys.exit(0)
print data
sys.exit(0)
- if options.set_mem_dup is not None:
if options.set_mem_dup != "+" and \
options.set_mem_dup != "-" and \
options.set_mem_dup != "":
print "Invalid duplex value `%s'" % options.set_mem_dup
print "Valid values are: '+', '-', ''"
sys.exit(1)
else:
_dup = options.set_mem_dup
- else:
_dup = None
- if options.set_mem_mode:
print "Set mode: %s" % options.set_mem_mode
if options.set_mem_mode not in chirp_common.MODES:
print "Invalid mode `%s'"
sys.exit(1)
else:
_mode = options.set_mem_mode
- else:
_mode = None
- if options.set_mem_name or options.set_mem_freq or \
options.set_mem_tencon or options.set_mem_tencoff or \
options.set_mem_tsqlon or options.set_mem_tsqloff or \
options.set_mem_dtcson or options.set_mem_dtcsoff or \
options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
options.set_mem_dup is not None or \
options.set_mem_mode or options.set_mem_dtcspol or\
options.set_mem_offset:
try:
mem = radio.get_memory(int(args[0]))
except errors.InvalidMemoryLocation:
mem = chirp_common.Memory()
mem.number = int(args[0])
mem.name = options.set_mem_name or mem.name
mem.freq = options.set_mem_freq or mem.freq
mem.rtone = options.set_mem_tenc or mem.rtone
mem.ctone = options.set_mem_tsql or mem.ctone
mem.dtcs = options.set_mem_dtcs or mem.dtcs
mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
if _dup is not None:
mem.duplex = _dup
mem.offset = options.set_mem_offset or mem.offset
mem.mode = _mode or mem.mode
if options.set_mem_tencon:
mem.tencEnabled = True
elif options.set_mem_tencoff:
mem.tencEnabled = False
if options.set_mem_tsqlon:
mem.tsqlEnabled = True
elif options.set_mem_tsqloff:
mem.tsqlEnabled = False
if options.set_mem_dtcson:
mem.dtcsEnabled = True
elif options.set_mem_dtcsoff:
mem.dtcsEnabled = False
radio.set_memory(mem)
- if options.get_mem:
try:
pos = int(args[0])
except ValueError:
pos = args[0]
try:
mem = radio.get_memory(pos)
except errors.InvalidMemoryLocation, e:
mem = chirp_common.Memory()
mem.number = pos
print mem
- if options.download_mmap:
#isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
radio.sync_in()
radio.save_mmap(options.mmap)
- if options.upload_mmap:
#isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
radio.load_mmap(options.mmap)
if radio.sync_out():
print "Clone successful"
else:
print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
radio.save_mmap(options.mmap)
diff --git a/chirpc b/chirpc new file mode 100755 index 0000000..9e5c59c --- /dev/null +++ b/chirpc @@ -0,0 +1,297 @@ +#!/usr/bin/env python +# +# Copyright 2008 Dan Smith dsmith@danplanet.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# 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 serial +import sys +from optparse import OptionParser +import optparse
+from chirp import * +from chirp import chirp_common, errors, idrp, directory, util
+def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
+def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
+RADIOS = directory.DRV_TO_RADIO
+def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
setattr(parser.values, option.dest, value)
- else:
raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
+def store_dtcs(option, opt, value, parser):
- try:
value = int(value, 10)
- except ValueError:
raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
setattr(parser.values, option.dest, value)
- else:
raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
+def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
+if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
default="mmap",
help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
default=False,
action="store_true",
help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
default=False,
action="store_true",
help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
default=False,
action="store_true",
help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
default=None,
help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
type="float",
default=None,
help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
default=False,
action="store_true",
help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
default=False,
action="store_true",
help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
default=False,
action="store_true",
help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
default=False,
action="store_true",
help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
default=False,
action="store_true",
help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
default=False,
action="store_true",
help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
type="float",
action="callback", callback=store_tone, nargs=1,
help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
type="float",
action="callback", callback=store_tone, nargs=1,
help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
type="string",
action="callback", callback=store_dtcs, nargs=1,
help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
type="string",
action="callback", callback=store_dtcspol, nargs=1,
help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
type="float",
help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
default=None,
help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
default=None,
help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
default=None,
help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
action="store_true",
default=False,
help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
action="store_true",
default=False,
help="Upload memory map to radio")
- if len(sys.argv) <= 1:
parser.print_help()
sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
from chirp import icf
s = serial.Serial(port=options.serial,
baudrate=9600,
timeout=0.5)
md = icf.get_model_data(s)
print "Model:\n%s" % util.hexprint(md)
sys.exit(0)
- if not options.radio:
if options.mmap:
rclass = directory.get_radio_by_image(options.mmap).__class__
else:
print "Must specify a radio model"
sys.exit(1)
- else:
rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
if options.mmap:
s = options.mmap
else:
s = options.radio + ".img"
- else:
print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
s = serial.Serial(port=options.serial,
baudrate=rclass.BAUD_RATE,
timeout=0.5)
- radio = rclass(s)
- if options.raw:
data = radio.get_raw_memory(int(args[0]))
for i in data:
if ord(i) > 0x7F:
print "Memory location %i (%i):\n%s" % (int(args[0]),
len(data),
util.hexprint(data))
sys.exit(0)
print data
sys.exit(0)
- if options.set_mem_dup is not None:
if options.set_mem_dup != "+" and \
options.set_mem_dup != "-" and \
options.set_mem_dup != "":
print "Invalid duplex value `%s'" % options.set_mem_dup
print "Valid values are: '+', '-', ''"
sys.exit(1)
else:
_dup = options.set_mem_dup
- else:
_dup = None
- if options.set_mem_mode:
print "Set mode: %s" % options.set_mem_mode
if options.set_mem_mode not in chirp_common.MODES:
print "Invalid mode `%s'"
sys.exit(1)
else:
_mode = options.set_mem_mode
- else:
_mode = None
- if options.set_mem_name or options.set_mem_freq or \
options.set_mem_tencon or options.set_mem_tencoff or \
options.set_mem_tsqlon or options.set_mem_tsqloff or \
options.set_mem_dtcson or options.set_mem_dtcsoff or \
options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
options.set_mem_dup is not None or \
options.set_mem_mode or options.set_mem_dtcspol or\
options.set_mem_offset:
try:
mem = radio.get_memory(int(args[0]))
except errors.InvalidMemoryLocation:
mem = chirp_common.Memory()
mem.number = int(args[0])
mem.name = options.set_mem_name or mem.name
mem.freq = options.set_mem_freq or mem.freq
mem.rtone = options.set_mem_tenc or mem.rtone
mem.ctone = options.set_mem_tsql or mem.ctone
mem.dtcs = options.set_mem_dtcs or mem.dtcs
mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
if _dup is not None:
mem.duplex = _dup
mem.offset = options.set_mem_offset or mem.offset
mem.mode = _mode or mem.mode
if options.set_mem_tencon:
mem.tencEnabled = True
elif options.set_mem_tencoff:
mem.tencEnabled = False
if options.set_mem_tsqlon:
mem.tsqlEnabled = True
elif options.set_mem_tsqloff:
mem.tsqlEnabled = False
if options.set_mem_dtcson:
mem.dtcsEnabled = True
elif options.set_mem_dtcsoff:
mem.dtcsEnabled = False
radio.set_memory(mem)
- if options.get_mem:
try:
pos = int(args[0])
except ValueError:
pos = args[0]
try:
mem = radio.get_memory(pos)
except errors.InvalidMemoryLocation, e:
mem = chirp_common.Memory()
mem.number = pos
print mem
- if options.download_mmap:
#isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
radio.sync_in()
radio.save_mmap(options.mmap)
- if options.upload_mmap:
#isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
radio.load_mmap(options.mmap)
if radio.sync_out():
print "Clone successful"
else:
print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
radio.save_mmap(options.mmap)
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 12:34 AM, Marco Filippi IZ3GME wrote:
Sorry but ... this doesn't look as a rename to me, I think we can loose connection to old history of file
D'oh. I should have check that more carefully. Git is smart enough to recognize that it is a rename. As mercurial uses git for its storage engine, I presume that it has such smarts too. If I had thought to use 'format-patch -C', the patch would have looked smarter. Mea culpa.
FYI my mercurial generate it as
diff --git a/chirp.py b/chirpc rename from chirp.py rename to chirpc
Hope this can help
73 de IZ3GME Marco
On 25/02/2015 09:44, Zach Welch wrote:
On 02/25/2015 12:34 AM, Marco Filippi IZ3GME wrote:
Sorry but ... this doesn't look as a rename to me, I think we can loose connection to old history of file
D'oh. I should have check that more carefully. Git is smart enough to recognize that it is a rename. As mercurial uses git for its storage engine, I presume that it has such smarts too. If I had thought to use 'format-patch -C', the patch would have looked smarter. Mea culpa.
Is it possible to rename a file in HG and have it keep the history?
If your keen on creating a tool for install purposes, look at the setup script. You may be able to achieve this by creating a named setup distro without requiring a rename of the source file. I haven't tried this myself but should be possible.
-kosta
----------------------------------------
Date: Wed, 25 Feb 2015 09:34:07 +0100 From: iz3gme.marco@gmail.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
Sorry but ... this doesn't look as a rename to me, I think we can loose connection to old history of file
73 de IZ3GME Marco
On 25/02/2015 08:26, Zach Welch wrote:
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Rename chirp.py as chirpc (#2343)
The chirp CLI needs a better name if it ever will be installed in PATH. It is better to do that early on rather than later.
diff --git a/chirp.py b/chirp.py deleted file mode 100755 index 9e5c59c..0000000 --- a/chirp.py +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008 Dan Smith dsmith@danplanet.com -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# 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 serial -import sys -from optparse import OptionParser -import optparse
-from chirp import * -from chirp import chirp_common, errors, idrp, directory, util
-def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
-def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
-RADIOS = directory.DRV_TO_RADIO
-def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
-def store_dtcs(option, opt, value, parser):
- try:
- value = int(value, 10)
- except ValueError:
- raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
-def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
- raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
-if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
- default="mmap",
- help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
- default=False,
- action="store_true",
- help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
- default=False,
- action="store_true",
- help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
- default=False,
- action="store_true",
- help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
- default=None,
- help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
- type="float",
- default=None,
- help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
- default=False,
- action="store_true",
- help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
- default=False,
- action="store_true",
- help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
- default=False,
- action="store_true",
- help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
- default=False,
- action="store_true",
- help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
- default=False,
- action="store_true",
- help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
- default=False,
- action="store_true",
- help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
- type="string",
- action="callback", callback=store_dtcs, nargs=1,
- help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
- type="string",
- action="callback", callback=store_dtcspol, nargs=1,
- help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
- help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
- type="float",
- help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
- default=None,
- help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
- default=None,
- help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
- default=None,
- help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
- action="store_true",
- default=False,
- help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
- action="store_true",
- default=False,
- help="Upload memory map to radio")
- if len(sys.argv) <= 1:
- parser.print_help()
- sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
- from chirp import icf
- s = serial.Serial(port=options.serial,
- baudrate=9600,
- timeout=0.5)
- md = icf.get_model_data(s)
- print "Model:\n%s" % util.hexprint(md)
- sys.exit(0)
- if not options.radio:
- if options.mmap:
- rclass = directory.get_radio_by_image(options.mmap).__class__
- else:
- print "Must specify a radio model"
- sys.exit(1)
- else:
- rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
- if options.mmap:
- s = options.mmap
- else:
- s = options.radio + ".img"
- else:
- print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
- s = serial.Serial(port=options.serial,
- baudrate=rclass.BAUD_RATE,
- timeout=0.5)
- radio = rclass(s)
- if options.raw:
- data = radio.get_raw_memory(int(args[0]))
- for i in data:
- if ord(i)> 0x7F:
- print "Memory location %i (%i):\n%s" % (int(args[0]),
- len(data),
- util.hexprint(data))
- sys.exit(0)
- print data
- sys.exit(0)
- if options.set_mem_dup is not None:
- if options.set_mem_dup != "+" and \
- options.set_mem_dup != "-" and \
- options.set_mem_dup != "":
- print "Invalid duplex value `%s'" % options.set_mem_dup
- print "Valid values are: '+', '-', ''"
- sys.exit(1)
- else:
- _dup = options.set_mem_dup
- else:
- _dup = None
- if options.set_mem_mode:
- print "Set mode: %s" % options.set_mem_mode
- if options.set_mem_mode not in chirp_common.MODES:
- print "Invalid mode `%s'"
- sys.exit(1)
- else:
- _mode = options.set_mem_mode
- else:
- _mode = None
- if options.set_mem_name or options.set_mem_freq or \
- options.set_mem_tencon or options.set_mem_tencoff or \
- options.set_mem_tsqlon or options.set_mem_tsqloff or \
- options.set_mem_dtcson or options.set_mem_dtcsoff or \
- options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
- options.set_mem_dup is not None or \
- options.set_mem_mode or options.set_mem_dtcspol or\
- options.set_mem_offset:
- try:
- mem = radio.get_memory(int(args[0]))
- except errors.InvalidMemoryLocation:
- mem = chirp_common.Memory()
- mem.number = int(args[0])
- mem.name = options.set_mem_name or mem.name
- mem.freq = options.set_mem_freq or mem.freq
- mem.rtone = options.set_mem_tenc or mem.rtone
- mem.ctone = options.set_mem_tsql or mem.ctone
- mem.dtcs = options.set_mem_dtcs or mem.dtcs
- mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
- if _dup is not None:
- mem.duplex = _dup
- mem.offset = options.set_mem_offset or mem.offset
- mem.mode = _mode or mem.mode
- if options.set_mem_tencon:
- mem.tencEnabled = True
- elif options.set_mem_tencoff:
- mem.tencEnabled = False
- if options.set_mem_tsqlon:
- mem.tsqlEnabled = True
- elif options.set_mem_tsqloff:
- mem.tsqlEnabled = False
- if options.set_mem_dtcson:
- mem.dtcsEnabled = True
- elif options.set_mem_dtcsoff:
- mem.dtcsEnabled = False
- radio.set_memory(mem)
- if options.get_mem:
- try:
- pos = int(args[0])
- except ValueError:
- pos = args[0]
- try:
- mem = radio.get_memory(pos)
- except errors.InvalidMemoryLocation, e:
- mem = chirp_common.Memory()
- mem.number = pos
- print mem
- if options.download_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.sync_in()
- radio.save_mmap(options.mmap)
- if options.upload_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.load_mmap(options.mmap)
- if radio.sync_out():
- print "Clone successful"
- else:
- print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
- radio.save_mmap(options.mmap)
diff --git a/chirpc b/chirpc new file mode 100755 index 0000000..9e5c59c --- /dev/null +++ b/chirpc @@ -0,0 +1,297 @@ +#!/usr/bin/env python +# +# Copyright 2008 Dan Smith dsmith@danplanet.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# 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 serial +import sys +from optparse import OptionParser +import optparse
+from chirp import * +from chirp import chirp_common, errors, idrp, directory, util
+def fail_unsupported():
- print "Operation not supported by selected radio"
- sys.exit(1)
+def fail_missing_mmap():
- print "mmap-only operation requires specification of an mmap file"
- sys.exit(1)
+RADIOS = directory.DRV_TO_RADIO
+def store_tone(option, opt, value, parser):
- if value in chirp_common.TONES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
+def store_dtcs(option, opt, value, parser):
- try:
- value = int(value, 10)
- except ValueError:
- raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES:
- setattr(parser.values, option.dest, value)
- else:
- raise optparse.OptionValueError("Invalid DTCS value: %03i" % value)
+def store_dtcspol(option, opt, value, parser):
- if value not in ["NN", "RN", "NR", "RR"]:
- raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value)
- setattr(parser.values, option.dest, value)
+if __name__ == "__main__":
- parser = OptionParser()
- parser.add_option("-s", "--serial", dest="serial",
- default="mmap",
- help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id",
- default=False,
- action="store_true",
- help="Request radio ID string")
- parser.add_option("", "--raw", dest="raw",
- default=False,
- action="store_true",
- help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem",
- default=False,
- action="store_true",
- help="Get and print memory location")
- parser.add_option("", "--set-mem-name", dest="set_mem_name",
- default=None,
- help="Set memory name")
- parser.add_option("", "--set-mem-freq", dest="set_mem_freq",
- type="float",
- default=None,
- help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon",
- default=False,
- action="store_true",
- help="Set tone encode enabled flag")
- parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff",
- default=False,
- action="store_true",
- help="Set tone decode disabled flag")
- parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon",
- default=False,
- action="store_true",
- help="Set tone squelch enabled flag")
- parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff",
- default=False,
- action="store_true",
- help="Set tone squelch disabled flag")
- parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson",
- default=False,
- action="store_true",
- help="Set DTCS enabled flag")
- parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff",
- default=False,
- action="store_true",
- help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory encode tone")
- parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql",
- type="float",
- action="callback", callback=store_tone, nargs=1,
- help="Set memory squelch tone")
- parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs",
- type="string",
- action="callback", callback=store_dtcs, nargs=1,
- help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol",
- type="string",
- action="callback", callback=store_dtcspol, nargs=1,
- help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup",
- help="Set memory duplex (+,-, or blank)")
- parser.add_option("", "--set-mem-offset", dest="set_mem_offset",
- type="float",
- help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode",
- default=None,
- help="Set mode (%s)" % ",".join(chirp_common.MODES))
- parser.add_option("-r", "--radio", dest="radio",
- default=None,
- help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap",
- default=None,
- help="Radio memory map file location")
- parser.add_option("", "--download-mmap", dest="download_mmap",
- action="store_true",
- default=False,
- help="Download memory map from radio")
- parser.add_option("", "--upload-mmap", dest="upload_mmap",
- action="store_true",
- default=False,
- help="Upload memory map to radio")
- if len(sys.argv) <= 1:
- parser.print_help()
- sys.exit(0)
- (options, args) = parser.parse_args()
- if options.id:
- from chirp import icf
- s = serial.Serial(port=options.serial,
- baudrate=9600,
- timeout=0.5)
- md = icf.get_model_data(s)
- print "Model:\n%s" % util.hexprint(md)
- sys.exit(0)
- if not options.radio:
- if options.mmap:
- rclass = directory.get_radio_by_image(options.mmap).__class__
- else:
- print "Must specify a radio model"
- sys.exit(1)
- else:
- rclass = directory.get_radio(options.radio)
- if options.serial == "mmap":
- if options.mmap:
- s = options.mmap
- else:
- s = options.radio + ".img"
- else:
- print "opening %s at %i" % (options.serial, rclass.BAUD_RATE)
- s = serial.Serial(port=options.serial,
- baudrate=rclass.BAUD_RATE,
- timeout=0.5)
- radio = rclass(s)
- if options.raw:
- data = radio.get_raw_memory(int(args[0]))
- for i in data:
- if ord(i)> 0x7F:
- print "Memory location %i (%i):\n%s" % (int(args[0]),
- len(data),
- util.hexprint(data))
- sys.exit(0)
- print data
- sys.exit(0)
- if options.set_mem_dup is not None:
- if options.set_mem_dup != "+" and \
- options.set_mem_dup != "-" and \
- options.set_mem_dup != "":
- print "Invalid duplex value `%s'" % options.set_mem_dup
- print "Valid values are: '+', '-', ''"
- sys.exit(1)
- else:
- _dup = options.set_mem_dup
- else:
- _dup = None
- if options.set_mem_mode:
- print "Set mode: %s" % options.set_mem_mode
- if options.set_mem_mode not in chirp_common.MODES:
- print "Invalid mode `%s'"
- sys.exit(1)
- else:
- _mode = options.set_mem_mode
- else:
- _mode = None
- if options.set_mem_name or options.set_mem_freq or \
- options.set_mem_tencon or options.set_mem_tencoff or \
- options.set_mem_tsqlon or options.set_mem_tsqloff or \
- options.set_mem_dtcson or options.set_mem_dtcsoff or \
- options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\
- options.set_mem_dup is not None or \
- options.set_mem_mode or options.set_mem_dtcspol or\
- options.set_mem_offset:
- try:
- mem = radio.get_memory(int(args[0]))
- except errors.InvalidMemoryLocation:
- mem = chirp_common.Memory()
- mem.number = int(args[0])
- mem.name = options.set_mem_name or mem.name
- mem.freq = options.set_mem_freq or mem.freq
- mem.rtone = options.set_mem_tenc or mem.rtone
- mem.ctone = options.set_mem_tsql or mem.ctone
- mem.dtcs = options.set_mem_dtcs or mem.dtcs
- mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity
- if _dup is not None:
- mem.duplex = _dup
- mem.offset = options.set_mem_offset or mem.offset
- mem.mode = _mode or mem.mode
- if options.set_mem_tencon:
- mem.tencEnabled = True
- elif options.set_mem_tencoff:
- mem.tencEnabled = False
- if options.set_mem_tsqlon:
- mem.tsqlEnabled = True
- elif options.set_mem_tsqloff:
- mem.tsqlEnabled = False
- if options.set_mem_dtcson:
- mem.dtcsEnabled = True
- elif options.set_mem_dtcsoff:
- mem.dtcsEnabled = False
- radio.set_memory(mem)
- if options.get_mem:
- try:
- pos = int(args[0])
- except ValueError:
- pos = args[0]
- try:
- mem = radio.get_memory(pos)
- except errors.InvalidMemoryLocation, e:
- mem = chirp_common.Memory()
- mem.number = pos
- print mem
- if options.download_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.sync_in()
- radio.save_mmap(options.mmap)
- if options.upload_mmap:
- #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported()
- radio.load_mmap(options.mmap)
- if radio.sync_out():
- print "Clone successful"
- else:
- print "Clone failed"
- if options.mmap and isinstance(radio, chirp_common.CloneModeRadio):
- radio.save_mmap(options.mmap)
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 01:11 AM, Kosta Arvanitis wrote:
Is it possible to rename a file in HG and have it keep the history?
The rename will preserve all history of the file, though you must ask for it explicitly:
hg log --follow chirpc
If your keen on creating a tool for install purposes, look at the setup script. You may be able to achieve this by creating a named setup distro without requiring a rename of the source file. I haven't tried this myself but should be possible.
I don't think it's a good idea to rename it on install, as it will be confusing to anyone that switches between an installed release and a daily build.
'hg log --follow' is not the default behaviour and thus I don't know if history will be shown in the online repository.
What is the name of the current chirp (windowed) binary in Linux? Is 'chirp' taken? If so then there already exists a discrepancy between the source and the install.
----------------------------------------
Date: Wed, 25 Feb 2015 01:16:11 -0800 From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
On 02/25/2015 01:11 AM, Kosta Arvanitis wrote:
Is it possible to rename a file in HG and have it keep the history?
The rename will preserve all history of the file, though you must ask for it explicitly:
hg log --follow chirpc
If your keen on creating a tool for install purposes, look at the setup script. You may be able to achieve this by creating a named setup distro without requiring a rename of the source file. I haven't tried this myself but should be possible.
I don't think it's a good idea to rename it on install, as it will be confusing to anyone that switches between an installed release and a daily build.
-- Zach Welch Mandolin Creek Farm www.mandolincreekfarm.com farm: 541-453-4131 cell: 541-740-3410 _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 01:33 AM, Kosta Arvanitis wrote:
'hg log --follow' is not the default behaviour and thus I don't know if history will be shown in the online repository.
If it doesn't, that's a bug in the repository viewer.
What is the name of the current chirp (windowed) binary in Linux? Is 'chirp' taken? If so then there already exists a discrepancy between the source and the install.
On ubuntu, the chirpw script is installed as /usr/bin/chirpw. There exists some other unrelated program that gets installed as chirp.
I've stated my view and will resolve to Dan's opinion on such matters as I'm not gaining much benefit from engaging in this further. Thanks for the contributions to date.
----------------------------------------
Date: Wed, 25 Feb 2015 01:39:56 -0800 From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 2/9] Rename chirp.py as chirpc (#2343)
On 02/25/2015 01:33 AM, Kosta Arvanitis wrote:
'hg log --follow' is not the default behaviour and thus I don't know if history will be shown in the online repository.
If it doesn't, that's a bug in the repository viewer.
What is the name of the current chirp (windowed) binary in Linux? Is 'chirp' taken? If so then there already exists a discrepancy between the source and the install.
On ubuntu, the chirpw script is installed as /usr/bin/chirpw. There exists some other unrelated program that gets installed as chirp.
-- Zach Welch Mandolin Creek Farm www.mandolincreekfarm.com farm: 541-453-4131 cell: 541-740-3410 _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Update chirpc argument parsing (#2343)
The optparse module is deprecated, so this patch converts chirpc to use the argparse module. This allows chirpc and chirpw to share argument parsing code.
diff --git a/chirpc b/chirpc index 9e5c59c..b4525a7 100755 --- a/chirpc +++ b/chirpc @@ -18,8 +18,7 @@
import serial import sys -from optparse import OptionParser -import optparse +import argparse
from chirp import * from chirp import chirp_common, errors, idrp, directory, util @@ -34,126 +33,131 @@ def fail_missing_mmap():
RADIOS = directory.DRV_TO_RADIO
-def store_tone(option, opt, value, parser): - if value in chirp_common.TONES: +class ToneAction(argparse.Action): +# def __init__(self, **kwargs): +# super(ToneAction, self).__init__(**kwargs) + + def __call__(self, parser, namespace, value, option_string=None): + if value in chirp_common.TONES: + raise argparse.ArgumentError("Invalid tone valeu: %.1f" % value) + setattr(namespace, self.dest, value) + +class DTCSAction(argparse.Action): + def __call__(self, parser, namespace, value, option_string=None): + try: + value = int(value, 10) + except ValueError: + raise argparse.ArgumentError("Invalid DTCS value: %s" % value) + + if value not in chirp_common.DTCS_CODES: + raise argparse.ArgumentError("Invalid DTCS value: %03i" % value) + setattr(namespace, self.dest, value) + +class DTCSPolarityAction(argparse.Action): + def __call__(self, parser, namespace, value, option_string=None): + if value not in ["NN", "RN", "NR", "RR"]: + raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value) setattr(parser.values, option.dest, value) - else: - raise optparse.OptionValueError("Invalid tone value: %.1f" % value)
-def store_dtcs(option, opt, value, parser): - try: - value = int(value, 10) - except ValueError: - raise optparse.OptionValueError("Invalid DTCS value: %s" % value)
- if value in chirp_common.DTCS_CODES: - setattr(parser.values, option.dest, value) - else: - raise optparse.OptionValueError("Invalid DTCS value: %03i" % value) - -def store_dtcspol(option, opt, value, parser): - if value not in ["NN", "RN", "NR", "RR"]: - raise optparse.OptionValueError("Invaid DTCS polarity: %s" % value) - - setattr(parser.values, option.dest, value) if __name__ == "__main__": - parser = OptionParser() - parser.add_option("-s", "--serial", dest="serial", + parser = argparse.ArgumentParser() + parser.add_argument("-s", "--serial", dest="serial", default="mmap", help="Serial port (default: mmap)")
- parser.add_option("-i", "--id", dest="id", + parser.add_argument("-i", "--id", dest="id", default=False, action="store_true", help="Request radio ID string") - parser.add_option("", "--raw", dest="raw", + parser.add_argument("--raw", dest="raw", default=False, action="store_true", help="Dump raw memory location")
- parser.add_option("", "--get-mem", dest="get_mem", + parser.add_argument("--get-mem", dest="get_mem", default=False, action="store_true", help="Get and print memory location") - parser.add_option("", "--set-mem-name", dest="set_mem_name", + parser.add_argument("--set-mem-name", dest="set_mem_name", default=None, help="Set memory name") - parser.add_option("", "--set-mem-freq", dest="set_mem_freq", - type="float", + parser.add_argument("--set-mem-freq", dest="set_mem_freq", + type=float, default=None, help="Set memory frequency")
- parser.add_option("", "--set-mem-tencon", dest="set_mem_tencon", + parser.add_argument("--set-mem-tencon", dest="set_mem_tencon", default=False, action="store_true", help="Set tone encode enabled flag") - parser.add_option("", "--set-mem-tencoff", dest="set_mem_tencoff", + parser.add_argument("--set-mem-tencoff", dest="set_mem_tencoff", default=False, action="store_true", help="Set tone decode disabled flag") - parser.add_option("", "--set-mem-tsqlon", dest="set_mem_tsqlon", + parser.add_argument("--set-mem-tsqlon", dest="set_mem_tsqlon", default=False, action="store_true", help="Set tone squelch enabled flag") - parser.add_option("", "--set-mem-tsqloff", dest="set_mem_tsqloff", + parser.add_argument("--set-mem-tsqloff", dest="set_mem_tsqloff", default=False, action="store_true", help="Set tone squelch disabled flag") - parser.add_option("", "--set-mem-dtcson", dest="set_mem_dtcson", + parser.add_argument("--set-mem-dtcson", dest="set_mem_dtcson", default=False, action="store_true", help="Set DTCS enabled flag") - parser.add_option("", "--set-mem-dtcsoff", dest="set_mem_dtcsoff", + parser.add_argument("--set-mem-dtcsoff", dest="set_mem_dtcsoff", default=False, action="store_true", help="Set DTCS disabled flag")
- parser.add_option("", "--set-mem-tenc", dest="set_mem_tenc", - type="float", - action="callback", callback=store_tone, nargs=1, + parser.add_argument("--set-mem-tenc", dest="set_mem_tenc", + type=float, action=ToneAction, nargs=1, help="Set memory encode tone") - parser.add_option("", "--set-mem-tsql", dest="set_mem_tsql", - type="float", - action="callback", callback=store_tone, nargs=1, + parser.add_argument("--set-mem-tsql", dest="set_mem_tsql", + type=float, action=ToneAction, nargs=1, help="Set memory squelch tone") - parser.add_option("", "--set-mem-dtcs", dest="set_mem_dtcs", - type="string", - action="callback", callback=store_dtcs, nargs=1, - help="Set memory DTCS code")
- parser.add_option("", "--set-mem-dtcspol", dest="set_mem_dtcspol", - type="string", - action="callback", callback=store_dtcspol, nargs=1, + parser.add_argument("--set-mem-dtcs", dest="set_mem_dtcs", + type=int, action=DTCSAction, nargs=1, + help="Set memory DTCS code") + parser.add_argument("--set-mem-dtcspol", dest="set_mem_dtcspol", + action=DTCSPolarityAction, nargs=1, help="Set memory DTCS polarity (NN, NR, RN, RR)")
- parser.add_option("", "--set-mem-dup", dest="set_mem_dup", + parser.add_argument("--set-mem-dup", dest="set_mem_dup", help="Set memory duplex (+,-, or blank)") - parser.add_option("", "--set-mem-offset", dest="set_mem_offset", - type="float", + parser.add_argument("--set-mem-offset", dest="set_mem_offset", + type=float, help="Set memory duplex offset (in MHz)")
- parser.add_option("", "--set-mem-mode", dest="set_mem_mode", + parser.add_argument("--set-mem-mode", dest="set_mem_mode", default=None, help="Set mode (%s)" % ",".join(chirp_common.MODES)) - parser.add_option("-r", "--radio", dest="radio", + parser.add_argument("-r", "--radio", dest="radio", default=None, help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- parser.add_option("", "--mmap", dest="mmap", + parser.add_argument("--mmap", dest="mmap", default=None, help="Radio memory map file location") - parser.add_option("", "--download-mmap", dest="download_mmap", + parser.add_argument("--download-mmap", dest="download_mmap", action="store_true", default=False, help="Download memory map from radio") - parser.add_option("", "--upload-mmap", dest="upload_mmap", + parser.add_argument("--upload-mmap", dest="upload_mmap", action="store_true", default=False, help="Upload memory map to radio") + parser.add_argument("args", metavar="arg", nargs='*', + help="Some commands require additional arguments") if len(sys.argv) <= 1: parser.print_help() sys.exit(0) - (options, args) = parser.parse_args() + + options = parser.parse_args() + args = options.args
if options.id: from chirp import icf
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
chirpc: add --list-radios option (#2343)
The current list of radios is too long to present to the user in the --help text, so this splits the list out into its own option.
diff --git a/chirpc b/chirpc index b4525a7..6a25e50 100755 --- a/chirpc +++ b/chirpc @@ -137,8 +137,9 @@ if __name__ == "__main__": help="Set mode (%s)" % ",".join(chirp_common.MODES)) parser.add_argument("-r", "--radio", dest="radio", default=None, - help="Radio model (one of %s)" % ",".join(RADIOS.keys())) - + help="Radio model (see --list-radios)") + parser.add_argument("--list-radios", action="store_true", + help="List radio models") parser.add_argument("--mmap", dest="mmap", default=None, help="Radio memory map file location") @@ -159,6 +160,10 @@ if __name__ == "__main__": options = parser.parse_args() args = options.args
+ if options.list_radios: + print "Supported Radios:\n\t", "\n\t".join(sorted(RADIOS.keys())) + sys.exit(0) + if options.id: from chirp import icf
To me this is more of an extension of help than an actual unique command line option. The reason being that it is now the only command (aside from help) which does not actually perform an action on a radio. If we are extending the list of radios why not apply it to set modes, duplex, etc...? Its starting to become rather confusing, imo. On the other hand the list of radios is rather long. Another option may be to print the list of radio at the end help output or to only print it out in verbose help mode, for example.
Most people are going to run --help, not see the list of radios, and they will need to figure out what command to run to see the list of radios, previously a one step process is now a two-step (with some thought).
-kosta
----------------------------------------
From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Date: Tue, 24 Feb 2015 23:26:48 -0800 Subject: [chirp_devel] [PATCH 4/9] chirpc: add --list-radios option (#2343)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
chirpc: add --list-radios option (#2343)
The current list of radios is too long to present to the user in the --help text, so this splits the list out into its own option.
diff --git a/chirpc b/chirpc index b4525a7..6a25e50 100755 --- a/chirpc +++ b/chirpc @@ -137,8 +137,9 @@ if __name__ == "__main__": help="Set mode (%s)" % ",".join(chirp_common.MODES)) parser.add_argument("-r", "--radio", dest="radio", default=None,
- help="Radio model (one of %s)" % ",".join(RADIOS.keys()))
- help="Radio model (see --list-radios)")
- parser.add_argument("--list-radios", action="store_true",
- help="List radio models")
parser.add_argument("--mmap", dest="mmap", default=None, help="Radio memory map file location") @@ -159,6 +160,10 @@ if __name__ == "__main__": options = parser.parse_args() args = options.args
- if options.list_radios:
- print "Supported Radios:\n\t", "\n\t".join(sorted(RADIOS.keys()))
- sys.exit(0)
if options.id: from chirp import icf
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 12:51 AM, Kosta Arvanitis wrote:
To me this is more of an extension of help than an actual unique command line option. The reason being that it is now the only command (aside from help) which does not actually perform an action on a radio.
It is a query command. It allows the code to be self-documenting, as opposed to having to maintain a separate list that will inevitably become out of date.
If we are extending the list of radios why not apply it to set modes, duplex, etc...? Its starting to become rather confusing, imo.
If you are asking for further query commands, I believe that would be a good idea. It will be beneficial to introspect into the tool, when the accepted values may be conditionally or dynamically defined.
On the other hand the list of radios is rather long. Another option may be to print the list of radio at the end help output or to only print it out in verbose help mode, for example.
I do not think it belongs in the help text. That block is already far too long, even after removing the radio list. It will only get worse.
Most people are going to run --help, not see the list of radios, and
they will need to figure out what command to run to see the list of radios, previously a one step process is now a two-step (with some thought).
If they need to specify the radio, it will tell them. They will then use --help to find the option to set the radio (-r). The help text for the that option tells them to use --list-radios to find the list of valid values. While it's slightly more work, I don't see it as a creating a problem for users.
Which list are you referring to that was being maintained? The list in the help text was already being programmatically generated and thus self-documenting.
Regardless, the list was obviously too long and tidying it up (along with verbose output) is called for. My opinion would be to have this info provided in the help text, but if some majority feels being less verbose is beneficial then so be it.
----------------------------------------
Date: Wed, 25 Feb 2015 01:55:03 -0800 From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 4/9] chirpc: add --list-radios option (#2343)
On 02/25/2015 12:51 AM, Kosta Arvanitis wrote:
To me this is more of an extension of help than an actual unique command line option. The reason being that it is now the only command (aside from help) which does not actually perform an action on a radio.
It is a query command. It allows the code to be self-documenting, as opposed to having to maintain a separate list that will inevitably become out of date.
If we are extending the list of radios why not apply it to set modes, duplex, etc...? Its starting to become rather confusing, imo.
If you are asking for further query commands, I believe that would be a good idea. It will be beneficial to introspect into the tool, when the accepted values may be conditionally or dynamically defined.
On the other hand the list of radios is rather long. Another option may be to print the list of radio at the end help output or to only print it out in verbose help mode, for example.
I do not think it belongs in the help text. That block is already far too long, even after removing the radio list. It will only get worse.
Most people are going to run --help, not see the list of radios, and
they will need to figure out what command to run to see the list of radios, previously a one step process is now a two-step (with some thought).
If they need to specify the radio, it will tell them. They will then use --help to find the option to set the radio (-r). The help text for the that option tells them to use --list-radios to find the list of valid values. While it's slightly more work, I don't see it as a creating a problem for users.
-- Zach Welch Mandolin Creek Farm www.mandolincreekfarm.com farm: 541-453-4131 cell: 541-740-3410 _______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
I do not think it belongs in the help text. That block is already far too long, even after removing the radio list. It will only get worse.
Agreed. If your help text scrolls three pages of text, it's broken, IMHO. Having it in the help text worked when we supported eight radios, but it's not digestible there anymore I don't think.
--Dan
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Refactor version display into chirp module (#2343)
This patch makes the version string reusable between the GUI and CLI.
diff --git a/chirp/version.py b/chirp/version.py new file mode 100644 index 0000000..b54706c --- /dev/null +++ b/chirp/version.py @@ -0,0 +1,34 @@ +# Copyright 2008 Dan Smith dsmith@danplanet.com +# Copyright 2015 Zachary T Welch zach@mandolincreekfarm.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +from chirp import CHIRP_VERSION +import argparse +import platform +import sys + + +class VersionAction(argparse.Action): + def __call__(self, parser, namespace, value, option_string=None): + args = (CHIRP_VERSION, + platform.get_platform().os_version_string(), + sys.version.split()[0]) + print "CHIRP %s on %s (Python %s)" % args + sys.exit(1) + + +def add_argument(parser): + parser.add_argument("--version", action=VersionAction, nargs=0, + help="Print version and exit") diff --git a/chirpc b/chirpc index 6a25e50..c3ff224 100755 --- a/chirpc +++ b/chirpc @@ -62,6 +62,7 @@ class DTCSPolarityAction(argparse.Action):
if __name__ == "__main__": parser = argparse.ArgumentParser() + version.add_argument(parser) parser.add_argument("-s", "--serial", dest="serial", default="mmap", help="Serial port (default: mmap)") diff --git a/chirpw b/chirpw index a3a316c..4f53e0d 100755 --- a/chirpw +++ b/chirpw @@ -18,7 +18,7 @@ import os
from chirp import elib_intl -from chirp import platform, CHIRP_VERSION +from chirp import platform, version from chirpui import config
# Hack to setup environment @@ -40,10 +40,6 @@ elif not os.isatty(0): sys.stdout = log sys.stderr = log
-print "CHIRP %s on %s (Python %s)" % (CHIRP_VERSION, - platform.get_platform().os_version_string(), - sys.version.split()[0]) - execpath = platform.get_platform().executable_path() localepath = os.path.abspath(os.path.join(execpath, "locale")) if not os.path.exists(localepath): @@ -127,6 +123,7 @@ from chirpui import mainapp, config
parser = argparse.ArgumentParser() parser.add_argument("files", metavar="file", nargs='*', help="File to open") +version.add_argument(parser) parser.add_argument("--profile", action="store_true", help="Enable profiling") args = parser.parse_args()
+class VersionAction(argparse.Action):
- def __call__(self, parser, namespace, value, option_string=None):
args = (CHIRP_VERSION,
platform.get_platform().os_version_string(),
sys.version.split()[0])
print "CHIRP %s on %s (Python %s)" % args
sys.exit(1)
It's not okay, IMHO, to exit() from a library call.
Overall, I don't think it's worth having a separate module for just this little thing. I'd just put it in __init__.py, or in chirp_common.
--Dan
On 02/25/2015 08:32 AM, Dan Smith wrote:
+class VersionAction(argparse.Action):
- def __call__(self, parser, namespace, value, option_string=None):
args = (CHIRP_VERSION,
platform.get_platform().os_version_string(),
sys.version.split()[0])
print "CHIRP %s on %s (Python %s)" % args
sys.exit(1)
It's not okay, IMHO, to exit() from a library call.
It's no different than argparse.parse_args exiting when using the --help option.
Overall, I don't think it's worth having a separate module for just this little thing. I'd just put it in __init__.py, or in chirp_common.
chirp_common is already pretty busy. __init__.py gets made static my setup.py (right?). I do not see anything wrong with having a small module like this, since it's shared between chirpc and chirpw.
Maybe merge it with logger.py (as it's shared too)? I just realized that we _really_ want to record this information in our log files.
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Add chirp.logger module (#2347)
This patch adds the chirp.logger module, using it in chirpc and chirpw. It adds a handful of optional command line arguments to control the new logging features. In addition, CHIRP_DEBUG, CHIRP_LOG, and CHIRP_LOG_LEVEL can be used to control the logging features from the environment.
diff --git a/chirp/logger.py b/chirp/logger.py new file mode 100644 index 0000000..753f75f --- /dev/null +++ b/chirp/logger.py @@ -0,0 +1,127 @@ +# Copyright 2015 Zachary T Welch zach@mandolincreekfarm.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + + +r""" +The chirp.logger module provides the core logging facilties for CHIRP. +It sets up the console and (optionally) a log file. For early debugging, +it checks the CHIRP_DEBUG, CHIRP_LOG, and CHIRP_LOG_LEVEL environment +variables. +""" + +import logging +import os + +#: Map human-readable logging levels to their internal values. +log_level_names = {"critical": logging.CRITICAL, + "error": logging.ERROR, + "warn": logging.WARNING, + "info": logging.INFO, + "debug": logging.DEBUG, + } + + +class Logger(object): + def __init__(self): + # create root logger + self.logger = logging.getLogger() + self.logger.setLevel(logging.DEBUG) + + self.LOG = logging.getLogger(__name__) + + # Set CHIRP_DEBUG in environment for early console debugging. + # It can be a number or a name; otherwise, level is set to 'debug' + # in order to maintain backward compatibility. + CHIRP_DEBUG = os.getenv("CHIRP_DEBUG") + level = logging.WARNING + if CHIRP_DEBUG: + try: + level = int(CHIRP_DEBUG) + except: + try: + level = log_evel_names[CHIRP_DEBUG] + except: + level = logging.DEBUG + + self.console = logging.StreamHandler() + self.console.setLevel(level) + format_str = '%(levelname)s: %(message)s' + self.console.setFormatter(logging.Formatter(format_str)) + self.logger.addHandler(self.console) + + # Set CHIRP_LOG in envoronment to the name of log file. + logname = os.getenv("CHIRP_LOG") + self.logfile = None + if logname is not None: + self.create_log_file(logname) + level = os.getenv("CHIRP_LOG_LEVEL") + if level is not None: + self.set_log_verbosity(level) + else: + self.set_log_level(logging.DEBUG) + + self.LOG.debug("logging started") + + def create_log_file(self, name): + if self.logfile is None: + self.logname = name + self.logfile = logging.FileHandler(name) + format_str = '[%(asctime)s] %(name)s - %(levelname)s: %(message)s' + self.logfile.setFormatter(logging.Formatter(format_str)) + self.logger.addHandler(self.logfile) + else: + self.logger.error("already logging to " + self.logname) + + def set_verbosity(self, level): + if level > logging.CRITICAL: + level = logging.CRITICAL + self.console.setLevel(level) + self.LOG.debug("verbosity=%d", level) + + def set_log_level(self, level): + if level > logging.CRITICAL: + level = logging.CRITICAL + self.logfile.setLevel(level) + self.LOG.debug("log level=%d", level) + + def set_log_level_by_name(self, level): + self.set_log_level(log_level_names[level]) + +LOG = Logger() + + +def add_arguments(parser): + parser.add_argument("-q", "--quiet", action="count", default=0, + help="Decrease verbosity") + parser.add_argument("-v", "--verbose", action="count", default=0, + help="Increase verbosity") + parser.add_argument("--log", dest="log_file", action="store", default=0, + help="Log messages to a file") + parser.add_argument("--log-level", action="store", default="debug", + help="Log file verbosity (critical, error, warn, " + + "info, debug). Defaults to 'debug'.") + + +def handle_options(options): + if options.verbose or options.quiet: + LOG.set_verbosity(30 + 10 * (options.quiet - options.verbose)) + + if options.log_file: + LOG.create_log_file(options.log_file) + try: + level = int(options.log_level) + LOG.set_log_level(level) + except: + LOG.set_log_level_by_name(options.log_level) diff --git a/chirpc b/chirpc index c3ff224..dc55de3 100755 --- a/chirpc +++ b/chirpc @@ -19,10 +19,14 @@ import serial import sys import argparse +import logging
+from chirp import logger from chirp import * from chirp import chirp_common, errors, idrp, directory, util
+LOG = logging.getLogger("chirpc") + def fail_unsupported(): print "Operation not supported by selected radio" sys.exit(1) @@ -152,8 +156,10 @@ if __name__ == "__main__": action="store_true", default=False, help="Upload memory map to radio") + logger.add_arguments(parser) parser.add_argument("args", metavar="arg", nargs='*', help="Some commands require additional arguments") + if len(sys.argv) <= 1: parser.print_help() sys.exit(0) @@ -161,6 +167,8 @@ if __name__ == "__main__": options = parser.parse_args() args = options.args
+ logger.handle_options(options) + if options.list_radios: print "Supported Radios:\n\t", "\n\t".join(sorted(RADIOS.keys())) sys.exit(0) @@ -182,7 +190,7 @@ if __name__ == "__main__": if options.mmap: rclass = directory.get_radio_by_image(options.mmap).__class__ else: - print "Must specify a radio model" + LOG.critical("You must specify a radio model.") sys.exit(1) else: rclass = directory.get_radio(options.radio) diff --git a/chirpw b/chirpw index 4f53e0d..c1fd0ea 100755 --- a/chirpw +++ b/chirpw @@ -18,7 +18,7 @@ import os
from chirp import elib_intl -from chirp import platform, version +from chirp import platform, version, logger from chirpui import config
# Hack to setup environment @@ -126,8 +126,11 @@ parser.add_argument("files", metavar="file", nargs='*', help="File to open") version.add_argument(parser) parser.add_argument("--profile", action="store_true", help="Enable profiling") +logger.add_arguments(parser) args = parser.parse_args()
+logger.handle_options(args) + a = mainapp.ChirpMain()
for i in args.files:
+#: Map human-readable logging levels to their internal values. +log_level_names = {"critical": logging.CRITICAL,
"error": logging.ERROR,
"warn": logging.WARNING,
"info": logging.INFO,
"debug": logging.DEBUG,
}
I don't think we need this:
logging.getLevelName(logging.DEBUG)
'DEBUG'
+class Logger(object):
- def __init__(self):
# create root logger
self.logger = logging.getLogger()
self.logger.setLevel(logging.DEBUG)
self.LOG = logging.getLogger(__name__)
# Set CHIRP_DEBUG in environment for early console debugging.
# It can be a number or a name; otherwise, level is set to 'debug'
# in order to maintain backward compatibility.
CHIRP_DEBUG = os.getenv("CHIRP_DEBUG")
level = logging.WARNING
if CHIRP_DEBUG:
try:
level = int(CHIRP_DEBUG)
except:
I know the chirp code is not a good example of this, but using "except exception" is generally frowned upon. ValueError is the thing you're trying to catch here, so you should just catch it.
try:
level = log_evel_names[CHIRP_DEBUG]
Typo here: log_evel_names doesn't match above.
except:
level = logging.DEBUG
IMHO, CHIRP_DEBUG is really just a hack we put in place in a few places. If it's set, I'd set logging to debug and if not, do nothing.
self.console = logging.StreamHandler()
self.console.setLevel(level)
format_str = '%(levelname)s: %(message)s'
self.console.setFormatter(logging.Formatter(format_str))
self.logger.addHandler(self.console)
# Set CHIRP_LOG in envoronment to the name of log file.
logname = os.getenv("CHIRP_LOG")
self.logfile = None
if logname is not None:
self.create_log_file(logname)
level = os.getenv("CHIRP_LOG_LEVEL")
if level is not None:
self.set_log_verbosity(level)
else:
self.set_log_level(logging.DEBUG)
self.LOG.debug("logging started")
A huge part of our ability to support people when they file bugs is asking them for the debug log. On Windows and MacOS, that is in chirp's profile directory, called 'debug.log'. IMHO, that's not something we want to lose.
So, I think this always needs to log at debug level to that location. If you want to add an option to disable it, or make it conditional on istty() of stdout, then that's fine too.
Given that, I'm not sure it's important to have an other configurable log, but if it is, I think doing so via an argument is sufficient. It's "really hard" for Windows people to set an environment variable.
+LOG = Logger()
IMHO, module-scope variables named "LOG" should be instances of the logging.Logger class. I don't really think the stuff you have in this class needs to be a class, but I also don't think it needs to be referenced outside of this module. I think we can just setup logging at start time and be done with it, right?
print "Must specify a radio model"
LOG.critical("You must specify a radio model.") sys.exit(1)
I don't think it makes sense for this to be a log call, does it? It's usage information printed before we do anything.
Otherwise, really happy to see us moving towards some organized logging of things, thanks!
--Dan
On 02/25/2015 08:43 AM, Dan Smith wrote:
+#: Map human-readable logging levels to their internal values. +log_level_names = {"critical": logging.CRITICAL,
"error": logging.ERROR,
"warn": logging.WARNING,
"info": logging.INFO,
"debug": logging.DEBUG,
}
I don't think we need this:
logging.getLevelName(logging.DEBUG)
'DEBUG'
That method maps the number to the name. I don't see a method that maps from name to number, which is what that dict does for us.
if CHIRP_DEBUG:
try:
level = int(CHIRP_DEBUG)
except:
I know the chirp code is not a good example of this, but using "except exception" is generally frowned upon. ValueError is the thing you're trying to catch here, so you should just catch it.
Fixed.
try:
level = log_evel_names[CHIRP_DEBUG]
Typo here: log_evel_names doesn't match above.
Good catch. Also, the matching except for this needs to catch KeyError.
except:
level = logging.DEBUG
IMHO, CHIRP_DEBUG is really just a hack we put in place in a few places. If it's set, I'd set logging to debug and if not, do nothing.
With proper logging, we can start adding many more LOG.<level>() calls, which may make it desirable to limit the output. Basically I think that it's a feature that I will use, or I wouldn't have added it.
...
A huge part of our ability to support people when they file bugs is asking them for the debug log. On Windows and MacOS, that is in chirp's profile directory, called 'debug.log'. IMHO, that's not something we want to lose.
So, I think this always needs to log at debug level to that location. If you want to add an option to disable it, or make it conditional on istty() of stdout, then that's fine too.
There is nothing stopping us from always logging to such a location in addition to other places.
Thus, I would vote for adding a new handler for that purpose, rather than changing the existing code (which gives developers more flexibility). The full DEBUG level output is really too verbose, and I would be annoyed if that were my only option.
I also vote to punt on that addition for another patch.
+LOG = Logger()
IMHO, module-scope variables named "LOG" should be instances of the logging.Logger class. I don't really think the stuff you have in this class needs to be a class, but I also don't think it needs to be referenced outside of this module. I think we can just setup logging at start time and be done with it, right?
I can imagine adding a menu option to the GUI ("Enable logging") and a window that updates in real-time. Naturally, that would be down the road, but that would be a wickedly useful feature for users. They could just copy and paste the relevant log information straight out of the GUI and into their mailer. Thus, I say the Logger class should be left intact, though I will move the LOG variable into the class.
print "Must specify a radio model"
LOG.critical("You must specify a radio model.") sys.exit(1)
I don't think it makes sense for this to be a log call, does it? It's usage information printed before we do anything.
Yeah, okay... It was more for my own testing than anything. I'll change it back.
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Use new logger module (#2347)
This patch adds logging support to the chirp.py script, including a handful of command line options to control this feature. I plan add these options to chirpw too, but that will require a separate patch that adds proper option parsing.
This patch chases down all references to CHIRP_DEBUG, converting the wrapped print calls to LOG.debug calls. it also eliminates a few plain DEBUG variables and a couple of other one-off variants.
diff --git a/chirp/anytone.py b/chirp/anytone.py index 4b9c785..b7d722b 100644 --- a/chirp/anytone.py +++ b/chirp/anytone.py @@ -16,6 +16,7 @@ import os import struct import time +import logging
from chirp import bitwise from chirp import chirp_common @@ -26,6 +27,8 @@ from chirp import util from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings, \ RadioSettingValueList, RadioSettingValueString, RadioSettingValueBoolean
+LOG = logging.getLogger(__name__) + _mem_format = """ #seekto 0x0100; struct { @@ -164,10 +167,6 @@ def _should_send_addr(memobj, addr): else: return _is_loc_used(memobj, _addr_to_loc(addr))
-def _debug(string): - if "CHIRP_DEBUG" in os.environ or True: - print string - def _echo_write(radio, data): try: radio.pipe.write(data) @@ -201,7 +200,7 @@ def _ident(radio): raise errors.RadioError("Unsupported model") _echo_write(radio, "\x02") response = radio.pipe.read(16) - _debug(util.hexprint(response)) + LOG.debug(util.hexprint(response)) if response[1:8] not in valid_model: print "Response was:\n%s" % util.hexprint(response) raise errors.RadioError("Unsupported model") @@ -227,7 +226,7 @@ def _send(radio, cmd, addr, length, data=None): frame += chr(_checksum(frame[1:])) frame += "\x06" _echo_write(radio, frame) - _debug("Sent:\n%s" % util.hexprint(frame)) + LOG.debug("Sent:\n%s" % util.hexprint(frame)) if data: result = radio.pipe.read(1) if result != "\x06": @@ -236,7 +235,7 @@ def _send(radio, cmd, addr, length, data=None): addr) return result = _read(radio, length + 6) - _debug("Got:\n%s" % util.hexprint(result)) + LOG.debug("Got:\n%s" % util.hexprint(result)) header = result[0:4] data = result[4:-2] ack = result[-1] diff --git a/chirp/baofeng_uv3r.py b/chirp/baofeng_uv3r.py index 52d1a78..0827885 100644 --- a/chirp/baofeng_uv3r.py +++ b/chirp/baofeng_uv3r.py @@ -24,11 +24,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettingValueFloat, RadioSettings
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def _uv3r_prep(radio): radio.pipe.write("\x05PROGRAM") ack = radio.pipe.read(1) diff --git a/chirp/bjuv55.py b/chirp/bjuv55.py index 7dd61be..9fb7e5a 100644 --- a/chirp/bjuv55.py +++ b/chirp/bjuv55.py @@ -28,11 +28,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from textwrap import dedent from chirp import uv5r
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - BJUV55_MODEL = "\x50\xBB\xDD\x55\x63\x98\x4D"
COLOR_LIST = ["Off", "Blue", "Red", "Pink"] diff --git a/chirp/ft1d.py b/chirp/ft1d.py index eb7a0b1..db0259f 100644 --- a/chirp/ft1d.py +++ b/chirp/ft1d.py @@ -17,6 +17,7 @@ import os import re import string +import logging
from chirp import chirp_common, yaesu_clone, directory from chirp import bitwise @@ -25,6 +26,8 @@ from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean from textwrap import dedent
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x049a; struct { @@ -1549,8 +1552,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): is_latitude = name.endswith("latitude") lat_long = setting.value.get_value().strip() sign, l_d, l_m, l_s = cls._str_to_latlong(lat_long, is_latitude) - if os.getenv("CHIRP_DEBUG"): - print "%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s) + LOG.debug("%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s)) setattr(obj, "%s_sign" % name, sign) setattr(obj, "%s_degree" % name, l_d) setattr(obj, "%s_minute" % name, l_m) @@ -1587,9 +1589,8 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio):
try: old_val = getattr(obj, setting) - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%r) <= %s" % ( - element.get_name(), old_val, element.value) + LOG.debug("Setting %s(%r) <= %s" % ( + element.get_name(), old_val, element.value)) setattr(obj, setting, element.value) except AttributeError as e: print "Setting %s is not in the memory map: %s" % ( @@ -1623,4 +1624,4 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): val = [FT1_DTMF_CHARS.index(x) for x in rawval] for x in range(len(val), 16): val.append(0xFF) - cls._memobj.dtmf[i].memory = val \ No newline at end of file + cls._memobj.dtmf[i].memory = val diff --git a/chirp/ft2800.py b/chirp/ft2800.py index fb9d10c..feac0ce 100644 --- a/chirp/ft2800.py +++ b/chirp/ft2800.py @@ -15,11 +15,12 @@
import time import os +import logging
from chirp import util, memmap, chirp_common, bitwise, directory, errors from chirp.yaesu_clone import YaesuCloneModeRadio
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
CHUNK_SIZE = 16 def _send(s, data): @@ -41,8 +42,7 @@ def _download(radio): if data == IDBLOCK: break
- if DEBUG: - print "Header:\n%s" % util.hexprint(data) + LOG.debug("Header:\n%s" % util.hexprint(data))
if len(data) != 8: raise Exception("Failed to read header") @@ -54,8 +54,7 @@ def _download(radio): while len(data) < radio._block_sizes[1]: time.sleep(0.1) chunk = radio.pipe.read(38) - if DEBUG: - print "Got: %i:\n%s" % (len(chunk), util.hexprint(chunk)) + LOG.debug("Got: %i:\n%s" % (len(chunk), util.hexprint(chunk))) if len(chunk) == 8: print "END?" elif len(chunk) != 38: @@ -79,8 +78,7 @@ def _download(radio): status.msg = "Cloning from radio" radio.status_fn(status)
- if DEBUG: - print "Total: %i" % len(data) + LOG.debug("Total: %i" % len(data))
return memmap.MemoryMap(data)
@@ -94,8 +92,7 @@ def _upload(radio): _send(radio.pipe, IDBLOCK) time.sleep(1) ack = radio.pipe.read(300) - if DEBUG: - print "Ack was (%i):\n%s" % (len(ack), util.hexprint(ack)) + LOG.debug("Ack was (%i):\n%s" % (len(ack), util.hexprint(ack))) if ack != ACK: raise Exception("Radio did not ack ID")
@@ -108,8 +105,7 @@ def _upload(radio): cs += ord(byte) data += chr(cs & 0xFF)
- if DEBUG: - print "Writing block %i:\n%s" % (block, util.hexprint(data)) + LOG.debug("Writing block %i:\n%s" % (block, util.hexprint(data)))
_send(radio.pipe, data) time.sleep(0.1) diff --git a/chirp/ft60.py b/chirp/ft60.py index 45c92d0..74799ef 100644 --- a/chirp/ft60.py +++ b/chirp/ft60.py @@ -13,7 +13,7 @@ # 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 time, os +import time, os, logging from chirp import chirp_common, yaesu_clone, memmap, bitwise, directory from chirp import errors from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -22,6 +22,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, RadioSettings from textwrap import dedent
+LOG = logging.getLogger(__name__) + ACK = "\x06"
def _send(pipe, data): @@ -617,8 +619,7 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio): obj = getattr(_settings, name) setattr(_settings, name, value)
- if os.getenv("CHIRP_DEBUG"): - print "Setting %s: %s" % (name, value) + LOG.debug("Setting %s: %s" % (name, value)) except Exception, e: print element.get_name() raise diff --git a/chirp/ft7800.py b/chirp/ft7800.py index 451fb08..824bd6d 100644 --- a/chirp/ft7800.py +++ b/chirp/ft7800.py @@ -13,7 +13,7 @@ # 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 time +import time, logging from chirp import chirp_common, yaesu_clone, memmap, directory from chirp import bitwise, errors from textwrap import dedent @@ -25,10 +25,7 @@ import os, re
from collections import defaultdict
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
ACK = chr(0x06)
@@ -540,9 +537,8 @@ class FT7800Radio(FTx800Radio): FTx800Radio.set_memory(self, memory)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -551,9 +547,8 @@ class FT7800Radio(FTx800Radio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(length): @@ -647,8 +642,7 @@ class FT7800Radio(FTx800Radio): break if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -721,8 +715,7 @@ class FT7800Radio(FTx800Radio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-2:]) _settings = self._memobj.dtmf[idx] _settings.memory = newval @@ -735,9 +728,7 @@ class FT7800Radio(FTx800Radio): # normal settings newval = element.value oldval = getattr(_settings, setting) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() diff --git a/chirp/ft817.py b/chirp/ft817.py index 8950f73..319bc46 100644 --- a/chirp/ft817.py +++ b/chirp/ft817.py @@ -22,9 +22,11 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import time, os +import time, os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + CMD_ACK = 0x06
@directory.register @@ -319,8 +321,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): raise Exception("Unable to read block %02X expected %i got %i" % (blocknum, block + 2, len(data)))
- if os.getenv("CHIRP_DEBUG"): - print "Read %i" % len(data) + LOG.debug("Read %i" % len(data)) return data
def _clone_in(self): @@ -382,15 +383,12 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): for _i in range(0, repeat): time.sleep(0.01) checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 1) - if os.getenv("CHIRP_DEBUG"): - print "Block %i - will send from %i to %i byte " % \ - (blocks, - pos, - pos + block) - print util.hexprint(chr(blocks)) - print util.hexprint(self.get_mmap()[pos:pos + block]) - print util.hexprint(chr(checksum.get_calculated( - self.get_mmap()))) + LOG.debug("Block %i - will send from %i to %i byte " % \ + (blocks, pos, pos + block)) + LOG.debug(util.hexprint(chr(blocks))) + LOG.debug(util.hexprint(self.get_mmap()[pos:pos + block])) + LOG.debug(util.hexprint(chr(checksum.get_calculated( + self.get_mmap())))) self.pipe.write(chr(blocks)) self.pipe.write(self.get_mmap()[pos:pos + block]) self.pipe.write(chr(checksum.get_calculated(self.get_mmap()))) @@ -399,8 +397,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): time.sleep(delay) buf = self.pipe.read(1) if not buf or buf[0] != chr(CMD_ACK): - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(buf) + LOG.debug(util.hexprint(buf)) raise Exception(_("Radio did not ack block %i") % blocks) pos += block blocks += 1 @@ -1030,9 +1027,8 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): else: obj = _settings setting = element.get_name() - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%s) <= %s" % (setting, - getattr(obj, setting), element.value) + LOG.debug("Setting %s(%s) <= %s" % (setting, + getattr(obj, setting), element.value)) if setting == "contrast": setattr(obj, setting, int(element.value) + 1) elif setting == "callsign": diff --git a/chirp/ft857.py b/chirp/ft857.py index a479623..ebe8e12 100644 --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -21,9 +21,11 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import os +import os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + @directory.register class FT857Radio(ft817.FT817Radio): """Yaesu FT-857/897""" @@ -956,9 +958,8 @@ class FT857Radio(ft817.FT817Radio): else: obj = _settings setting = element.get_name() - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%s) <= %s" % (setting, - getattr(obj, setting), element.value) + LOG.debug("Setting %s(%s) <= %s" % (setting, + getattr(obj, setting), element.value)) if setting == "arts_idw": self._memobj.arts_idw = \ [self._CALLSIGN_CHARSET_REV[x] for x in diff --git a/chirp/ft90.py b/chirp/ft90.py index bfbddda..b638d47 100644 --- a/chirp/ft90.py +++ b/chirp/ft90.py @@ -19,13 +19,10 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import time, os, traceback, string, re +import time, os, traceback, string, re, logging from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG=False +LOG = logging.getLogger(__name__)
CMD_ACK = chr(0x06)
@@ -289,27 +286,24 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): blocknumbyte = chr(blocknum) payloadbytes = self.get_mmap()[pos:pos+blocksize] checksumbyte = chr(checksum.get_calculated(self.get_mmap())) - if CHIRP_DEBUG: - print "Block %i - will send from %i to %i byte " % \ - (blocknum, pos, pos + blocksize) - print util.hexprint(blocknumbyte) - print util.hexprint(payloadbytes) - print util.hexprint(checksumbyte) + LOG.debug("Block %i - will send from %i to %i byte " % \ + (blocknum, pos, pos + blocksize)) + LOG.debug(util.hexprint(blocknumbyte)) + LOG.debug(util.hexprint(payloadbytes)) + LOG.debug(util.hexprint(checksumbyte)) # send wrapped bytes time.sleep(looppredelay) self.pipe.write(blocknumbyte) self.pipe.write(payloadbytes) self.pipe.write(checksumbyte) tmp = self.pipe.read(blocksize+2) #chew echo - if CHIRP_DEBUG: - print "bytes echoed: " - print util.hexprint(tmp) + LOG.debug("bytes echoed: ") + LOG.debug(util.hexprint(tmp)) # radio is slow to write/ack: time.sleep(looppostdelay) buf = self.pipe.read(1) - if CHIRP_DEBUG: - print "ack recd:" - print util.hexprint(buf) + LOG.debug("ack recd:") + LOG.debug(util.hexprint(buf)) if buf != CMD_ACK: raise Exception("Radio did not ack block %i" % blocknum) pos += blocksize @@ -463,12 +457,10 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
def _decode_cwid(self, cwidarr): cwid = "" - if CHIRP_DEBUG: - print "@ +_decode_cwid:" + LOG.debug("@ +_decode_cwid:") for byte in cwidarr.get_value(): char = int(byte) - if CHIRP_DEBUG: - print char + LOG.debug(char) # bitwise wraps in quotes! get rid of those if char < len(FT90_CWID_CHARS): cwid += FT90_CWID_CHARS[char] @@ -476,21 +468,17 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
def _encode_cwid(self, cwidarr): cwid = "" - if CHIRP_DEBUG: - print "@ _encode_cwid:" + LOG.debug("@ _encode_cwid:") for char in cwidarr.get_value(): cwid += chr(FT90_CWID_CHARS.index(char)) - if CHIRP_DEBUG: - print cwid + LOG.debug(cwid) return cwid
def _bbcd2dtmf(self, bcdarr, strlen = 16): # doing bbcd, but with support for ABCD*# - if CHIRP_DEBUG: - print bcdarr.get_value() + LOG.debug(bcdarr.get_value()) string = ''.join("%02X" % b for b in bcdarr) - if CHIRP_DEBUG: - print "@_bbcd2dtmf, received: %s" % string + LOG.debug("@_bbcd2dtmf, received: %s" % string) string = string.replace('E','*').replace('F','#') if strlen <= 16: string = string[:strlen] @@ -501,8 +489,7 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): dtmfstr = dtmfstr.replace('*', 'E').replace('#', 'F') dtmfstr = str.ljust(dtmfstr.strip(), 16, "0" ) bcdarr = list(bytearray.fromhex(dtmfstr)) - if CHIRP_DEBUG: - print "@_dtmf2bbcd, sending: %s" % bcdarr + LOG.debug("@_dtmf2bbcd, sending: %s" % bcdarr) return bcdarr
def get_settings(self): @@ -644,9 +631,7 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): dtmfstrlen = len(str(newval).strip()) setattr(_settings, setting + "_len", dtmfstrlen) newval = self._dtmf2bbcd(newval) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() diff --git a/chirp/ftm350.py b/chirp/ftm350.py index 442cde1..e3fcbfe 100644 --- a/chirp/ftm350.py +++ b/chirp/ftm350.py @@ -16,12 +16,15 @@ import time import struct import os +import logging
from chirp import chirp_common, yaesu_clone, directory, errors, util from chirp import bitwise, memmap from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings from chirp.settings import RadioSettingValueInteger, RadioSettingValueString
+LOG = logging.getLogger(__name__) + mem_format = """ struct mem { u8 used:1, @@ -141,8 +144,8 @@ def _clone_in(radio): radio.pipe.write("\x06") time.sleep(0.05)
- if os.getenv("CHIRP_DEBUG") and (last_addr + 128) != addr: - print "Gap, expecting %04x, got %04x" % (last_addr+128, addr) + if (last_addr + 128) != addr: + LOG.debug("Gap, expecting %04x, got %04x" % (last_addr+128, addr)) last_addr = addr data[addr] = block length += len(block) diff --git a/chirp/h777.py b/chirp/h777.py index bce4b98..5ac0351 100644 --- a/chirp/h777.py +++ b/chirp/h777.py @@ -18,6 +18,7 @@ import time import os import struct import unittest +import logging
from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util @@ -25,7 +26,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettings
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0010; @@ -139,8 +140,7 @@ def _h777_read_block(radio, block_addr, block_size):
cmd = struct.pack(">cHb", 'R', block_addr, BLOCK_SIZE) expectedresponse = "W" + cmd[1:] - if DEBUG: - print("Reading block %04x..." % (block_addr)) + LOG.debug("Reading block %04x..." % (block_addr))
try: serial.write(cmd) @@ -166,9 +166,8 @@ def _h777_write_block(radio, block_addr, block_size): cmd = struct.pack(">cHb", 'W', block_addr, BLOCK_SIZE) data = radio.get_mmap()[block_addr:block_addr + 8]
- if DEBUG: - print("Writing Data:") - print util.hexprint(cmd + data) + LOG.debug("Writing Data:") + LOG.debug(util.hexprint(cmd + data))
try: serial.write(cmd + data) @@ -197,9 +196,8 @@ def do_download(radio): block = _h777_read_block(radio, addr, BLOCK_SIZE) data += block
- if DEBUG: - print "Address: %04x" % addr - print util.hexprint(block) + LOG.debug("Address: %04x" % addr) + LOG.debug(util.hexprint(block))
_h777_exit_programming_mode(radio)
diff --git a/chirp/icomciv.py b/chirp/icomciv.py index 71af300..1d02553 100644 --- a/chirp/icomciv.py +++ b/chirp/icomciv.py @@ -1,9 +1,9 @@
-import struct +import struct, logging from chirp import chirp_common, icf, util, errors, bitwise, directory from chirp.memmap import MemoryMap
-DEBUG = True +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ bbcd number[2]; @@ -80,9 +80,8 @@ class Frame: raw = struct.pack("BBBBBB", 0xFE, 0xFE, src, dst, self._cmd, self._sub) raw += str(self._data) + chr(0xFD)
- if DEBUG: - print "%02x -> %02x (%i):\n%s" % (src, dst, - len(raw), util.hexprint(raw)) + LOG.debug("%02x -> %02x (%i):\n%s" % (src, dst, + len(raw), util.hexprint(raw)))
serial.write(raw) if willecho: @@ -106,8 +105,7 @@ class Frame: raise errors.RadioError("Radio reported error")
src, dst = struct.unpack("BB", data[2:4]) - if DEBUG: - print "%02x <- %02x:\n%s" % (src, dst, util.hexprint(data)) + LOG.debug("%02x <- %02x:\n%s" % (src, dst, util.hexprint(data)))
self._cmd = ord(data[4]) self._sub = ord(data[5]) diff --git a/chirp/idrp.py b/chirp/idrp.py index e20ba07..012bb46 100644 --- a/chirp/idrp.py +++ b/chirp/idrp.py @@ -13,12 +13,11 @@ # 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 serial +import serial, logging
-from chirp import chirp_common, errors -from chirp import util +from chirp import chirp_common, errors, util
-DEBUG_IDRP = False +LOG = logging.getLogger(__name__)
def parse_frames(buf): """Parse frames from the radio""" @@ -49,8 +48,7 @@ def send(pipe, buf): break
data += buf - if DEBUG_IDRP: - print "Got: \n%s" % util.hexprint(buf) + LOG.debug("Got: \n%s" % util.hexprint(buf))
return parse_frames(data)
@@ -97,8 +95,7 @@ def get_freq(pipe): ord(els[2]), ord(els[1]), ord(els[0]))) - if DEBUG_IDRP: - print "Freq: %f" % freq + LOG.debug("Freq: %f" % freq) return freq
raise errors.InvalidDataError("No frequency frame received") diff --git a/chirp/kenwood_live.py b/chirp/kenwood_live.py index 971c08e..6cac1c9 100644 --- a/chirp/kenwood_live.py +++ b/chirp/kenwood_live.py @@ -17,6 +17,9 @@ import threading import os import sys import time +import logging + +LOG = logging.getLogger(__name__)
NOCACHE = os.environ.has_key("CHIRP_NOCACHE")
@@ -29,8 +32,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueBoolean, \ RadioSettingValueString, RadioSettingValueList, RadioSettings
-DEBUG = True - DUPLEX = { 0 : "", 1 : "+", 2 : "-" } MODES = { 0 : "FM", 1 : "AM" } STEPS = list(chirp_common.TUNING_STEPS) @@ -49,8 +50,7 @@ def command(ser, cmd, *args): LOCK.acquire() if args: cmd += " " + " ".join(args) - if DEBUG: - print "PC->RADIO: %s" % cmd + LOG.debug("PC->RADIO: %s" % cmd) ser.write(cmd + "\r")
result = "" @@ -60,8 +60,7 @@ def command(ser, cmd, *args): print "Timeout waiting for data" break
- if DEBUG: - print "D7->PC: %s" % result.strip() + LOG.debug("D7->PC: %s" % result.strip())
LOCK.release()
diff --git a/chirp/kguv8d.py b/chirp/kguv8d.py index 772b04f..d0f779f 100644 --- a/chirp/kguv8d.py +++ b/chirp/kguv8d.py @@ -17,16 +17,14 @@
import time import os +import logging from chirp import util, chirp_common, bitwise, memmap, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettings
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
CMD_ID = 128 CMD_END = 129 @@ -304,8 +302,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _packet += payload # calculate and add the checksum to the packet _packet += chr(self._checksum(_packet[1:])) - if CHIRP_DEBUG: - print "Sent:\n%s" % util.hexprint(_packet) + LOG.debug("Sent:\n%s" % util.hexprint(_packet)) self.pipe.write(_packet)
def _read_record(self): @@ -317,9 +314,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _cs += self._checksum(_packet) _cs %= 256 _rcs = ord(self.pipe.read(1)) - if CHIRP_DEBUG: - print "_cs =", _cs - print "_rcs=", _rcs + LOG.debug("_cs =", _cs) + LOG.debug("_rcs=", _rcs) return (_rcs != _cs, _packet)
# Identify the radio @@ -350,14 +346,12 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, for _i in range(0, 10): self._write_record(CMD_ID) _chksum_err, _resp = self._read_record() - if CHIRP_DEBUG: - print "Got:\n%s" % util.hexprint(_resp) + LOG.debug("Got:\n%s" % util.hexprint(_resp)) if _chksum_err: print "Checksum error: retrying ident..." time.sleep(0.100) continue - if CHIRP_DEBUG: - print "Model %s" % util.hexprint(_resp[0:7]) + LOG.debug("Model %s" % util.hexprint(_resp[0:7])) if _resp[0:7] == self._model: return if len(_resp) == 0: @@ -407,8 +401,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, # TODO: probably should retry a few times here print util.hexprint(resp) raise Exception("Checksum error on read") - if CHIRP_DEBUG: - print "Got:\n%s" % util.hexprint(resp) + LOG.debug("Got:\n%s" % util.hexprint(resp)) image += resp[2:] if self.status_fn: status = chirp_common.Status() @@ -436,11 +429,9 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, req = chr(i / 256) + chr(i % 256) chunk = self.get_mmap()[ptr:ptr + blocksize] self._write_record(CMD_WR, req + chunk) - if CHIRP_DEBUG: - print util.hexprint(req + chunk) + LOG.debug(util.hexprint(req + chunk)) cserr, ack = self._read_record() - if CHIRP_DEBUG: - print util.hexprint(ack) + LOG.debug(util.hexprint(ack)) j = ord(ack[0]) * 256 + ord(ack[1]) if cserr or j != ptr: raise Exception("Radio did not ack block %i" % ptr) @@ -537,9 +528,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, # always set it even if no dtcs is used mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N")
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.txtone, - rxmode, _mem.rxtone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.txtone, + rxmode, _mem.rxtone))
def get_memory(self, number): _mem = self._memobj.memory[number] @@ -549,8 +539,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, mem.number = number _valid = self._memobj.valid[mem.number]
- if CHIRP_DEBUG: - print number, _valid == MEM_VALID + LOG.debug("%d %s", number, _valid == MEM_VALID) if _valid != MEM_VALID: mem.empty = True return mem @@ -618,9 +607,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, else: _mem.rxtone = 0
- if CHIRP_DEBUG: - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.txtone, - rx_mode, _mem.rxtone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.txtone, + rx_mode, _mem.rxtone))
def set_memory(self, mem): number = mem.number diff --git a/chirp/kyd.py b/chirp/kyd.py index 2d4223d..e188df9 100644 --- a/chirp/kyd.py +++ b/chirp/kyd.py @@ -17,6 +17,7 @@ import time import os import struct +import logging
from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util @@ -24,7 +25,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettings
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0010; @@ -132,8 +133,7 @@ def _nc630a_read_block(radio, block_addr, block_size):
cmd = struct.pack(">cHb", 'R', block_addr, BLOCK_SIZE) expectedresponse = "W" + cmd[1:] - if DEBUG: - print("Reading block %04x..." % (block_addr)) + LOG.debug("Reading block %04x..." % (block_addr))
try: serial.write(cmd) @@ -159,9 +159,8 @@ def _nc630a_write_block(radio, block_addr, block_size): cmd = struct.pack(">cHb", 'W', block_addr, BLOCK_SIZE) data = radio.get_mmap()[block_addr:block_addr + 8]
- if DEBUG: - print("Writing Data:") - print util.hexprint(cmd + data) + LOG.debug("Writing Data:") + LOG.debug(util.hexprint(cmd + data))
try: serial.write(cmd + data) @@ -190,9 +189,8 @@ def do_download(radio): block = _nc630a_read_block(radio, addr, BLOCK_SIZE) data += block
- if DEBUG: - print "Address: %04x" % addr - print util.hexprint(block) + LOG.debug("Address: %04x" % addr) + LOG.debug(util.hexprint(block))
_nc630a_exit_programming_mode(radio)
@@ -301,9 +299,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): if mem.tmode == "DTCS": mem.dtcs_polarity = "%s%s" % (tpol, rpol)
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, - rxmode, _mem.rx_tone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, + rxmode, _mem.rx_tone))
def get_memory(self, number): bitpos = (1 << ((number - 1) % 8)) @@ -387,9 +384,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone))
def set_memory(self, mem): bitpos = (1 << ((mem.number - 1) % 8)) diff --git a/chirp/leixen.py b/chirp/leixen.py index 1977f0c..285fe84 100644 --- a/chirp/leixen.py +++ b/chirp/leixen.py @@ -24,11 +24,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x0184; struct { diff --git a/chirp/puxing.py b/chirp/puxing.py index 88cbe79..f38b41e 100644 --- a/chirp/puxing.py +++ b/chirp/puxing.py @@ -20,11 +20,6 @@ import os from chirp import util, chirp_common, bitwise, errors, directory from chirp.wouxun_common import wipe_memory, do_download, do_upload
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def _puxing_prep(radio): radio.pipe.write("\x02PROGRA") ack = radio.pipe.read(1) diff --git a/chirp/th9800.py b/chirp/th9800.py index 3edc310..d1a1b0b 100644 --- a/chirp/th9800.py +++ b/chirp/th9800.py @@ -24,12 +24,10 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from chirp_common import format_freq import os import time +import logging from datetime import date
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
TH9800_MEM_FORMAT = """ struct mem { @@ -323,8 +321,7 @@ class TYTTH9800Base(chirp_common.Radio): _prev_active = self.get_active("chan_active", mem.number) self.set_active("chan_active", mem.number, not mem.empty) if mem.empty or not _prev_active: - if CHIRP_DEBUG: - print "initializing memory channel %d" % mem.number + LOG.debug("initializing memory channel %d" % mem.number) _mem.set_raw(BLANK_MEMORY)
if mem.empty: @@ -390,8 +387,7 @@ class TYTTH9800Base(chirp_common.Radio): _mem.step = STEPS.index(mem.tuning_step)
for setting in mem.extra: - if CHIRP_DEBUG: - print "@set_mem:", setting.get_name(), setting.value + LOG.debug("@set_mem:", setting.get_name(), setting.value) setattr(_mem, setting.get_name(), setting.value)
def get_settings(self): @@ -559,9 +555,7 @@ class TYTTH9800Base(chirp_common.Radio): oldval = getattr(_settings, setting) newval = element.value
- if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() @@ -666,12 +660,12 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): m = today.month d = today.day _info = radio._memobj.info - if CHIRP_DEBUG: - ly = _info.prog_yr - lm = _info.prog_mon - ld = _info.prog_day - print "Updating last program date:%d/%d/%d" % (lm,ld,ly) - print " to today:%d/%d/%d" % (m,d,y) + + ly = _info.prog_yr + lm = _info.prog_mon + ld = _info.prog_day + LOG.debug("Updating last program date:%d/%d/%d" % (lm,ld,ly)) + LOG.debug(" to today:%d/%d/%d" % (m,d,y))
_info.prog_yr = y _info.prog_mon = m @@ -680,8 +674,7 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): offset = 0x0100 for addr in range(offset, memsize, blocksize): mapaddr = addr + radio._mmap_offset - offset - if CHIRP_DEBUG: - print "addr: 0x%04X, mmapaddr: 0x%04X" % (addr, mapaddr) + LOG.debug("addr: 0x%04X, mmapaddr: 0x%04X" % (addr, mapaddr)) msg = struct.pack(">cHB", "W", addr, blocksize) msg += radio._mmap[mapaddr:(mapaddr + blocksize)] print util.hexprint(msg) @@ -703,8 +696,7 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80):
# Checksum? final_data = radio.pipe.read(3) - if CHIRP_DEBUG: - print "final:", util.hexprint(final_data) + LOG.debug("final:", util.hexprint(final_data))
@directory.register class TYTTH9800Radio(TYTTH9800Base, chirp_common.CloneModeRadio, diff --git a/chirp/th_uv3r.py b/chirp/th_uv3r.py index 5e3e2c0..3b670fe 100644 --- a/chirp/th_uv3r.py +++ b/chirp/th_uv3r.py @@ -19,11 +19,6 @@ import os from chirp import chirp_common, bitwise, errors, directory from chirp.wouxun_common import do_download, do_upload
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def tyt_uv3r_prep(radio): try: radio.pipe.write("PROGRAMa") diff --git a/chirp/thd72.py b/chirp/thd72.py index 0d80adc..aa414de 100644 --- a/chirp/thd72.py +++ b/chirp/thd72.py @@ -15,9 +15,9 @@
from chirp import chirp_common, errors, util, directory from chirp import bitwise, memmap -import time, struct, sys +import time, struct, sys, logging
-DEBUG = True +LOG = logging.getLogger(__name__)
# TH-D72 memory map # 0x0000..0x0200: startup password and other stuff @@ -452,13 +452,11 @@ class THD72Radio(chirp_common.CloneModeRadio): start = time.time()
data = "" - if DEBUG: - print "PC->D72: %s" % cmd + LOG.debug("PC->D72: %s" % cmd) self.pipe.write(cmd + "\r") while not data.endswith("\r") and (time.time() - start) < timeout: data += self.pipe.read(1) - if DEBUG: - print "D72->PC: %s" % data.strip() + LOG.debug("D72->PC: %s" % data.strip()) return data.strip()
def get_id(self): diff --git a/chirp/tk8102.py b/chirp/tk8102.py index 32e8621..4cf291e 100644 --- a/chirp/tk8102.py +++ b/chirp/tk8102.py @@ -15,6 +15,7 @@
import struct import os +import logging
from chirp import chirp_common, directory, memmap, errors, util from chirp import bitwise @@ -22,6 +23,8 @@ from chirp.settings import RadioSettingGroup, RadioSetting from chirp.settings import RadioSettingValueBoolean, RadioSettingValueList from chirp.settings import RadioSettingValueString, RadioSettings
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x0030; struct { @@ -317,9 +320,8 @@ class KenwoodTKx102Radio(chirp_common.CloneModeRadio): else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone)) def set_memory(self, mem): _mem = self._memobj.memory[mem.number - 1]
diff --git a/chirp/tmv71_ll.py b/chirp/tmv71_ll.py index dac7f36..201412e 100644 --- a/chirp/tmv71_ll.py +++ b/chirp/tmv71_ll.py @@ -13,11 +13,11 @@ # 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 struct, time +import struct, time, logging
from chirp import memmap, chirp_common, errors
-DEBUG = True +LOG = logging.getLogger(__name__)
POS_MODE = 5 POS_DUP = 6 @@ -50,13 +50,11 @@ def command(s, cmd, timeout=0.5): start = time.time()
data = "" - if DEBUG: - print "PC->V71: %s" % cmd + LOG.debug("PC->V71: %s" % cmd) s.write(cmd + "\r") while not data.endswith("\r") and (time.time() - start) < timeout: data += s.read(1) - if DEBUG: - print "V71->PC: %s" % data.strip() + LOG.debug("V71->PC: %s" % data.strip()) return data.strip()
def get_id(s): diff --git a/chirp/uv5r.py b/chirp/uv5r.py index 6fcbae1..646d6e2 100644 --- a/chirp/uv5r.py +++ b/chirp/uv5r.py @@ -16,6 +16,7 @@ import struct import time import os +import logging
from chirp import chirp_common, errors, util, directory, memmap from chirp import bitwise @@ -25,10 +26,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0008; @@ -394,8 +392,7 @@ def _firmware_version_from_image(radio): version = _firmware_version_from_data(radio.get_mmap(), radio._fw_ver_file_start, radio._fw_ver_file_stop) - if CHIRP_DEBUG: - print "_firmware_version_from_image: " + util.hexprint(version) + LOG.debug("_firmware_version_from_image: " + util.hexprint(version)) return version
def _special_block_from_data(data, special_block_start, special_block_stop): @@ -404,8 +401,7 @@ def _special_block_from_data(data, special_block_start, special_block_stop):
def _special_block_from_image(radio): special_block = _special_block_from_data(radio.get_mmap(), 0x0CFA, 0x0D01) - if CHIRP_DEBUG: - print "_special_block_from_image: " + util.hexprint(special_block) + LOG.debug("_special_block_from_image: " + util.hexprint(special_block)) return special_block
def _do_ident(radio, magic): @@ -504,19 +500,16 @@ def _do_download(radio): raise errors.RadioError("Incorrect 'Model' selected.")
# Main block - if CHIRP_DEBUG: - print "downloading main block..." + LOG.debug("downloading main block...") for i in range(0, 0x1800, 0x40): data += _read_block(radio, i, 0x40) _do_status(radio, i) - if CHIRP_DEBUG: - print "done." - print "downloading aux block..." + LOG.debug("done.") + LOG.debug("downloading aux block...") # Auxiliary block starts at 0x1ECO (?) for i in range(0x1EC0, 0x2000, 0x40): data += _read_block(radio, i, 0x40) - if CHIRP_DEBUG: - print "done." + LOG.debug("done.") return memmap.MemoryMap(data)
def _send_block(radio, addr, data): @@ -916,8 +909,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio,
def _is_orig(self): version_tag = _firmware_version_from_image(self) - if CHIRP_DEBUG: - print "@_is_orig, version_tag:", util.hexprint(version_tag) + LOG.debug("@_is_orig, version_tag: %s", util.hexprint(version_tag)) try: if 'BFB' in version_tag: idx = version_tag.index("BFB") + 3 diff --git a/chirp/vx170.py b/chirp/vx170.py index 20aac04..eaa7dbc 100644 --- a/chirp/vx170.py +++ b/chirp/vx170.py @@ -19,11 +19,6 @@ from textwrap import dedent import time, os from chirp import ft7800
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x018A; struct { diff --git a/chirp/vx2.py b/chirp/vx2.py index 3156806..6c6b912 100644 --- a/chirp/vx2.py +++ b/chirp/vx2.py @@ -19,12 +19,9 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import os, traceback, re +import os, traceback, re, logging
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x7F52; @@ -410,9 +407,8 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): return VX2BankModel(self)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -421,9 +417,8 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(0, length): @@ -648,8 +643,7 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): for c in dtmfsetting.digits: if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -676,8 +670,7 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-1:]) - 1 _settings = self._memobj.dtmf[idx] _settings.digits = newval @@ -698,12 +691,10 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): newval = self._encode_chars(newval) if setting == "openmsg": newval = self._encode_chars(newval, 6) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() raise
- \ No newline at end of file + diff --git a/chirp/vx3.py b/chirp/vx3.py index 99d0951..0575a46 100644 --- a/chirp/vx3.py +++ b/chirp/vx3.py @@ -21,7 +21,9 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings from textwrap import dedent -import os, re +import os, re, logging + +LOG = logging.getLogger(__name__)
#interesting offsets which may be checksums needed later #0x0393 checksum1? @@ -29,11 +31,6 @@ import os, re #0x0409 checksum2? #0x04C9 checksum2a?
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x7F4A; u8 checksum; @@ -499,9 +496,8 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): return VX3BankModel(self)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -510,9 +506,8 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(length): @@ -785,8 +780,7 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): for c in dtmfsetting.memory: if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -861,8 +855,7 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-1:]) _settings = self._memobj.dtmf[idx] _settings.memory = newval @@ -885,11 +878,9 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): newval = self._encode_chars(newval) if setting == "openmsg": newval = self._encode_chars(newval, 6) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() raise - \ No newline at end of file + diff --git a/chirp/vx8.py b/chirp/vx8.py index 02490a1..45fff7a 100644 --- a/chirp/vx8.py +++ b/chirp/vx8.py @@ -15,6 +15,7 @@
import os import re +import logging
from chirp import chirp_common, yaesu_clone, directory from chirp import bitwise @@ -23,6 +24,8 @@ from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean from textwrap import dedent
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x047f; struct { @@ -1461,8 +1464,7 @@ class VX8DRadio(VX8Radio): is_latitude = name.endswith("latitude") lat_long = setting.value.get_value().strip() sign, l_d, l_m, l_s = cls._str_to_latlong(lat_long, is_latitude) - if os.getenv("CHIRP_DEBUG"): - print "%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s) + LOG.debug("%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s)) setattr(obj, "%s_sign" % name, sign) setattr(obj, "%s_degree" % name, l_d) setattr(obj, "%s_minute" % name, l_m) @@ -1499,9 +1501,8 @@ class VX8DRadio(VX8Radio):
try: old_val = getattr(obj, setting) - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%r) <= %s" % ( - element.get_name(), old_val, element.value) + LOG.debug("Setting %s(%r) <= %s" % ( + element.get_name(), old_val, element.value)) setattr(obj, setting, element.value) except AttributeError as e: print "Setting %s is not in the memory map: %s" % ( diff --git a/chirp/wouxun.py b/chirp/wouxun.py index 6feec42..4a3dd0b 100644 --- a/chirp/wouxun.py +++ b/chirp/wouxun.py @@ -17,6 +17,7 @@
import time import os +import logging from chirp import util, chirp_common, bitwise, memmap, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ @@ -25,6 +26,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from chirp.wouxun_common import wipe_memory, do_download, do_upload from textwrap import dedent
+LOG = logging.getLogger(__name__) + FREQ_ENCODE_TABLE = [ 0x7, 0xa, 0x0, 0x9, 0xb, 0x2, 0xe, 0x1, 0x3, 0xf ]
def encode_freq(freq): @@ -717,9 +720,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, # always set it even if no dtcs is used mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N")
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, - rxmode, _mem.rx_tone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, + rxmode, _mem.rx_tone))
def _is_txinh(self, _mem): raw_tx = "" @@ -817,9 +819,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone))
def set_memory(self, mem): _mem = self._memobj.memory[mem.number - 1] diff --git a/chirp/wouxun_common.py b/chirp/wouxun_common.py index 3c78b3a..5b51e93 100644 --- a/chirp/wouxun_common.py +++ b/chirp/wouxun_common.py @@ -18,8 +18,11 @@
import struct import os +import logging from chirp import util, chirp_common, memmap
+LOG = logging.getLogger(__name__) + def wipe_memory(_mem, byte): """Cleanup a memory""" _mem.set_raw(byte * (_mem.size() / 8)) @@ -29,8 +32,7 @@ def do_download(radio, start, end, blocksize): image = "" for i in range(start, end, blocksize): cmd = struct.pack(">cHb", "R", i, blocksize) - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(cmd) + LOG.debug(util.hexprint(cmd)) radio.pipe.write(cmd) length = len(cmd) + blocksize resp = radio.pipe.read(length) @@ -61,8 +63,7 @@ def do_upload(radio, start, end, blocksize): chunk = radio.get_mmap()[ptr:ptr+blocksize] ptr += blocksize radio.pipe.write(cmd + chunk) - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(cmd + chunk) + LOG.debug(util.hexprint(cmd + chunk))
ack = radio.pipe.read(1) if not ack == "\x06": diff --git a/chirp/yaesu_clone.py b/chirp/yaesu_clone.py index 57958c3..e8ec732 100644 --- a/chirp/yaesu_clone.py +++ b/chirp/yaesu_clone.py @@ -16,9 +16,11 @@ CMD_ACK = 0x06
from chirp import chirp_common, util, memmap, errors -import time, os +import time, os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + def _safe_read(pipe, count): buf = "" first = True @@ -49,8 +51,7 @@ def _chunk_read(pipe, count, status_fn): status.max = count status.cur = len(data) status_fn(status) - if os.getenv("CHIRP_DEBUG"): - print "Read %i/%i" % (len(data), count) + LOG.debug("Read %i/%i" % (len(data), count)) return data
def __clone_in(radio): @@ -91,8 +92,7 @@ def _chunk_write(pipe, data, status_fn, block): chunk = data[i:i+block] pipe.write(chunk) count += len(chunk) - if os.getenv("CHIRP_DEBUG"): - print "@_chunk_write, count: %i, blocksize: %i" % (count,block) + LOG.debug("@_chunk_write, count: %i, blocksize: %i" % (count,block)) time.sleep(delay)
status = chirp_common.Status() @@ -120,8 +120,7 @@ def __clone_out(radio): for block in radio._block_lengths: blocks += 1 if blocks != len(radio._block_lengths): - if os.getenv("CHIRP_DEBUG"): - print "Sending %i-%i" % (pos, pos+block) + LOG.debug("Sending %i-%i" % (pos, pos+block)) pipe.write(radio.get_mmap()[pos:pos+block]) buf = pipe.read(1) if buf and buf[0] != chr(CMD_ACK): diff --git a/chirpui/reporting.py b/chirpui/reporting.py index c48c6bb..efe18c1 100644 --- a/chirpui/reporting.py +++ b/chirpui/reporting.py @@ -28,16 +28,18 @@ import threading import os import time +import logging
from chirp import CHIRP_VERSION, platform
REPORT_URL = "http://chirp.danplanet.com/report/report.php?do_report" ENABLED = True -DEBUG = os.getenv("CHIRP_DEBUG") == "y" THREAD_SEM = threading.Semaphore(10) # Maximum number of outstanding threads LAST = 0 LAST_TYPE = None
+LOG = logging.getLogger(__name__) + try: # Don't let failure to import any of these modules cause trouble from chirpui import config @@ -45,18 +47,14 @@ try: except: ENABLED = False
-def debug(string): - if DEBUG: - print string - def should_report(): if not ENABLED: - debug("Not reporting due to recent failure") + LOG.debug("Not reporting due to recent failure") return False
conf = config.get() if conf.get_bool("no_report"): - debug("Reporting disabled") + LOG.debug("Reporting disabled") return False
return True @@ -70,7 +68,7 @@ def _report_model_usage(model, direction, success): model = "%s_%s" % (model.VENDOR, model.MODEL) data = "%s,%s,%s" % (model, direction, success)
- debug("Reporting model usage: %s" % data) + LOG.debug("Reporting model usage: %s" % data)
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_stats(CHIRP_VERSION, @@ -84,7 +82,7 @@ def _report_model_usage(model, direction, success): def _report_exception(stack): global ENABLED
- debug("Reporting exception") + LOG.debug("Reporting exception")
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_exception(CHIRP_VERSION, @@ -98,7 +96,7 @@ def _report_exception(stack): def _report_misc_error(module, data): global ENABLED
- debug("Reporting misc error with %s" % module) + LOG.debug("Reporting misc error with %s" % module)
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_misc_error(CHIRP_VERSION, @@ -109,12 +107,12 @@ def _report_misc_error(module, data): return id != 0
def _check_for_updates(callback): - debug("Checking for updates") + LOG.debug("Checking for updates") proxy = xmlrpclib.ServerProxy(REPORT_URL) ver = proxy.check_for_updates(CHIRP_VERSION, platform.get_platform().os_version_string())
- debug("Server reports version %s is latest" % ver) + LOG.debug("Server reports version %s is latest" % ver) callback(ver) return True
@@ -128,7 +126,7 @@ class ReportThread(threading.Thread): try: return self.__func(*self.__args) except Exception, e: - debug("Failed to report: %s" % e) + LOG.debug("Failed to report: %s" % e) return False
def run(self): @@ -139,7 +137,7 @@ class ReportThread(threading.Thread): ENABLED = False elif (time.time() - start) > 15: # Reporting took too long - debug("Time to report was %.2f sec -- Disabling" % \ + LOG.debug("Time to report was %.2f sec -- Disabling" % \ (time.time()-start)) ENABLED = False
@@ -151,13 +149,13 @@ def dispatch_thread(func, *args):
# If reporting is disabled or failing, bail if not should_report(): - debug("Reporting is disabled") + LOG.debug("Reporting is disabled") return
# If the time between now and the last report is less than 5 seconds, bail delta = time.time() - LAST if delta < 5 and func == LAST_TYPE: - debug("Throttling...") + LOG.debug("Throttling...") return
LAST = time.time() @@ -165,7 +163,7 @@ def dispatch_thread(func, *args):
# If there are already too many threads running, bail if not THREAD_SEM.acquire(False): - debug("Too many threads already running") + LOG.debug("Too many threads already running") return
t = ReportThread(func, *args)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Suppress startup debugging messages (#2347)
This patch changes the verbose startup messages to use LOG.info calls. This change is required to make the CLI remotely usable, as it's unreasonable to print so much information in that context.
I kept this separate from the last patch, because I can imagine that this might impact the automated/buildbot testing. To avoid regressions, the previous output can be generated by setting 'CHIRP_DEBUG=info' in the environment.
diff --git a/chirp/directory.py b/chirp/directory.py index 5fc47e3..07308ee 100644 --- a/chirp/directory.py +++ b/chirp/directory.py @@ -16,10 +16,13 @@
import os import tempfile +import logging
from chirp import icf from chirp import chirp_common, util, rfinder, radioreference, errors
+LOG = logging.getLogger(__name__) + def radio_class_id(cls): """Return a unique identification string for @cls""" ident = "%s_%s" % (cls.VENDOR, cls.MODEL) @@ -47,12 +50,12 @@ def register(cls): ident = radio_class_id(cls) if ident in DRV_TO_RADIO.keys(): if ALLOW_DUPS: - print "Replacing existing driver id `%s'" % ident + LOG.warn("Replacing existing driver id `%s'" % ident) else: raise Exception("Duplicate radio driver id `%s'" % ident) DRV_TO_RADIO[ident] = cls RADIO_TO_DRV[cls] = ident - print "Registered %s = %s" % (ident, cls.__name__) + LOG.info("Registered %s = %s" % (ident, cls.__name__))
return cls
diff --git a/chirpui/mainapp.py b/chirpui/mainapp.py index 79f6815..2d8e3e1 100644 --- a/chirpui/mainapp.py +++ b/chirpui/mainapp.py @@ -21,11 +21,14 @@ import webbrowser from glob import glob import shutil import time +import logging
import gtk import gobject gobject.threads_init()
+LOG = logging.getLogger(__name__) + if __name__ == "__main__": import sys sys.path.insert(0, "..") @@ -526,7 +529,7 @@ If you think that it is valid, you can select a radio model below to force an op files = glob(os.path.join(basepath, "*.csv")) for fn in files: if os.path.exists(os.path.join(stock_dir, os.path.basename(fn))): - print "Skipping existing stock config" + LOG.info("Skipping existing stock config") continue try: shutil.copy(fn, stock_dir)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Fix style issues (#2355)
This patch contains whitespace-only changes that eliminate all of the PEP8 style warnings in the CLI and GUI scripts.
diff --git a/chirpc b/chirpc index dc55de3..1a5ffdd 100755 --- a/chirpc +++ b/chirpc @@ -26,16 +26,18 @@ from chirp import * from chirp import chirp_common, errors, idrp, directory, util
LOG = logging.getLogger("chirpc") +RADIOS = directory.DRV_TO_RADIO +
def fail_unsupported(): print "Operation not supported by selected radio" sys.exit(1)
+ def fail_missing_mmap(): print "mmap-only operation requires specification of an mmap file" sys.exit(1)
-RADIOS = directory.DRV_TO_RADIO
class ToneAction(argparse.Action): # def __init__(self, **kwargs): @@ -46,6 +48,7 @@ class ToneAction(argparse.Action): raise argparse.ArgumentError("Invalid tone valeu: %.1f" % value) setattr(namespace, self.dest, value)
+ class DTCSAction(argparse.Action): def __call__(self, parser, namespace, value, option_string=None): try: @@ -57,6 +60,7 @@ class DTCSAction(argparse.Action): raise argparse.ArgumentError("Invalid DTCS value: %03i" % value) setattr(namespace, self.dest, value)
+ class DTCSPolarityAction(argparse.Action): def __call__(self, parser, namespace, value, option_string=None): if value not in ["NN", "RN", "NR", "RR"]: @@ -65,251 +69,244 @@ class DTCSPolarityAction(argparse.Action):
if __name__ == "__main__": - parser = argparse.ArgumentParser() - version.add_argument(parser) - parser.add_argument("-s", "--serial", dest="serial", - default="mmap", - help="Serial port (default: mmap)") - - parser.add_argument("-i", "--id", dest="id", - default=False, - action="store_true", - help="Request radio ID string") - parser.add_argument("--raw", dest="raw", - default=False, - action="store_true", - help="Dump raw memory location") - - parser.add_argument("--get-mem", dest="get_mem", - default=False, - action="store_true", - help="Get and print memory location") - parser.add_argument("--set-mem-name", dest="set_mem_name", - default=None, - help="Set memory name") - parser.add_argument("--set-mem-freq", dest="set_mem_freq", - type=float, - default=None, - help="Set memory frequency") - - parser.add_argument("--set-mem-tencon", dest="set_mem_tencon", - default=False, - action="store_true", - help="Set tone encode enabled flag") - parser.add_argument("--set-mem-tencoff", dest="set_mem_tencoff", - default=False, - action="store_true", - help="Set tone decode disabled flag") - parser.add_argument("--set-mem-tsqlon", dest="set_mem_tsqlon", - default=False, - action="store_true", - help="Set tone squelch enabled flag") - parser.add_argument("--set-mem-tsqloff", dest="set_mem_tsqloff", - default=False, - action="store_true", - help="Set tone squelch disabled flag") - parser.add_argument("--set-mem-dtcson", dest="set_mem_dtcson", - default=False, - action="store_true", - help="Set DTCS enabled flag") - parser.add_argument("--set-mem-dtcsoff", dest="set_mem_dtcsoff", - default=False, - action="store_true", - help="Set DTCS disabled flag") - - parser.add_argument("--set-mem-tenc", dest="set_mem_tenc", - type=float, action=ToneAction, nargs=1, - help="Set memory encode tone") - parser.add_argument("--set-mem-tsql", dest="set_mem_tsql", - type=float, action=ToneAction, nargs=1, - help="Set memory squelch tone") - - parser.add_argument("--set-mem-dtcs", dest="set_mem_dtcs", - type=int, action=DTCSAction, nargs=1, - help="Set memory DTCS code") - parser.add_argument("--set-mem-dtcspol", dest="set_mem_dtcspol", - action=DTCSPolarityAction, nargs=1, - help="Set memory DTCS polarity (NN, NR, RN, RR)") - - parser.add_argument("--set-mem-dup", dest="set_mem_dup", - help="Set memory duplex (+,-, or blank)") - parser.add_argument("--set-mem-offset", dest="set_mem_offset", - type=float, - help="Set memory duplex offset (in MHz)") - - parser.add_argument("--set-mem-mode", dest="set_mem_mode", - default=None, - help="Set mode (%s)" % ",".join(chirp_common.MODES)) - parser.add_argument("-r", "--radio", dest="radio", - default=None, - help="Radio model (see --list-radios)") - parser.add_argument("--list-radios", action="store_true", - help="List radio models") - parser.add_argument("--mmap", dest="mmap", - default=None, - help="Radio memory map file location") - parser.add_argument("--download-mmap", dest="download_mmap", - action="store_true", - default=False, - help="Download memory map from radio") - parser.add_argument("--upload-mmap", dest="upload_mmap", - action="store_true", - default=False, - help="Upload memory map to radio") - logger.add_arguments(parser) - parser.add_argument("args", metavar="arg", nargs='*', - help="Some commands require additional arguments") - - if len(sys.argv) <= 1: - parser.print_help() - sys.exit(0) - - options = parser.parse_args() - args = options.args - - logger.handle_options(options) - - if options.list_radios: - print "Supported Radios:\n\t", "\n\t".join(sorted(RADIOS.keys())) - sys.exit(0) - - if options.id: - from chirp import icf - - s = serial.Serial(port=options.serial, - baudrate=9600, - timeout=0.5) - - md = icf.get_model_data(s) - - print "Model:\n%s" % util.hexprint(md) - - sys.exit(0) - - if not options.radio: - if options.mmap: - rclass = directory.get_radio_by_image(options.mmap).__class__ - else: - LOG.critical("You must specify a radio model.") - sys.exit(1) - else: - rclass = directory.get_radio(options.radio) - - if options.serial == "mmap": - if options.mmap: - s = options.mmap - else: - s = options.radio + ".img" - else: - print "opening %s at %i" % (options.serial, rclass.BAUD_RATE) - s = serial.Serial(port=options.serial, - baudrate=rclass.BAUD_RATE, - timeout=0.5) - - radio = rclass(s) - - if options.raw: - data = radio.get_raw_memory(int(args[0])) - for i in data: - if ord(i) > 0x7F: - print "Memory location %i (%i):\n%s" % (int(args[0]), - len(data), - util.hexprint(data)) - sys.exit(0) - print data - sys.exit(0) - - if options.set_mem_dup is not None: - if options.set_mem_dup != "+" and \ - options.set_mem_dup != "-" and \ - options.set_mem_dup != "": - print "Invalid duplex value `%s'" % options.set_mem_dup - print "Valid values are: '+', '-', ''" - sys.exit(1) - else: - _dup = options.set_mem_dup - else: - _dup = None - - if options.set_mem_mode: - print "Set mode: %s" % options.set_mem_mode - if options.set_mem_mode not in chirp_common.MODES: - print "Invalid mode `%s'" - sys.exit(1) - else: - _mode = options.set_mem_mode - else: - _mode = None - - if options.set_mem_name or options.set_mem_freq or \ - options.set_mem_tencon or options.set_mem_tencoff or \ - options.set_mem_tsqlon or options.set_mem_tsqloff or \ - options.set_mem_dtcson or options.set_mem_dtcsoff or \ - options.set_mem_tenc or options.set_mem_tsql or options.set_mem_dtcs or\ - options.set_mem_dup is not None or \ - options.set_mem_mode or options.set_mem_dtcspol or\ - options.set_mem_offset: - try: - mem = radio.get_memory(int(args[0])) - except errors.InvalidMemoryLocation: - mem = chirp_common.Memory() - mem.number = int(args[0]) - - mem.name = options.set_mem_name or mem.name - mem.freq = options.set_mem_freq or mem.freq - mem.rtone = options.set_mem_tenc or mem.rtone - mem.ctone = options.set_mem_tsql or mem.ctone - mem.dtcs = options.set_mem_dtcs or mem.dtcs - mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity - if _dup is not None: - mem.duplex = _dup - mem.offset = options.set_mem_offset or mem.offset - mem.mode = _mode or mem.mode - - if options.set_mem_tencon: - mem.tencEnabled = True - elif options.set_mem_tencoff: - mem.tencEnabled = False - - if options.set_mem_tsqlon: - mem.tsqlEnabled = True - elif options.set_mem_tsqloff: - mem.tsqlEnabled = False - - if options.set_mem_dtcson: - mem.dtcsEnabled = True - elif options.set_mem_dtcsoff: - mem.dtcsEnabled = False - - radio.set_memory(mem) - - if options.get_mem: - try: - pos = int(args[0]) - except ValueError: - pos = args[0] - - try: - mem = radio.get_memory(pos) - except errors.InvalidMemoryLocation, e: - mem = chirp_common.Memory() - mem.number = pos - - print mem - - if options.download_mmap: - #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() - radio.sync_in() - radio.save_mmap(options.mmap) - - if options.upload_mmap: - #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() - radio.load_mmap(options.mmap) - if radio.sync_out(): - print "Clone successful" - else: - print "Clone failed" - - if options.mmap and isinstance(radio, chirp_common.CloneModeRadio): - radio.save_mmap(options.mmap) - + parser = argparse.ArgumentParser() + version.add_argument(parser) + parser.add_argument("-s", "--serial", dest="serial", + default="mmap", + help="Serial port (default: mmap)") + + parser.add_argument("-i", "--id", dest="id", + default=False, + action="store_true", + help="Request radio ID string") + parser.add_argument("--raw", dest="raw", + default=False, + action="store_true", + help="Dump raw memory location") + + parser.add_argument("--get-mem", dest="get_mem", + default=False, + action="store_true", + help="Get and print memory location") + parser.add_argument("--set-mem-name", dest="set_mem_name", + default=None, + help="Set memory name") + parser.add_argument("--set-mem-freq", dest="set_mem_freq", + type=float, + default=None, + help="Set memory frequency") + + parser.add_argument("--set-mem-tencon", dest="set_mem_tencon", + default=False, + action="store_true", + help="Set tone encode enabled flag") + parser.add_argument("--set-mem-tencoff", dest="set_mem_tencoff", + default=False, + action="store_true", + help="Set tone decode disabled flag") + parser.add_argument("--set-mem-tsqlon", dest="set_mem_tsqlon", + default=False, + action="store_true", + help="Set tone squelch enabled flag") + parser.add_argument("--set-mem-tsqloff", dest="set_mem_tsqloff", + default=False, + action="store_true", + help="Set tone squelch disabled flag") + parser.add_argument("--set-mem-dtcson", dest="set_mem_dtcson", + default=False, + action="store_true", + help="Set DTCS enabled flag") + parser.add_argument("--set-mem-dtcsoff", dest="set_mem_dtcsoff", + default=False, + action="store_true", + help="Set DTCS disabled flag") + + parser.add_argument("--set-mem-tenc", dest="set_mem_tenc", + type=float, action=ToneAction, nargs=1, + help="Set memory encode tone") + parser.add_argument("--set-mem-tsql", dest="set_mem_tsql", + type=float, action=ToneAction, nargs=1, + help="Set memory squelch tone") + + parser.add_argument("--set-mem-dtcs", dest="set_mem_dtcs", + type=int, action=DTCSAction, nargs=1, + help="Set memory DTCS code") + parser.add_argument("--set-mem-dtcspol", dest="set_mem_dtcspol", + action=DTCSPolarityAction, nargs=1, + help="Set memory DTCS polarity (NN, NR, RN, RR)") + + parser.add_argument("--set-mem-dup", dest="set_mem_dup", + help="Set memory duplex (+,-, or blank)") + parser.add_argument("--set-mem-offset", dest="set_mem_offset", + type=float, + help="Set memory duplex offset (in MHz)") + + parser.add_argument("--set-mem-mode", dest="set_mem_mode", + default=None, + help="Set mode (%s)" % ",".join(chirp_common.MODES)) + parser.add_argument("-r", "--radio", dest="radio", + default=None, + help="Radio model (see --list-radios)") + parser.add_argument("--list-radios", action="store_true", + help="List radio models") + parser.add_argument("--mmap", dest="mmap", + default=None, + help="Radio memory map file location") + parser.add_argument("--download-mmap", dest="download_mmap", + action="store_true", + default=False, + help="Download memory map from radio") + parser.add_argument("--upload-mmap", dest="upload_mmap", + action="store_true", + default=False, + help="Upload memory map to radio") + logger.add_arguments(parser) + parser.add_argument("args", metavar="arg", nargs='*', + help="Some commands require additional arguments") + + if len(sys.argv) <= 1: + parser.print_help() + sys.exit(0) + + options = parser.parse_args() + args = options.args + + logger.handle_options(options) + + if options.list_radios: + print "Supported Radios:\n\t", "\n\t".join(sorted(RADIOS.keys())) + sys.exit(0) + + if options.id: + from chirp import icf + s = serial.Serial(port=options.serial, baudrate=9600, timeout=0.5) + md = icf.get_model_data(s) + print "Model:\n%s" % util.hexprint(md) + sys.exit(0) + + if not options.radio: + if options.mmap: + rclass = directory.get_radio_by_image(options.mmap).__class__ + else: + LOG.critical("You must specify a radio model.") + sys.exit(1) + else: + rclass = directory.get_radio(options.radio) + + if options.serial == "mmap": + if options.mmap: + s = options.mmap + else: + s = options.radio + ".img" + else: + print "opening %s at %i" % (options.serial, rclass.BAUD_RATE) + s = serial.Serial(port=options.serial, + baudrate=rclass.BAUD_RATE, + timeout=0.5) + + radio = rclass(s) + + if options.raw: + data = radio.get_raw_memory(int(args[0])) + for i in data: + if ord(i) > 0x7F: + print "Memory location %i (%i):\n%s" % (int(args[0]), + len(data), + util.hexprint(data)) + sys.exit(0) + print data + sys.exit(0) + + if options.set_mem_dup is not None: + if options.set_mem_dup != "+" and \ + options.set_mem_dup != "-" and \ + options.set_mem_dup != "": + print "Invalid duplex value `%s'" % options.set_mem_dup + print "Valid values are: '+', '-', ''" + sys.exit(1) + else: + _dup = options.set_mem_dup + else: + _dup = None + + if options.set_mem_mode: + print "Set mode: %s" % options.set_mem_mode + if options.set_mem_mode not in chirp_common.MODES: + print "Invalid mode `%s'" + sys.exit(1) + else: + _mode = options.set_mem_mode + else: + _mode = None + + if options.set_mem_name or options.set_mem_freq or \ + options.set_mem_tencon or options.set_mem_tencoff or \ + options.set_mem_tsqlon or options.set_mem_tsqloff or \ + options.set_mem_dtcson or options.set_mem_dtcsoff or \ + options.set_mem_tenc or options.set_mem_tsql or \ + options.set_mem_dtcs or options.set_mem_dup is not None or \ + options.set_mem_mode or options.set_mem_dtcspol or\ + options.set_mem_offset: + try: + mem = radio.get_memory(int(args[0])) + except errors.InvalidMemoryLocation: + mem = chirp_common.Memory() + mem.number = int(args[0]) + + mem.name = options.set_mem_name or mem.name + mem.freq = options.set_mem_freq or mem.freq + mem.rtone = options.set_mem_tenc or mem.rtone + mem.ctone = options.set_mem_tsql or mem.ctone + mem.dtcs = options.set_mem_dtcs or mem.dtcs + mem.dtcs_polarity = options.set_mem_dtcspol or mem.dtcs_polarity + if _dup is not None: + mem.duplex = _dup + mem.offset = options.set_mem_offset or mem.offset + mem.mode = _mode or mem.mode + + if options.set_mem_tencon: + mem.tencEnabled = True + elif options.set_mem_tencoff: + mem.tencEnabled = False + + if options.set_mem_tsqlon: + mem.tsqlEnabled = True + elif options.set_mem_tsqloff: + mem.tsqlEnabled = False + + if options.set_mem_dtcson: + mem.dtcsEnabled = True + elif options.set_mem_dtcsoff: + mem.dtcsEnabled = False + + radio.set_memory(mem) + + if options.get_mem: + try: + pos = int(args[0]) + except ValueError: + pos = args[0] + + try: + mem = radio.get_memory(pos) + except errors.InvalidMemoryLocation, e: + mem = chirp_common.Memory() + mem.number = pos + + print mem + + if options.download_mmap: + #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() + radio.sync_in() + radio.save_mmap(options.mmap) + + if options.upload_mmap: + #isinstance(radio, chirp_common.IcomMmapRadio) or fail_unsupported() + radio.load_mmap(options.mmap) + if radio.sync_out(): + print "Clone successful" + else: + print "Clone failed" + + if options.mmap and isinstance(radio, chirp_common.CloneModeRadio): + radio.save_mmap(options.mmap) diff --git a/chirpw b/chirpw index c1fd0ea..26d2369 100755 --- a/chirpw +++ b/chirpw @@ -49,16 +49,16 @@ conf = config.get() manual_language = conf.get("language", "state") langs = [] if manual_language and manual_language != "Auto": - lang_codes = { "English" : "en_US", - "Polish" : "pl", - "Italian" : "it", - "Dutch" : "nl", - "German" : "de", - "Hungarian" : "hu", - "Russian" : "ru", - "Portuguese (BR)" : "pt_BR", - "French" : "fr", - } + lang_codes = {"English": "en_US", + "Polish": "pl", + "Italian": "it", + "Dutch": "nl", + "German": "de", + "Hungarian": "hu", + "Russian": "ru", + "Portuguese (BR)": "pt_BR", + "French": "fr", + } try: print lang_codes[manual_language] langs = [lang_codes[manual_language]] @@ -67,7 +67,7 @@ if manual_language and manual_language != "Auto": else: lc, encoding = locale.getdefaultlocale() if (lc): - langs = [lc] + langs = [lc] try: langs += os.getenv("LANG").split(":") except: @@ -88,6 +88,7 @@ lang = gettext.translation("CHIRP", localepath, languages=langs,
import gtk
+ # Python <2.6 does not have str.format(), which chirp uses to make translation # strings nicer. So, instead of installing the gettext standard "_()" function, # we can install our own, which returns a string of the following class, @@ -96,21 +97,22 @@ import gtk class CompatStr(str): def format(self, **kwargs): base = lang.gettext(self) - for k,v in kwargs.items(): + for k, v in kwargs.items(): base = base.replace("{%s}" % k, str(v)) return base
pyver = sys.version.split()[0]
-try : +try: vmaj, vmin, vrel = pyver.split(".", 3) -except : +except: vmaj, vmin = pyver.split(".", 2) vrel = 0
if int(vmaj) < 2 or int(vmin) < 6: # Python <2.6, emulate str.format() import __builtin__ + def lang_with_format(string): return CompatStr(string) __builtin__._ = lang_with_format @@ -140,7 +142,8 @@ for i in args.files: a.show()
if args.profile: - import cProfile, pstats + import cProfile + import pstats cProfile.run("gtk.main()", "chirpw.stats") p = pstats.Stats("chirpw.stats") p.sort_stats("cumulative").print_stats(10)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Add pep8 checker script (#2355)
This patch adds a new script that runs the pep8 tool on the CHIRP source code files. This script is intended to be included in the repository pre-commit hook, preventing future patches from causing any style-related regressions.
The script checks a blacklist of files that are not yet compliant with the style standards, allowing this check to be added almost immediately. Since no new files should ever be added to the blacklist, the blacklist should shrink to empty, and the script will check the entire codebase.
diff --git a/pep8.blacklist b/pep8.blacklist new file mode 100644 index 0000000..2e87a8f --- /dev/null +++ b/pep8.blacklist @@ -0,0 +1,142 @@ +# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant. +# Over time, this list should shrink and (eventually) be eliminated. +# The current list of files that do not yet meet PEP8 standards. +./chirp/alinco.py +./chirp/anytone.py +./chirp/ap510.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/bandplan.py +./chirp/baofeng_uv3r.py +./chirp/bitwise_grammar.py +./chirp/bitwise.py +./chirp/bjuv55.py +./chirp/chirp_common.py +./chirp/detect.py +./chirp/directory.py +./chirp/elib_intl.py +./chirp/errors.py +./chirp/ft1802.py +./chirp/ft1d.py +./chirp/ft2800.py +./chirp/ft50_ll.py +./chirp/ft50.py +./chirp/ft60.py +./chirp/ft7800.py +./chirp/ft817.py +./chirp/ft857.py +./chirp/ft90.py +./chirp/ftm350.py +./chirp/generic_csv.py +./chirp/generic_tpe.py +./chirp/generic_xml.py +./chirp/h777.py +./chirp/ic208.py +./chirp/ic2100.py +./chirp/ic2200.py +./chirp/ic2720.py +./chirp/ic2820.py +./chirp/ic9x_icf_ll.py +./chirp/ic9x_icf.py +./chirp/ic9x_ll.py +./chirp/ic9x.py +./chirp/icf.py +./chirp/icomciv.py +./chirp/icq7.py +./chirp/ict70.py +./chirp/ict7h.py +./chirp/ict8.py +./chirp/icw32.py +./chirp/icx8x_ll.py +./chirp/icx8x.py +./chirp/id31.py +./chirp/id51.py +./chirp/id800.py +./chirp/id880.py +./chirp/idrp.py +./chirp/import_logic.py +./chirp/__init__.py +./chirp/kenwood_hmk.py +./chirp/kenwood_itm.py +./chirp/kenwood_live.py +./chirp/kguv8d.py +./chirp/kyd.py +./chirp/leixen.py +./chirp/memmap.py +./chirp/platform.py +./chirp/puxing.py +./chirp/pyPEG.py +./chirp/radioreference.py +./chirp/rfinder.py +./chirp/settings.py +./chirp/template.py +./chirp/th9800.py +./chirp/thd72.py +./chirp/thuv1f.py +./chirp/th_uv3r25.py +./chirp/th_uv3r.py +./chirp/th_uvf8d.py +./chirp/tk8102.py +./chirp/tmv71_ll.py +./chirp/tmv71.py +./chirpui/bandplans.py +./chirpui/bankedit.py +./chirpui/cloneprog.py +./chirpui/clone.py +./chirpui/common.py +./chirpui/config.py +./chirpui/dstaredit.py +./chirpui/editorset.py +./chirpui/fips.py +./chirpui/importdialog.py +./chirpui/__init__.py +./chirpui/inputdialog.py +./chirpui/mainapp.py +./chirpui/memdetail.py +./chirpui/memedit.py +./chirpui/miscwidgets.py +./chirpui/radiobrowser.py +./chirpui/reporting.py +./chirpui/settingsedit.py +./chirpui/shiftdialog.py +./chirp/util.py +./chirp/uv5r.py +./chirp/uvb5.py +./chirp/vx170.py +./chirp/vx2.py +./chirp/vx3.py +./chirp/vx510.py +./chirp/vx5.py +./chirp/vx6.py +./chirp/vx7.py +./chirp/vx8.py +./chirp/vxa700.py +./chirp/wouxun_common.py +./chirp/wouxun.py +./chirp/xml_ll.py +./chirp/yaesu_clone.py +./csvdump/csvapp.py +./csvdump/csvdump.py +./csvdump/__init__.py +./csvdump.py +./locale/check_parameters.py +./rpttool +./setup.py +./share/make_supported.py +./tests/__init__.py +./tests/run_tests +./tests/unit/base.py +./tests/unit/__init__.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/img2thd72.py diff --git a/pep8.manifest b/pep8.manifest new file mode 100644 index 0000000..2fe9d77 --- /dev/null +++ b/pep8.manifest @@ -0,0 +1,4 @@ +./chirpc +./chirpw +./rpttool +./tests/run_tests diff --git a/pep8.py b/pep8.py new file mode 100755 index 0000000..5b9d99f --- /dev/null +++ b/pep8.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# pep8.py - Check Python source files for PEP8 compliance. +# +# Copyright 2015 Zachary T Welch zach@mandolincreekfarm.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# 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 os +import sys +import logging +import argparse +import subprocess +from chirp import logger + +LOG = logging.getLogger("pep8.py") + +parser = argparse.ArgumentParser() +parser.add_argument("-a", "--all", action="store_true", + help="Check all files, ignoring blacklist") +parser.add_argument("--stats", action="store_true", + help="Only show statistics") +parser.add_argument("files", metavar="file", nargs='*', + help="List of files to check (if none, check all)") +logger.add_arguments(parser) +args = parser.parse_args() +logger.handle_options(args) + + +def file_to_lines(name): + fh = file(name, "r") + lines = fh.read().split("\n") + lines.pop() + fh.close() + return lines + +# read manifest and search for python files +manifest = file_to_lines("pep8.manifest") +for root, dirs, files in os.walk("."): + for f in files: + if f.endswith('.py'): + manifest.append(os.path.join(root, f)) + +# read the blacklisted source files +blacklist = file_to_lines("pep8.blacklist") + +if args.files: + manifest = args.files + +for f in manifest: + if args.all or f not in blacklist: + LOG.info("checking %s", f) + cmdline = ['pep8', f] + if args.stats: + cmdline += ['-q', '--statistics'] + subprocess.call(cmdline)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Fix some style issues (#2355)
This patch fixes the style in a handful of files and removes them from pep8.blacklist.
diff --git a/chirp/bandplan.py b/chirp/bandplan.py index f2b8541..97f2425 100644 --- a/chirp/bandplan.py +++ b/chirp/bandplan.py @@ -15,6 +15,7 @@
from chirp import chirp_common
+ class Band(object): def __init__(self, limits, name, mode=None, step_khz=None, input_offset=None, output_offset=None, tones=None): @@ -79,6 +80,6 @@ class Band(object): self.step_khz and 'step_khz: %s ' % (self.step_khz,) or '', self.offset and 'offset: %s ' % (self.offset,) or '', self.tones and 'tones: %s ' % (self.tones,) or '') - + return "%s-%s %s %s %s" % ( self.limits[0], self.limits[1], self.name, self.duplex, desc) diff --git a/csvdump/__init__.py b/csvdump/__init__.py index 833c0c7..e418fca 100644 --- a/csvdump/__init__.py +++ b/csvdump/__init__.py @@ -14,4 +14,3 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. - diff --git a/locale/check_parameters.py b/locale/check_parameters.py index 431faec..f0f3d51 100755 --- a/locale/check_parameters.py +++ b/locale/check_parameters.py @@ -15,16 +15,17 @@ for name, po in pos.iteritems(): if len(entry.msgstr) > 0: try: ids = [field_name - for literal_text, field_name, format_spec, conversion - in formatter.parse(entry.msgid)] + for literal_text, field_name, format_spec, conversion + in formatter.parse(entry.msgid)] tids = [field_name - for literal_text, field_name, format_spec, conversion - in formatter.parse(entry.msgstr)] + for literal_text, field_name, format_spec, conversion + in formatter.parse(entry.msgstr)] except Exception as e: print "Got exception!", e, "for entry", entry.msgid else: - if tids != None: + if tids is not None: missing = [name for name in tids - if name is not None and name not in ids] + if name is not None and name not in ids] if len(missing) > 0: - print "Missing parameters", missing, "in translation of", entry.msgid + print "Missing parameters", missing, \ + "in translation of", entry.msgid diff --git a/pep8.blacklist b/pep8.blacklist index 2e87a8f..b55d94b 100644 --- a/pep8.blacklist +++ b/pep8.blacklist @@ -9,7 +9,6 @@ ./chirp/bandplan_iaru_r2.py ./chirp/bandplan_iaru_r3.py ./chirp/bandplan_na.py -./chirp/bandplan.py ./chirp/baofeng_uv3r.py ./chirp/bitwise_grammar.py ./chirp/bitwise.py @@ -120,9 +119,7 @@ ./chirp/yaesu_clone.py ./csvdump/csvapp.py ./csvdump/csvdump.py -./csvdump/__init__.py ./csvdump.py -./locale/check_parameters.py ./rpttool ./setup.py ./share/make_supported.py @@ -130,13 +127,8 @@ ./tests/run_tests ./tests/unit/base.py ./tests/unit/__init__.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/img2thd72.py diff --git a/tests/unit/base.py b/tests/unit/base.py index 47d16d4..ee6884c 100644 --- a/tests/unit/base.py +++ b/tests/unit/base.py @@ -4,6 +4,7 @@ import mox import warnings warnings.simplefilter('ignore', Warning)
+ class BaseTest(unittest.TestCase): def setUp(self): __builtins__['_'] = lambda s: s diff --git a/tests/unit/test_bitwise.py b/tests/unit/test_bitwise.py index 611836f..aabc7b3 100644 --- a/tests/unit/test_bitwise.py +++ b/tests/unit/test_bitwise.py @@ -18,6 +18,7 @@ import unittest from chirp import bitwise from chirp import memmap
+ class BaseTest(unittest.TestCase): def _compare_structure(self, obj, primitive): for key, value in primitive.iteritems(): @@ -26,6 +27,7 @@ class BaseTest(unittest.TestCase): else: self.assertEqual(type(value)(getattr(obj, key)), value)
+ class TestBitwiseBaseIntTypes(BaseTest): def _test_type(self, datatype, _data, value): data = memmap.MemoryMap(_data) @@ -78,6 +80,7 @@ class TestBitwiseBaseIntTypes(BaseTest): obj.foo[i] = i * 2 self.assertEqual('\x00\x02\x04\x06', data.get_packed())
+ class TestBitfieldTypes(BaseTest): def test_bitfield_u8(self): defn = "u8 foo:4, bar:4;" @@ -139,6 +142,7 @@ class TestBitfieldTypes(BaseTest): def test_bitfield_ul24(self): self._test_bitfield_24("l", "\xC2\x40\x00")
+ class TestBitType(BaseTest): def test_bit_array(self): defn = "bit foo[24];" @@ -153,6 +157,7 @@ class TestBitType(BaseTest): def test_bit_array_fail(self): self.assertRaises(ValueError, bitwise.parse, "bit foo[23];", "000")
+ class TestBitwiseBCDTypes(BaseTest): def _test_def(self, definition, name, _data, value): data = memmap.MemoryMap(_data) @@ -181,6 +186,7 @@ class TestBitwiseBCDTypes(BaseTest): def test_lbcd_array(self): self._test_def("lbcd foo[2];", "foo", "\x12\x34", 3412)
+ class TestBitwiseCharTypes(BaseTest): def test_char(self): data = memmap.MemoryMap("c") @@ -202,7 +208,6 @@ class TestBitwiseCharTypes(BaseTest): data = memmap.MemoryMap("\xFFoobar1") obj = bitwise.parse("struct {char foo[7];} bar;", data) self.assertIn('\xffoobar1', repr(obj.bar)) -
def test_string_wrong_length(self): data = memmap.MemoryMap("foobar") @@ -210,6 +215,7 @@ class TestBitwiseCharTypes(BaseTest): self.assertRaises(ValueError, setattr, obj, "foo", "bazfo") self.assertRaises(ValueError, setattr, obj, "foo", "bazfooo")
+ class TestBitwiseStructTypes(BaseTest): def _test_def(self, definition, data, primitive): obj = bitwise.parse(definition, data) @@ -218,12 +224,12 @@ class TestBitwiseStructTypes(BaseTest):
def test_struct_one_element(self): defn = "struct { u8 bar; } foo;" - value = {"foo" : {"bar": 128}} + value = {"foo": {"bar": 128}} self._test_def(defn, "\x80", value)
def test_struct_two_elements(self): defn = "struct { u8 bar; u16 baz; } foo;" - value = {"foo" : {"bar": 128, "baz": 256}} + value = {"foo": {"bar": 128, "baz": 256}} self._test_def(defn, "\x80\x01\x00", value)
def test_struct_writes(self): @@ -234,6 +240,7 @@ class TestBitwiseStructTypes(BaseTest): obj.foo.baz = 0x34 self.assertEqual(data.get_packed(), "\x12\x34")
+ class TestBitwiseSeek(BaseTest): def test_seekto(self): defn = "#seekto 4; char foo;" @@ -246,10 +253,12 @@ class TestBitwiseSeek(BaseTest): self.assertEqual(str(obj.foo), "A") self.assertEqual(str(obj.bar), "Z")
+ class TestBitwiseErrors(BaseTest): def test_missing_semicolon(self): self.assertRaises(SyntaxError, bitwise.parse, "u8 foo", "")
+ class TestBitwiseComments(BaseTest): def test_comment_inline_cppstyle(self): obj = bitwise.parse('u8 foo; // test', '\x10') diff --git a/tests/unit/test_chirp_common.py b/tests/unit/test_chirp_common.py index 1a75cbf..8393c40 100644 --- a/tests/unit/test_chirp_common.py +++ b/tests/unit/test_chirp_common.py @@ -2,6 +2,7 @@ from tests.unit import base from chirp import chirp_common from chirp import errors
+ class TestUtilityFunctions(base.BaseTest): def test_parse_freq_whole(self): self.assertEqual(chirp_common.parse_freq("146.520000"), 146520000) @@ -47,6 +48,7 @@ class TestUtilityFunctions(base.BaseTest): self.assertEqual(chirp_common.format_freq(1), "0.000001") self.assertEqual(chirp_common.format_freq(1250000000), "1250.000000")
+ class TestSplitTone(base.BaseTest): def _test_split_tone_decode(self, tx, rx, **vals): mem = chirp_common.Memory() @@ -184,6 +186,7 @@ class TestSplitTone(base.BaseTest): (('', None, None), ('Tone', 100.0, None)))
+ class TestStepFunctions(base.BaseTest): _625 = [145856250, 445856250, diff --git a/tests/unit/test_mappingmodel.py b/tests/unit/test_mappingmodel.py index 5a3c706..7ccbc86 100644 --- a/tests/unit/test_mappingmodel.py +++ b/tests/unit/test_mappingmodel.py @@ -17,6 +17,7 @@ from tests.unit import base from chirp import chirp_common from chirp import icf
+ class TestBaseMapping(base.BaseTest): CLS = chirp_common.MemoryMapping
@@ -37,9 +38,11 @@ class TestBaseMapping(base.BaseTest): self.assertEqual(mapping1, mapping2) self.assertNotEqual(mapping1, mapping3)
+ class TestBaseBank(TestBaseMapping): CLS = chirp_common.Bank
+ class _TestBaseClass(base.BaseTest): ARGS = tuple()
@@ -51,6 +54,7 @@ class _TestBaseClass(base.BaseTest): self.assertRaises(NotImplementedError, getattr(self.model, method), *args)
+ class TestBaseMappingModel(_TestBaseClass): CLS = chirp_common.MappingModel ARGS = tuple([None, 'Foo']) @@ -69,6 +73,7 @@ class TestBaseMappingModel(_TestBaseClass): def test_get_name(self): self.assertEqual(self.model.get_name(), 'Foo')
+ class TestBaseBankModel(TestBaseMappingModel): ARGS = tuple([None]) CLS = chirp_common.BankModel @@ -76,6 +81,7 @@ class TestBaseBankModel(TestBaseMappingModel): def test_get_name(self): self.assertEqual(self.model.get_name(), 'Banks')
+ class TestBaseMappingModelIndexInterface(_TestBaseClass): CLS = chirp_common.MappingModelIndexInterface
@@ -88,12 +94,14 @@ class TestBaseMappingModelIndexInterface(_TestBaseClass): for method, args in methods: self._test_base(method, *args)
+ class TestIcomBanks(TestBaseMapping): def test_icom_bank(self): bank = icf.IcomBank(None, 1, 'Foo') # IcomBank has an index attribute used by IcomBankModel self.assertTrue(hasattr(bank, 'index'))
+ class TestIcomBankModel(base.BaseTest): CLS = icf.IcomBankModel
@@ -209,6 +217,7 @@ class TestIcomBankModel(base.BaseTest): self.assertEqual(self._model.get_memory_mappings(mem1)[0], banks[2]) self.assertEqual(self._model.get_memory_mappings(mem2), [])
+ class TestIcomIndexedBankModel(TestIcomBankModel): CLS = icf.IcomIndexedBankModel
diff --git a/tests/unit/test_platform.py b/tests/unit/test_platform.py index c69c743..2148499 100644 --- a/tests/unit/test_platform.py +++ b/tests/unit/test_platform.py @@ -20,6 +20,7 @@ import os from tests.unit import base from chirp import platform
+ class Win32PlatformTest(base.BaseTest): def _test_init(self): self.mox.StubOutWithMock(platform, 'comports') diff --git a/tests/unit/test_shiftdialog.py b/tests/unit/test_shiftdialog.py index 83a0370..46f83ce 100644 --- a/tests/unit/test_shiftdialog.py +++ b/tests/unit/test_shiftdialog.py @@ -6,6 +6,7 @@ from chirpui import shiftdialog from chirp import chirp_common from chirp import errors
+ class FakeRadio(object): def __init__(self, *memories): self._mems = {} @@ -44,6 +45,7 @@ class FakeRadioThread(object): def unlock(self): pass
+ class ShiftDialogTest(base.BaseTest): def _test_hole(self, fn, starting, arg, expected): radio = FakeRadio(*tuple(starting))
Maintaining a list of black files seems like more housekeeping which could get overlooked. Have you looked into the current suite of test tools?
Currently the style check test only verifies against the tip revision, and thus certain files are limited from ever being tested for style. I presume the idea was that as files were recommitted they would have their style brought into compliance, and thus through attrition the entire source tree would eventually reach compliance. Not a bad compromise.
Alternatively, we could enable style check on all source files as part of the test suite execution. This of course would require complete compliance of the source tree, and thus the requirement for a backlist as a stop gap. This does not mention the performance implications if any.
In lieu of having to maintain a list I find the current method more applicable. Having said that though there is nothing stopping us from bringing the codename into compliance one file at a time...
----------------------------------------
From: zach@mandolincreekfarm.com To: chirp_devel@intrepid.danplanet.com Date: Wed, 25 Feb 2015 01:43:39 -0800 Subject: [chirp_devel] [PATCH 10/9] Add pep8 checker script (#2355)
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Add pep8 checker script (#2355)
This patch adds a new script that runs the pep8 tool on the CHIRP source code files. This script is intended to be included in the repository pre-commit hook, preventing future patches from causing any style-related regressions.
The script checks a blacklist of files that are not yet compliant with the style standards, allowing this check to be added almost immediately. Since no new files should ever be added to the blacklist, the blacklist should shrink to empty, and the script will check the entire codebase.
diff --git a/pep8.blacklist b/pep8.blacklist new file mode 100644 index 0000000..2e87a8f --- /dev/null +++ b/pep8.blacklist @@ -0,0 +1,142 @@ +# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant. +# Over time, this list should shrink and (eventually) be eliminated. +# The current list of files that do not yet meet PEP8 standards. +./chirp/alinco.py +./chirp/anytone.py +./chirp/ap510.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/bandplan.py +./chirp/baofeng_uv3r.py +./chirp/bitwise_grammar.py +./chirp/bitwise.py +./chirp/bjuv55.py +./chirp/chirp_common.py +./chirp/detect.py +./chirp/directory.py +./chirp/elib_intl.py +./chirp/errors.py +./chirp/ft1802.py +./chirp/ft1d.py +./chirp/ft2800.py +./chirp/ft50_ll.py +./chirp/ft50.py +./chirp/ft60.py +./chirp/ft7800.py +./chirp/ft817.py +./chirp/ft857.py +./chirp/ft90.py +./chirp/ftm350.py +./chirp/generic_csv.py +./chirp/generic_tpe.py +./chirp/generic_xml.py +./chirp/h777.py +./chirp/ic208.py +./chirp/ic2100.py +./chirp/ic2200.py +./chirp/ic2720.py +./chirp/ic2820.py +./chirp/ic9x_icf_ll.py +./chirp/ic9x_icf.py +./chirp/ic9x_ll.py +./chirp/ic9x.py +./chirp/icf.py +./chirp/icomciv.py +./chirp/icq7.py +./chirp/ict70.py +./chirp/ict7h.py +./chirp/ict8.py +./chirp/icw32.py +./chirp/icx8x_ll.py +./chirp/icx8x.py +./chirp/id31.py +./chirp/id51.py +./chirp/id800.py +./chirp/id880.py +./chirp/idrp.py +./chirp/import_logic.py +./chirp/__init__.py +./chirp/kenwood_hmk.py +./chirp/kenwood_itm.py +./chirp/kenwood_live.py +./chirp/kguv8d.py +./chirp/kyd.py +./chirp/leixen.py +./chirp/memmap.py +./chirp/platform.py +./chirp/puxing.py +./chirp/pyPEG.py +./chirp/radioreference.py +./chirp/rfinder.py +./chirp/settings.py +./chirp/template.py +./chirp/th9800.py +./chirp/thd72.py +./chirp/thuv1f.py +./chirp/th_uv3r25.py +./chirp/th_uv3r.py +./chirp/th_uvf8d.py +./chirp/tk8102.py +./chirp/tmv71_ll.py +./chirp/tmv71.py +./chirpui/bandplans.py +./chirpui/bankedit.py +./chirpui/cloneprog.py +./chirpui/clone.py +./chirpui/common.py +./chirpui/config.py +./chirpui/dstaredit.py +./chirpui/editorset.py +./chirpui/fips.py +./chirpui/importdialog.py +./chirpui/__init__.py +./chirpui/inputdialog.py +./chirpui/mainapp.py +./chirpui/memdetail.py +./chirpui/memedit.py +./chirpui/miscwidgets.py +./chirpui/radiobrowser.py +./chirpui/reporting.py +./chirpui/settingsedit.py +./chirpui/shiftdialog.py +./chirp/util.py +./chirp/uv5r.py +./chirp/uvb5.py +./chirp/vx170.py +./chirp/vx2.py +./chirp/vx3.py +./chirp/vx510.py +./chirp/vx5.py +./chirp/vx6.py +./chirp/vx7.py +./chirp/vx8.py +./chirp/vxa700.py +./chirp/wouxun_common.py +./chirp/wouxun.py +./chirp/xml_ll.py +./chirp/yaesu_clone.py +./csvdump/csvapp.py +./csvdump/csvdump.py +./csvdump/__init__.py +./csvdump.py +./locale/check_parameters.py +./rpttool +./setup.py +./share/make_supported.py +./tests/__init__.py +./tests/run_tests +./tests/unit/base.py +./tests/unit/__init__.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/img2thd72.py diff --git a/pep8.manifest b/pep8.manifest new file mode 100644 index 0000000..2fe9d77 --- /dev/null +++ b/pep8.manifest @@ -0,0 +1,4 @@ +./chirpc +./chirpw +./rpttool +./tests/run_tests diff --git a/pep8.py b/pep8.py new file mode 100755 index 0000000..5b9d99f --- /dev/null +++ b/pep8.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# pep8.py - Check Python source files for PEP8 compliance. +# +# Copyright 2015 Zachary T Welch zach@mandolincreekfarm.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# 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 os +import sys +import logging +import argparse +import subprocess +from chirp import logger
+LOG = logging.getLogger("pep8.py")
+parser = argparse.ArgumentParser() +parser.add_argument("-a", "--all", action="store_true",
- help="Check all files, ignoring blacklist")
+parser.add_argument("--stats", action="store_true",
- help="Only show statistics")
+parser.add_argument("files", metavar="file", nargs='*',
- help="List of files to check (if none, check all)")
+logger.add_arguments(parser) +args = parser.parse_args() +logger.handle_options(args)
+def file_to_lines(name):
- fh = file(name, "r")
- lines = fh.read().split("\n")
- lines.pop()
- fh.close()
- return lines
+# read manifest and search for python files +manifest = file_to_lines("pep8.manifest") +for root, dirs, files in os.walk("."):
- for f in files:
- if f.endswith('.py'):
- manifest.append(os.path.join(root, f))
+# read the blacklisted source files +blacklist = file_to_lines("pep8.blacklist")
+if args.files:
- manifest = args.files
+for f in manifest:
- if args.all or f not in blacklist:
- LOG.info("checking %s", f)
- cmdline = ['pep8', f]
- if args.stats:
- cmdline += ['-q', '--statistics']
- subprocess.call(cmdline)
chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 02:25 AM, Kosta Arvanitis wrote:
Maintaining a list of black files seems like more housekeeping which could get overlooked. Have you looked into the current suite of test tools?
First off, I plan to systematically go through the tree and fix the style issues (though others are welcome to do so). When I do so, I will remove the files from the blacklist. I don't expect it will take very long until the blacklist is gone, but it still might be a matter of weeks.
During that period, I do not want others to accidentally cause regressions in the files that I have already cleaned up, thus I want this tool to be put into place as soon as possible. That requires a blacklist to prevent others from being immediately forced to clean up files that they are working on (though such efforts would be welcome).
As for performance, it can be run with the list of files that have been touched (i.e. from a 'diffstat -l'), so it can limit its check to files in a patch (and not check the whole tree). Style checking the whole tree currently takes less than 2 minutes on my underpowered netbook.
As for coverage, the pep8 tool is much more thorough than the existing style checks. Dan and I discussed this approach on IRC tonight, and these patches were driven directly out of that discussion.
Hi Zach
First off, I plan to systematically go through the tree and fix the style issues (though others are welcome to do so).
I'm waiting for this "patch storm" to calm down (and be included in the tree) then I'll start fixing some of the style issues.
73 de IZ3GME Marco
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Move radios into their own directory (#2351)
CHIRP now supports enough radios that the chirp/ directory has become cluttered. This creates unnecessary coupling when importing all of the radios. This patch moves all of the radios to their own directory and then chases down all of the stale import references.
There may be more work to do in order to finish this feature, but these changes do not cause any new regressions in the test suite. Further, the CLI and GUI both continue to work, so it's a good first step.
diff --git a/chirp/detect.py b/chirp/detect.py index eeefb32..7676b9f 100644 --- a/chirp/detect.py +++ b/chirp/detect.py @@ -15,8 +15,8 @@
import serial
-from chirp import errors, icf, directory, ic9x_ll -from chirp import kenwood_live, icomciv +from chirp import errors, directory +from radio import ic9x_ll, icf, kenwood_live, icomciv
def _icom_model_data_to_rclass(md): for _rtype, rclass in directory.DRV_TO_RADIO.items(): diff --git a/chirp/directory.py b/chirp/directory.py index 07308ee..ce7cf20 100644 --- a/chirp/directory.py +++ b/chirp/directory.py @@ -18,7 +18,7 @@ import os import tempfile import logging
-from chirp import icf +from radio import icf from chirp import chirp_common, util, rfinder, radioreference, errors
LOG = logging.getLogger(__name__) diff --git a/chirpc b/chirpc index 1a5ffdd..1d20548 100755 --- a/chirpc +++ b/chirpc @@ -21,9 +21,8 @@ import sys import argparse import logging
-from chirp import logger -from chirp import * -from chirp import chirp_common, errors, idrp, directory, util +from radio import * +from chirp import chirp_common, errors, directory, util, logger, version
LOG = logging.getLogger("chirpc") RADIOS = directory.DRV_TO_RADIO diff --git a/chirpui/mainapp.py b/chirpui/mainapp.py index 2d8e3e1..52e4d90 100644 --- a/chirpui/mainapp.py +++ b/chirpui/mainapp.py @@ -40,9 +40,9 @@ except ImportError,e: common.log_exception() common.show_error("\nThe Pyserial module is not installed!") from chirp import platform, generic_xml, generic_csv, directory, util -from chirp import ic9x, kenwood_live, idrp, vx7, vx5, vx6 +from radio import ic9x, kenwood_live, idrp, vx7, vx5, vx6 +from radio import icf, ic9x_icf from chirp import CHIRP_VERSION, chirp_common, detect, errors -from chirp import icf, ic9x_icf from chirpui import editorset, clone, miscwidgets, config, reporting, fips from chirpui import bandplans
diff --git a/chirpui/radiobrowser.py b/chirpui/radiobrowser.py index a11d810..724d262 100644 --- a/chirpui/radiobrowser.py +++ b/chirpui/radiobrowser.py @@ -318,7 +318,7 @@ class RadioBrowser(common.Editor): self._focused = False
if __name__ == "__main__": - from chirp import * + from radio import * from chirp import directory import sys
diff --git a/chirpw b/chirpw index 26d2369..2a44df8 100755 --- a/chirpw +++ b/chirpw @@ -120,7 +120,7 @@ else: # Python >=2.6, use normal gettext behavior lang.install()
-from chirp import * +from radio import * from chirpui import mainapp, config
parser = argparse.ArgumentParser() diff --git a/radio/__init__.py b/radio/__init__.py new file mode 100644 index 0000000..726217b --- /dev/null +++ b/radio/__init__.py @@ -0,0 +1,10 @@ +import os +import sys +from glob import glob + +module_dir = os.path.dirname(sys.modules["radio"].__file__) +__all__ = [] +for i in sorted(glob(os.path.join(module_dir, "*.py"))): + name = os.path.basename(i)[:-3] + if not name.startswith("__"): + __all__.append(name) diff --git a/chirp/alinco.py b/radio/alinco.py similarity index 100% rename from chirp/alinco.py rename to radio/alinco.py diff --git a/chirp/anytone.py b/radio/anytone.py similarity index 100% rename from chirp/anytone.py rename to radio/anytone.py diff --git a/chirp/ap510.py b/radio/ap510.py similarity index 100% rename from chirp/ap510.py rename to radio/ap510.py diff --git a/chirp/baofeng_uv3r.py b/radio/baofeng_uv3r.py similarity index 99% rename from chirp/baofeng_uv3r.py rename to radio/baofeng_uv3r.py index 0827885..c98ab37 100644 --- a/chirp/baofeng_uv3r.py +++ b/radio/baofeng_uv3r.py @@ -17,8 +17,8 @@
import time import os +from wouxun_common import do_download, do_upload from chirp import util, chirp_common, bitwise, errors, directory -from chirp.wouxun_common import do_download, do_upload from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ RadioSettingValueInteger, RadioSettingValueString, \ diff --git a/chirp/bjuv55.py b/radio/bjuv55.py similarity index 99% rename from chirp/bjuv55.py rename to radio/bjuv55.py index 9fb7e5a..2aaa8b0 100644 --- a/chirp/bjuv55.py +++ b/radio/bjuv55.py @@ -19,6 +19,7 @@ import struct import time import os
+from radio import uv5r from chirp import chirp_common, errors, util, directory, memmap from chirp import bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -26,7 +27,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent -from chirp import uv5r
BJUV55_MODEL = "\x50\xBB\xDD\x55\x63\x98\x4D"
diff --git a/chirp/ft1802.py b/radio/ft1802.py similarity index 99% rename from chirp/ft1802.py rename to radio/ft1802.py index 7b5945d..4d4e570 100644 --- a/chirp/ft1802.py +++ b/radio/ft1802.py @@ -23,7 +23,8 @@ # 4. Press the [D/MR(MW)] key ("--WAIT--" will appear on the LCD). # 5. In Chirp, choose Upload to Radio.
-from chirp import chirp_common, bitwise, directory, yaesu_clone +from radio import yaesu_clone +from chirp import chirp_common, bitwise, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettings from textwrap import dedent diff --git a/chirp/ft1d.py b/radio/ft1d.py similarity index 99% rename from chirp/ft1d.py rename to radio/ft1d.py index db0259f..33a94ec 100644 --- a/chirp/ft1d.py +++ b/radio/ft1d.py @@ -19,8 +19,8 @@ import re import string import logging
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean diff --git a/chirp/ft2800.py b/radio/ft2800.py similarity index 99% rename from chirp/ft2800.py rename to radio/ft2800.py index feac0ce..d091d7b 100644 --- a/chirp/ft2800.py +++ b/radio/ft2800.py @@ -18,7 +18,7 @@ import os import logging
from chirp import util, memmap, chirp_common, bitwise, directory, errors -from chirp.yaesu_clone import YaesuCloneModeRadio +from yaesu_clone import YaesuCloneModeRadio
LOG = logging.getLogger(__name__)
diff --git a/chirp/ft50.py b/radio/ft50.py similarity index 95% rename from chirp/ft50.py rename to radio/ft50.py index d101360..ff1a660 100644 --- a/chirp/ft50.py +++ b/radio/ft50.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, ft50_ll, directory +from radio import yaesu_clone, ft50_ll +from chirp import chirp_common, directory
# Not working, don't register #@directory.register diff --git a/chirp/ft50_ll.py b/radio/ft50_ll.py similarity index 100% rename from chirp/ft50_ll.py rename to radio/ft50_ll.py diff --git a/chirp/ft60.py b/radio/ft60.py similarity index 99% rename from chirp/ft60.py rename to radio/ft60.py index 74799ef..8abe856 100644 --- a/chirp/ft60.py +++ b/radio/ft60.py @@ -14,8 +14,8 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import time, os, logging -from chirp import chirp_common, yaesu_clone, memmap, bitwise, directory -from chirp import errors +from radio import yaesu_clone +from chirp import chirp_common, memmap, bitwise, directory, errors from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/ft7800.py b/radio/ft7800.py similarity index 99% rename from chirp/ft7800.py rename to radio/ft7800.py index 824bd6d..cc64456 100644 --- a/chirp/ft7800.py +++ b/radio/ft7800.py @@ -14,8 +14,8 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import time, logging -from chirp import chirp_common, yaesu_clone, memmap, directory -from chirp import bitwise, errors +from radio import yaesu_clone +from chirp import chirp_common, memmap, directory, bitwise, errors from textwrap import dedent from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ diff --git a/chirp/ft817.py b/radio/ft817.py similarity index 99% rename from chirp/ft817.py rename to radio/ft817.py index 319bc46..55d5a28 100644 --- a/chirp/ft817.py +++ b/radio/ft817.py @@ -16,8 +16,8 @@
"""FT817 - FT817ND - FT817ND/US management module"""
-from chirp import chirp_common, yaesu_clone, util, memmap, errors, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, util, memmap, errors, directory, bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/ft857.py b/radio/ft857.py similarity index 99% rename from chirp/ft857.py rename to radio/ft857.py index ebe8e12..f1d2431 100644 --- a/chirp/ft857.py +++ b/radio/ft857.py @@ -16,7 +16,8 @@
"""FT857 - FT857/US management module"""
-from chirp import ft817, chirp_common, errors, directory +from radio import ft817 +from chirp import chirp_common, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/ft90.py b/radio/ft90.py similarity index 99% rename from chirp/ft90.py rename to radio/ft90.py index b638d47..6611b09 100644 --- a/chirp/ft90.py +++ b/radio/ft90.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, bitwise, memmap, directory, errors, util, yaesu_clone +from radio import yaesu_clone +from chirp import chirp_common, bitwise, memmap, directory, errors, util from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/ftm350.py b/radio/ftm350.py similarity index 99% rename from chirp/ftm350.py rename to radio/ftm350.py index e3fcbfe..b9226ef 100644 --- a/chirp/ftm350.py +++ b/radio/ftm350.py @@ -18,8 +18,8 @@ import struct import os import logging
-from chirp import chirp_common, yaesu_clone, directory, errors, util -from chirp import bitwise, memmap +from radio import yaesu_clone +from chirp import chirp_common, directory, errors, util, bitwise, memmap from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings from chirp.settings import RadioSettingValueInteger, RadioSettingValueString
diff --git a/chirp/h777.py b/radio/h777.py similarity index 100% rename from chirp/h777.py rename to radio/h777.py diff --git a/chirp/ic208.py b/radio/ic208.py similarity index 98% rename from chirp/ic208.py rename to radio/ic208.py index f93300c..4f24bc8 100644 --- a/chirp/ic208.py +++ b/radio/ic208.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, errors, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, errors, directory, bitwise
MEM_FORMAT = """ struct memory { diff --git a/chirp/ic2100.py b/radio/ic2100.py similarity index 98% rename from chirp/ic2100.py rename to radio/ic2100.py index 0b2dda8..a1d5f9e 100644 --- a/chirp/ic2100.py +++ b/radio/ic2100.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, util, directory -from chirp import bitwise, memmap +from radio import icf +from chirp import chirp_common, util, directory, bitwise, memmap from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/ic2200.py b/radio/ic2200.py similarity index 99% rename from chirp/ic2200.py rename to radio/ic2200.py index d6b1fe2..8d2d133 100644 --- a/chirp/ic2200.py +++ b/radio/ic2200.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, util, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, util, directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/ic2720.py b/radio/ic2720.py similarity index 98% rename from chirp/ic2720.py rename to radio/ic2720.py index 24d499a..583cced 100644 --- a/chirp/ic2720.py +++ b/radio/ic2720.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, util, directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/ic2820.py b/radio/ic2820.py similarity index 99% rename from chirp/ic2820.py rename to radio/ic2820.py index 5f5827c..4d7d1e0 100644 --- a/chirp/ic2820.py +++ b/radio/ic2820.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, util, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, util, directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/ic9x.py b/radio/ic9x.py similarity index 99% rename from chirp/ic9x.py rename to radio/ic9x.py index 3d8c437..a692bfc 100644 --- a/chirp/ic9x.py +++ b/radio/ic9x.py @@ -16,7 +16,8 @@ import time import threading
-from chirp import chirp_common, errors, ic9x_ll, icf, util, directory +from radio import ic9x_ll, icf +from chirp import chirp_common, errors, util, directory from chirp import bitwise
IC9XA_SPECIAL = {} diff --git a/chirp/ic9x_icf.py b/radio/ic9x_icf.py similarity index 96% rename from chirp/ic9x_icf.py rename to radio/ic9x_icf.py index 9da75b5..658eb59 100644 --- a/chirp/ic9x_icf.py +++ b/radio/ic9x_icf.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, ic9x_icf_ll, util, directory, errors +from radio import icf, ic9x_icf_ll +from chirp import chirp_common, util, directory, errors
# Don't register as this module is used to load icf file from File-Open menu # see do_open in mainapp.py diff --git a/chirp/ic9x_icf_ll.py b/radio/ic9x_icf_ll.py similarity index 100% rename from chirp/ic9x_icf_ll.py rename to radio/ic9x_icf_ll.py diff --git a/chirp/ic9x_ll.py b/radio/ic9x_ll.py similarity index 100% rename from chirp/ic9x_ll.py rename to radio/ic9x_ll.py diff --git a/chirp/icf.py b/radio/icf.py similarity index 100% rename from chirp/icf.py rename to radio/icf.py diff --git a/chirp/icomciv.py b/radio/icomciv.py similarity index 99% rename from chirp/icomciv.py rename to radio/icomciv.py index 1d02553..3babf16 100644 --- a/chirp/icomciv.py +++ b/radio/icomciv.py @@ -1,6 +1,7 @@
import struct, logging -from chirp import chirp_common, icf, util, errors, bitwise, directory +from radio import icf +from chirp import chirp_common, util, errors, bitwise, directory from chirp.memmap import MemoryMap
LOG = logging.getLogger(__name__) diff --git a/chirp/icq7.py b/radio/icq7.py similarity index 99% rename from chirp/icq7.py rename to radio/icq7.py index 23333fb..73ee492 100644 --- a/chirp/icq7.py +++ b/radio/icq7.py @@ -14,8 +14,8 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import struct -from chirp import chirp_common, icf, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, directory, bitwise from chirp.chirp_common import to_GHz, from_GHz from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ diff --git a/chirp/ict70.py b/radio/ict70.py similarity index 98% rename from chirp/ict70.py rename to radio/ict70.py index d035e14..ca56fb7 100644 --- a/chirp/ict70.py +++ b/radio/ict70.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/ict7h.py b/radio/ict7h.py similarity index 98% rename from chirp/ict7h.py rename to radio/ict7h.py index 768fb34..f833ba7 100644 --- a/chirp/ict7h.py +++ b/radio/ict7h.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, directory, bitwise
mem_format = """ struct { diff --git a/chirp/ict8.py b/radio/ict8.py similarity index 97% rename from chirp/ict8.py rename to radio/ict8.py index c77d8f3..548cae2 100644 --- a/chirp/ict8.py +++ b/radio/ict8.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, util, directory +from radio import icf +from chirp import chirp_common, util, directory from chirp import bitwise
mem_format = """ diff --git a/chirp/icw32.py b/radio/icw32.py similarity index 98% rename from chirp/icw32.py rename to radio/icw32.py index 2b028ad..ad45507 100644 --- a/chirp/icw32.py +++ b/radio/icw32.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, util, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, util, directory, bitwise
MEM_FORMAT = """ #seekto 0x%x; diff --git a/chirp/icx8x.py b/radio/icx8x.py similarity index 98% rename from chirp/icx8x.py rename to radio/icx8x.py index b9ea35c..88175aa 100644 --- a/chirp/icx8x.py +++ b/radio/icx8x.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, icx8x_ll, errors, directory +from radio import icf, icx8x_ll +from chirp import chirp_common, errors, directory
def _isuhf(pipe): try: diff --git a/chirp/icx8x_ll.py b/radio/icx8x_ll.py similarity index 100% rename from chirp/icx8x_ll.py rename to radio/icx8x_ll.py diff --git a/chirp/id31.py b/radio/id31.py similarity index 99% rename from chirp/id31.py rename to radio/id31.py index 128d79d..66e3d31 100644 --- a/chirp/id31.py +++ b/radio/id31.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import directory, icf, bitwise, chirp_common +from radio import icf +from chirp import directory, bitwise, chirp_common
MEM_FORMAT = """ struct { diff --git a/chirp/id51.py b/radio/id51.py similarity index 97% rename from chirp/id51.py rename to radio/id51.py index 4b72c44..980ce97 100644 --- a/chirp/id51.py +++ b/radio/id51.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import directory, bitwise, id31 +from radio import id31 +from chirp import directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/id800.py b/radio/id800.py similarity index 99% rename from chirp/id800.py rename to radio/id800.py index 56350de..4976793 100644 --- a/chirp/id800.py +++ b/radio/id800.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, errors, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, errors, directory, bitwise
MEM_FORMAT = """ #seekto 0x0020; diff --git a/chirp/id880.py b/radio/id880.py similarity index 99% rename from chirp/id880.py rename to radio/id880.py index b6c8b39..4b5c06d 100644 --- a/chirp/id880.py +++ b/radio/id880.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, icf, directory -from chirp import bitwise +from radio import icf +from chirp import chirp_common, directory, bitwise
MEM_FORMAT = """ struct { diff --git a/chirp/idrp.py b/radio/idrp.py similarity index 100% rename from chirp/idrp.py rename to radio/idrp.py diff --git a/chirp/kenwood_hmk.py b/radio/kenwood_hmk.py similarity index 100% rename from chirp/kenwood_hmk.py rename to radio/kenwood_hmk.py diff --git a/chirp/kenwood_itm.py b/radio/kenwood_itm.py similarity index 100% rename from chirp/kenwood_itm.py rename to radio/kenwood_itm.py diff --git a/chirp/kenwood_live.py b/radio/kenwood_live.py similarity index 100% rename from chirp/kenwood_live.py rename to radio/kenwood_live.py diff --git a/chirp/kguv8d.py b/radio/kguv8d.py similarity index 100% rename from chirp/kguv8d.py rename to radio/kguv8d.py diff --git a/chirp/kyd.py b/radio/kyd.py similarity index 100% rename from chirp/kyd.py rename to radio/kyd.py diff --git a/chirp/leixen.py b/radio/leixen.py similarity index 100% rename from chirp/leixen.py rename to radio/leixen.py diff --git a/chirp/puxing.py b/radio/puxing.py similarity index 99% rename from chirp/puxing.py rename to radio/puxing.py index f38b41e..fcd8966 100644 --- a/chirp/puxing.py +++ b/radio/puxing.py @@ -18,7 +18,7 @@ import time import os from chirp import util, chirp_common, bitwise, errors, directory -from chirp.wouxun_common import wipe_memory, do_download, do_upload +from radio.wouxun_common import wipe_memory, do_download, do_upload
def _puxing_prep(radio): radio.pipe.write("\x02PROGRA") diff --git a/chirp/th9800.py b/radio/th9800.py similarity index 99% rename from chirp/th9800.py rename to radio/th9800.py index d1a1b0b..1f1d498 100644 --- a/chirp/th9800.py +++ b/radio/th9800.py @@ -21,7 +21,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettingValueFloat, InvalidValueError, RadioSettings -from chirp_common import format_freq +from chirp.chirp_common import format_freq import os import time import logging diff --git a/chirp/th_uv3r.py b/radio/th_uv3r.py similarity index 99% rename from chirp/th_uv3r.py rename to radio/th_uv3r.py index 3b670fe..f692545 100644 --- a/chirp/th_uv3r.py +++ b/radio/th_uv3r.py @@ -17,7 +17,7 @@
import os from chirp import chirp_common, bitwise, errors, directory -from chirp.wouxun_common import do_download, do_upload +from radio.wouxun_common import do_download, do_upload
def tyt_uv3r_prep(radio): try: diff --git a/chirp/th_uv3r25.py b/radio/th_uv3r25.py similarity index 99% rename from chirp/th_uv3r25.py rename to radio/th_uv3r25.py index e9b4cbb..f509e11 100644 --- a/chirp/th_uv3r25.py +++ b/radio/th_uv3r25.py @@ -16,7 +16,7 @@ """TYT uv3r (2.5kHz) radio management module"""
from chirp import chirp_common, bitwise, directory -from chirp.wouxun_common import do_download, do_upload +from radio.wouxun_common import do_download, do_upload
from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ diff --git a/chirp/th_uvf8d.py b/radio/th_uvf8d.py similarity index 100% rename from chirp/th_uvf8d.py rename to radio/th_uvf8d.py diff --git a/chirp/thd72.py b/radio/thd72.py similarity index 100% rename from chirp/thd72.py rename to radio/thd72.py diff --git a/chirp/thuv1f.py b/radio/thuv1f.py similarity index 100% rename from chirp/thuv1f.py rename to radio/thuv1f.py diff --git a/chirp/tk8102.py b/radio/tk8102.py similarity index 100% rename from chirp/tk8102.py rename to radio/tk8102.py diff --git a/chirp/tmv71.py b/radio/tmv71.py similarity index 98% rename from chirp/tmv71.py rename to radio/tmv71.py index 59ef226..6be6db9 100644 --- a/chirp/tmv71.py +++ b/radio/tmv71.py @@ -14,7 +14,7 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
from chirp import chirp_common, errors, util -from chirp import tmv71_ll +from radio import tmv71_ll
class TMV71ARadio(chirp_common.CloneModeRadio): BAUD_RATE = 9600 diff --git a/chirp/tmv71_ll.py b/radio/tmv71_ll.py similarity index 100% rename from chirp/tmv71_ll.py rename to radio/tmv71_ll.py diff --git a/chirp/uv5r.py b/radio/uv5r.py similarity index 100% rename from chirp/uv5r.py rename to radio/uv5r.py diff --git a/chirp/uvb5.py b/radio/uvb5.py similarity index 100% rename from chirp/uvb5.py rename to radio/uvb5.py diff --git a/chirp/vx170.py b/radio/vx170.py similarity index 96% rename from chirp/vx170.py rename to radio/vx170.py index eaa7dbc..aa24531 100644 --- a/chirp/vx170.py +++ b/radio/vx170.py @@ -13,11 +13,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory, memmap -from chirp import bitwise, errors +from radio import yaesu_clone, ft7800 +from chirp import chirp_common, directory, memmap, bitwise, errors from textwrap import dedent import time, os -from chirp import ft7800
MEM_FORMAT = """ #seekto 0x018A; diff --git a/chirp/vx2.py b/radio/vx2.py similarity index 99% rename from chirp/vx2.py rename to radio/vx2.py index 6c6b912..3f1bd36 100644 --- a/chirp/vx2.py +++ b/radio/vx2.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory, bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/vx3.py b/radio/vx3.py similarity index 99% rename from chirp/vx3.py rename to radio/vx3.py index 0575a46..e671287 100644 --- a/chirp/vx3.py +++ b/radio/vx3.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ diff --git a/chirp/vx5.py b/radio/vx5.py similarity index 98% rename from chirp/vx5.py rename to radio/vx5.py index 65a5ba4..cfdb4ad 100644 --- a/chirp/vx5.py +++ b/radio/vx5.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory, errors -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, errors, bitwise
MEM_FORMAT = """ #seekto 0x002A; diff --git a/chirp/vx510.py b/radio/vx510.py similarity index 98% rename from chirp/vx510.py rename to radio/vx510.py index 7f287a9..3f8ed66 100644 --- a/chirp/vx510.py +++ b/radio/vx510.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise
# This driver is unfinished and therefore does not register itself with Chirp. # diff --git a/chirp/vx6.py b/radio/vx6.py similarity index 99% rename from chirp/vx6.py rename to radio/vx6.py index 0cdb115..f0af37d 100644 --- a/chirp/vx6.py +++ b/radio/vx6.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from textwrap import dedent
# flags.{even|odd}_pskip: These are actually "preferential *scan* channels". diff --git a/chirp/vx7.py b/radio/vx7.py similarity index 99% rename from chirp/vx7.py rename to radio/vx7.py index 5fff4b1..3ebb74d 100644 --- a/chirp/vx7.py +++ b/radio/vx7.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/.
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from textwrap import dedent
MEM_FORMAT = """ diff --git a/chirp/vx8.py b/radio/vx8.py similarity index 99% rename from chirp/vx8.py rename to radio/vx8.py index 45fff7a..b822868 100644 --- a/chirp/vx8.py +++ b/radio/vx8.py @@ -17,8 +17,8 @@ import os import re import logging
-from chirp import chirp_common, yaesu_clone, directory -from chirp import bitwise +from radio import yaesu_clone +from chirp import chirp_common, directory, bitwise from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean diff --git a/chirp/vxa700.py b/radio/vxa700.py similarity index 100% rename from chirp/vxa700.py rename to radio/vxa700.py diff --git a/chirp/wouxun.py b/radio/wouxun.py similarity index 99% rename from chirp/wouxun.py rename to radio/wouxun.py index 4a3dd0b..2a73f0a 100644 --- a/chirp/wouxun.py +++ b/radio/wouxun.py @@ -23,7 +23,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettingValueFloat, RadioSettings -from chirp.wouxun_common import wipe_memory, do_download, do_upload +from wouxun_common import wipe_memory, do_download, do_upload from textwrap import dedent
LOG = logging.getLogger(__name__) diff --git a/chirp/wouxun_common.py b/radio/wouxun_common.py similarity index 100% rename from chirp/wouxun_common.py rename to radio/wouxun_common.py diff --git a/chirp/yaesu_clone.py b/radio/yaesu_clone.py similarity index 100% rename from chirp/yaesu_clone.py rename to radio/yaesu_clone.py diff --git a/tests/run_tests b/tests/run_tests index 26a632b..f5e442e 100755 --- a/tests/run_tests +++ b/tests/run_tests @@ -23,7 +23,7 @@ from serial import Serial sys.path.insert(0, "../")
from chirp import CHIRP_VERSION -from chirp import * +from radio import * from chirp import chirp_common, directory, generic_csv, import_logic, memmap, settings from chirp import errors
diff --git a/radio/__init__.py b/radio/__init__.py new file mode 100644 index 0000000..726217b --- /dev/null +++ b/radio/__init__.py
This isn't okay, as it will generate a top-level module called 'radio' if the package is installed on the system. I.e. it would look like this:
from radio import ic2820
This needs to be under chirp/, and I'd prefer "drivers".
Note that your chirpc rename patch did not work, as mercurial didn't properly generate a follow-able rename change and instead just deleted/added the old/new file(s). So, that means someone who uses mercurial will have to generate that patch (jab).
Before we do, I'd like to ask the group whether they think this is really something we need to change. I agree that chirp/ is very cluttered, but I'm also not sure that it really matters. This massive rename is kindof a hassle (and will break my muscle memory).
So: should we do this?
--Dan
I think this is good. I also prefer the radio source under the chirp tree, fwiw I would prefer also source (chirpui) under this tree as well so as so to make indexed source better.
Either drivers or radios is fine. I would lean towards radio only because the classes in this folder would mostly inherit from radio. Either way good change imo.
Date: Wed, 25 Feb 2015 08:55:50 -0800 From: dsmith@danplanet.com To: chirp_devel@intrepid.danplanet.com Subject: Re: [chirp_devel] [PATCH 12/9] Move radios into their own directory (#2351)
diff --git a/radio/__init__.py b/radio/__init__.py new file mode 100644 index 0000000..726217b --- /dev/null +++ b/radio/__init__.py
This isn't okay, as it will generate a top-level module called 'radio' if the package is installed on the system. I.e. it would look like this:
from radio import ic2820
This needs to be under chirp/, and I'd prefer "drivers".
Note that your chirpc rename patch did not work, as mercurial didn't properly generate a follow-able rename change and instead just deleted/added the old/new file(s). So, that means someone who uses mercurial will have to generate that patch (jab).
Before we do, I'd like to ask the group whether they think this is really something we need to change. I agree that chirp/ is very cluttered, but I'm also not sure that it really matters. This massive rename is kindof a hassle (and will break my muscle memory).
So: should we do this?
--Dan
_______________________________________________ chirp_devel mailing list chirp_devel@intrepid.danplanet.com http://intrepid.danplanet.com/mailman/listinfo/chirp_devel Developer docs: http://chirp.danplanet.com/projects/chirp/wiki/Developers
On 02/25/2015 08:55 AM, Dan Smith wrote:
diff --git a/radio/__init__.py b/radio/__init__.py new file mode 100644 index 0000000..726217b --- /dev/null +++ b/radio/__init__.py
This isn't okay, as it will generate a top-level module called 'radio' if the package is installed on the system. I.e. it would look like this:
from radio import ic2820
This needs to be under chirp/, and I'd prefer "drivers".
To be clear, you want chirp/radio/ or chirp/drivers/?
I think "drivers" is too generic a term. These are all radios. If we have another class of drivers, they should go in a different directory, named appropriately.
Also, I agree with Kosta regarding the ui. It should be chirp/ui/, but that would need to be a separate patch.
Note that your chirpc rename patch did not work, as mercurial didn't properly generate a follow-able rename change and instead just deleted/added the old/new file(s). So, that means someone who uses mercurial will have to generate that patch (jab).
Deleting and adding is how git tracks files, and mercurial uses it as the storage engine. Use 'hg log --follow chirpc', and you'll see the history is all there.
Cheers,
To be clear, you want chirp/radio/ or chirp/drivers/?
Yes.
I think "drivers" is too generic a term. These are all radios. If we have another class of drivers, they should go in a different directory, named appropriately.
They are not all radios. There are storage formats in there, repeaters, and APRS units. They're all drivers, and "drivers" is my preference for the module name.
Also, I agree with Kosta regarding the ui. It should be chirp/ui/, but that would need to be a separate patch.
Yep.
Deleting and adding is how git tracks files, and mercurial uses it as the storage engine.
Why do you keep saying this? Unless something has changed recently in either tool, this definitely not the case. Mercurial uses revlog, which is similar in concept, but significantly different in practice.
Either way, the patch handling and event recording could easily be different depending on the tool, regardless of the eventual persistence.
Use 'hg log --follow chirpc', and you'll see the history is all there.
When I "hg import" your patch, --follow does not show the history. When I "hg rename" it, it does. As such, I didn't apply your patch, did the rename myself, and committed it with your authorship, which is why the repository shows the correct history.
If you actually used mercurial to try to apply your patch to a copy of the tree from before I applied the proper fix, you'll see the history is not maintained.
--Dan
On 02/25/2015 09:53 AM, Dan Smith wrote: ...
I think "drivers" is too generic a term. These are all radios. If we have another class of drivers, they should go in a different directory, named appropriately.
They are not all radios. There are storage formats in there, repeaters, and APRS units. They're all drivers, and "drivers" is my preference for the module name.
Okay, I did not realize this either. I am still learning. If you are looking down the road, will there be value in creating separate radio/, storage/, repeater/, arps/ directories (under chirp/, of course)? It would be nice to plan ahead so we don't ever have to do this kind of shuffle again.
Personally, I like this idea, as it would help newbies (like me) understand that there are different classes of drivers. Moreover, it becomes easier to make sure that changes to a certain class are effected across all relevant drivers (i.e. just be sure to touch everything in the appropriate directory).
Deleting and adding is how git tracks files, and mercurial uses it as the storage engine.
Why do you keep saying this? Unless something has changed recently in either tool, this definitely not the case. Mercurial uses revlog, which is similar in concept, but significantly different in practice.
Apparently my memory is not what it used to be. Mea culpa.
Use 'hg log --follow chirpc', and you'll see the history is all there.
When I "hg import" your patch, --follow does not show the history. When I "hg rename" it, it does. As such, I didn't apply your patch, did the rename myself, and committed it with your authorship, which is why the repository shows the correct history.
I see. I did not realize you did that you did that. I wonder whether it would have worked had I used -C, as I did for this patch.
If you actually used mercurial to try to apply your patch to a copy of the tree from before I applied the proper fix, you'll see the history is not maintained.
I will do a 'hg import' of my revised series on a clone of my hg repo and see if I can make it work. If not, I'll suck it up and try to send them from mercurial. Meanwhile, thanks for working with me to try and make sending from git a possibility.
participants (5)
-
Dan Smith
-
Jens Jensen
-
Kosta Arvanitis
-
Marco Filippi IZ3GME
-
Zach Welch