# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 86297c746bd88e56a68b06108d7b7ea2eb24d603
Use logging in drivers/[ab]*.py (#2347)
diff --git a/chirp/drivers/alinco.py b/chirp/drivers/alinco.py index 31bbbea..5662aaa 100644 --- a/chirp/drivers/alinco.py +++ b/chirp/drivers/alinco.py @@ -18,6 +18,9 @@ from chirp.settings import RadioSettingGroup, RadioSetting from chirp.settings import RadioSettingValueBoolean, RadioSettings
import time +import logging + +LOG = logging.getLogger(__name__)
DRX35_MEM_FORMAT = """ @@ -92,13 +95,13 @@ class AlincoStyleRadio(chirp_common.CloneModeRadio): _model = "NONE"
def _send(self, data): - print "PC->R: (%2i) %s" % (len(data), tohex(data)) + LOG.debug("PC->R: (%2i) %s" % (len(data), tohex(data))) self.pipe.write(data) self.pipe.read(len(data))
def _read(self, length): data = self.pipe.read(length) - print "R->PC: (%2i) %s" % (len(data), tohex(data)) + LOG.debug("R->PC: (%2i) %s" % (len(data), tohex(data))) return data
def _download_chunk(self, addr): @@ -119,10 +122,10 @@ class AlincoStyleRadio(chirp_common.CloneModeRadio): data += chr(int(_data[i:i+2], 16))
if len(data) != 16: - print "Response was:" - print "|%s|" - print "Which I converted to:" - print util.hexprint(data) + LOG.debug("Response was:") + LOG.debug("|%s|") + LOG.debug("Which I converted to:") + LOG.debug(util.hexprint(data)) raise Exception("Radio returned less than 16 bytes")
return data @@ -556,10 +559,10 @@ class DJ175Radio(DRx35Radio): data += chr(int(_data[i:i+2], 16))
if len(data) != 16: - print "Response was:" - print "|%s|" - print "Which I converted to:" - print util.hexprint(data) + LOG.debug("Response was:") + LOG.debug("|%s|") + LOG.debug("Which I converted to:") + LOG.debug(util.hexprint(data)) raise Exception("Radio returned less than 16 bytes")
return data diff --git a/chirp/drivers/anytone.py b/chirp/drivers/anytone.py index 8755708..b80099c 100644 --- a/chirp/drivers/anytone.py +++ b/chirp/drivers/anytone.py @@ -178,7 +178,7 @@ def _echo_write(radio, data): radio.pipe.write(data) radio.pipe.read(len(data)) except Exception, e: - print "Error writing to radio: %s" % e + LOG.error("Error writing to radio: %s" % e) raise errors.RadioError("Unable to write to radio")
@@ -186,13 +186,13 @@ def _read(radio, length): try: data = radio.pipe.read(length) except Exception, e: - print "Error reading from radio: %s" % e + LOG.error("Error reading from radio: %s" % e) raise errors.RadioError("Unable to read from radio")
if len(data) != length: - print "Short read from radio (%i, expected %i)" % (len(data), - length) - print util.hexprint(data) + LOG.error("Short read from radio (%i, expected %i)" % + (len(data), length)) + LOG.debug(util.hexprint(data)) raise errors.RadioError("Short read from radio") return data
@@ -204,13 +204,13 @@ def _ident(radio): _echo_write(radio, "PROGRAM") response = radio.pipe.read(3) if response != "QX\x06": - print "Response was:\n%s" % util.hexprint(response) + LOG.debug("Response was:\n%s" % util.hexprint(response)) raise errors.RadioError("Unsupported model") _echo_write(radio, "\x02") response = radio.pipe.read(16) LOG.debug(util.hexprint(response)) if response[1:8] not in valid_model: - print "Response was:\n%s" % util.hexprint(response) + LOG.debug("Response was:\n%s" % util.hexprint(response)) raise errors.RadioError("Unsupported model")
@@ -219,7 +219,7 @@ def _finish(radio): _echo_write(radio, endframe) result = radio.pipe.read(1) if result != "\x06": - print "Got:\n%s" % util.hexprint(result) + LOG.debug("Got:\n%s" % util.hexprint(result)) raise errors.RadioError("Radio did not finish cleanly")
@@ -241,7 +241,7 @@ def _send(radio, cmd, addr, length, data=None): if data: result = radio.pipe.read(1) if result != "\x06": - print "Ack was: %s" % repr(result) + LOG.debug("Ack was: %s" % repr(result)) raise errors.RadioError( "Radio did not accept block at %04x" % addr) return @@ -251,18 +251,18 @@ def _send(radio, cmd, addr, length, data=None): data = result[4:-2] ack = result[-1] if ack != "\x06": - print "Ack was: %s" % repr(ack) + LOG.debug("Ack was: %s" % repr(ack)) raise errors.RadioError("Radio NAK'd block at %04x" % addr) _cmd, _addr, _length = struct.unpack(">cHb", header) if _addr != addr or _length != _length: - print "Expected/Received:" - print " Length: %02x/%02x" % (length, _length) - print " Addr: %04x/%04x" % (addr, _addr) + LOG.debug("Expected/Received:") + LOG.debug(" Length: %02x/%02x" % (length, _length)) + LOG.debug(" Addr: %04x/%04x" % (addr, _addr)) raise errors.RadioError("Radio send unexpected block") cs = _checksum(result[1:-2]) if cs != ord(result[-2]): - print "Calculated: %02x" % cs - print "Actual: %02x" % ord(result[-2]) + LOG.debug("Calculated: %02x" % cs) + LOG.debug("Actual: %02x" % ord(result[-2])) raise errors.RadioError("Block at 0x%04x failed checksum" % addr) return data
diff --git a/chirp/drivers/ap510.py b/chirp/drivers/ap510.py index ae2ffe6..d7b3ff2 100644 --- a/chirp/drivers/ap510.py +++ b/chirp/drivers/ap510.py @@ -15,6 +15,7 @@
import struct from time import sleep +import logging
from chirp import chirp_common, directory, errors, util from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -22,6 +23,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ InvalidValueError, RadioSettings
+LOG = logging.getLogger(__name__) +
def chunks(s, t): """ Yield chunks of s in sizes defined in t.""" @@ -91,8 +94,8 @@ def download(radio): else: raise errors.RadioError("Incomplete data received.")
- print "%04i P<R: %s" % ( - len(buf), util.hexprint(buf).replace("\n", "\n ")) + LOG.debug("%04i P<R: %s" % + (len(buf), util.hexprint(buf).replace("\n", "\n "))) return buf
@@ -189,7 +192,7 @@ class AP510Memory(object): if '=' in line: data.append(line.split('=', 1)) self._memobj = dict(data) - print self.version + LOG.debug(self.version)
def __getattr__(self, name): if hasattr(self, 'get_%s' % name): @@ -751,7 +754,7 @@ class AP510Radio(chirp_common.CloneModeRadio): multiple['tf_card'] = TF_CARD.index(str(setting.value)) self._mmap.multiple = multiple except: - print setting.get_name() + LOG.debug(setting.get_name()) raise
def set_callsign(self, callsign=None, ssid=None): diff --git a/chirp/drivers/baofeng_uv3r.py b/chirp/drivers/baofeng_uv3r.py index 7b5ac60..7c72a96 100644 --- a/chirp/drivers/baofeng_uv3r.py +++ b/chirp/drivers/baofeng_uv3r.py @@ -17,6 +17,8 @@
import time import os +import logging + from wouxun_common import do_download, do_upload from chirp import util, chirp_common, bitwise, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -24,6 +26,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettingValueFloat, RadioSettings
+LOG = logging.getLogger(__name__) +
def _uv3r_prep(radio): radio.pipe.write("\x05PROGRAM") @@ -34,7 +38,7 @@ def _uv3r_prep(radio): radio.pipe.write("\x02") ident = radio.pipe.read(8) if len(ident) != 8: - print util.hexprint(ident) + LOG.debug(util.hexprint(ident)) raise errors.RadioError("Radio did not send identification")
radio.pipe.write("\x06") @@ -260,7 +264,7 @@ class UV3RRadio(chirp_common.CloneModeRadio): mem.dtcs = tcode txmode = "DTCS" else: - print "Bug: tx_mode is %02x" % _mem.txtone + LOG.warn("Bug: tx_mode is %02x" % _mem.txtone)
if _mem.rxtone in [0, 0xFF]: rxmode = "" @@ -272,7 +276,7 @@ class UV3RRadio(chirp_common.CloneModeRadio): mem.dtcs = rcode rxmode = "DTCS" else: - print "Bug: rx_mode is %02x" % _mem.rxtone + LOG.warn("Bug: rx_mode is %02x" % _mem.rxtone)
if txmode == "Tone" and not rxmode: mem.tmode = "Tone" @@ -613,13 +617,13 @@ class UV3RRadio(chirp_common.CloneModeRadio): setting = element.get_name()
if element.has_apply_callback(): - print "Using apply callback" + LOG.debug("Using apply callback") element.run_apply_callback() else: - print "Setting %s = %s" % (setting, element.value) + LOG.debug("Setting %s = %s" % (setting, element.value)) setattr(obj, setting, element.value) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
def _set_fm_preset(self, settings): @@ -631,11 +635,11 @@ class UV3RRadio(chirp_common.CloneModeRadio): value = int(val[1].get_value() * 10 - 650) else: value = 0x01AF - print "Setting fm_presets[%1i] = %s" % (index, value) + LOG.debug("Setting fm_presets[%1i] = %s" % (index, value)) setting = self._memobj.fm_presets setting[index] = value except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
@classmethod diff --git a/chirp/drivers/bjuv55.py b/chirp/drivers/bjuv55.py index e5c2377..fc9f43c 100644 --- a/chirp/drivers/bjuv55.py +++ b/chirp/drivers/bjuv55.py @@ -18,6 +18,7 @@ import struct import time import os +import logging
from chirp.drivers import uv5r from chirp import chirp_common, errors, util, directory, memmap @@ -28,6 +29,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
+LOG = logging.getLogger(__name__) +
BJUV55_MODEL = "\x50\xBB\xDD\x55\x63\x98\x4D"
@@ -642,8 +645,8 @@ class BaojieBJUV55Radio(uv5r.BaofengUV5R): try: val = element.value value = int(val.get_value() * 10 - 870) - print "Setting fm_preset = %s" % (value) + LOG.debug("Setting fm_preset = %s" % (value)) self._memobj.fm_preset = value except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise