# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 07fe6f3bd0e63cebcdaabbbab4ec120f1480dfa5
Use logging in uv*.py (#2347)
diff --git a/chirp/drivers/uv5r.py b/chirp/drivers/uv5r.py index 2f6ddad..8ed1c51 100644 --- a/chirp/drivers/uv5r.py +++ b/chirp/drivers/uv5r.py @@ -418,7 +418,7 @@ def _do_ident(radio, magic): serial = radio.pipe serial.setTimeout(1)
- print "Sending Magic: %s" % util.hexprint(magic) + LOG.info("Sending Magic: %s" % util.hexprint(magic)) for byte in magic: serial.write(byte) time.sleep(0.01) @@ -426,13 +426,13 @@ def _do_ident(radio, magic):
if ack != "\x06": if ack: - print repr(ack) + LOG.debug(repr(ack)) raise errors.RadioError("Radio did not respond")
serial.write("\x02") ident = serial.read(8)
- print "Ident:\n%s" % util.hexprint(ident) + LOG.info("Ident: %s" % util.hexprint(ident))
serial.write("\x06") ack = serial.read(1) @@ -452,15 +452,15 @@ def _read_block(radio, start, size):
cmd, addr, length = struct.unpack(">BHB", answer) if cmd != ord("X") or addr != start or length != size: - print "Invalid answer for block 0x%04x:" % start - print "CMD: %s ADDR: %04x SIZE: %02x" % (cmd, addr, length) + LOG.error("Invalid answer for block 0x%04x:" % start) + LOG.debug("CMD: %s ADDR: %04x SIZE: %02x" % (cmd, addr, length)) raise errors.RadioError("Unknown response from radio")
chunk = radio.pipe.read(0x40) if not chunk: raise errors.RadioError("Radio did not send block 0x%04x" % start) elif len(chunk) != size: - print "Chunk length was 0x%04i" % len(chunk) + LOG.error("Chunk length was 0x%04i" % len(chunk)) raise errors.RadioError("Radio sent incomplete block 0x%04x" % start)
radio.pipe.write("\x06") @@ -497,7 +497,7 @@ def _ident_radio(radio): data = _do_ident(radio, magic) return data except errors.RadioError, e: - print e + LOG.error(e) error = e time.sleep(2) if error: @@ -509,7 +509,7 @@ def _do_download(radio): data = _ident_radio(radio)
radio_version = _get_radio_firmware_version(radio) - print "Radio Version is %s" % repr(radio_version) + LOG.info("Radio Version is %s" % repr(radio_version))
if not any(type in radio_version for type in radio._basetype): raise errors.RadioError("Incorrect 'Model' selected.") @@ -548,8 +548,8 @@ def _do_upload(radio):
image_version = _firmware_version_from_image(radio) radio_version = _get_radio_firmware_version(radio) - print "Image Version is %s" % repr(image_version) - print "Radio Version is %s" % repr(radio_version) + LOG.info("Image Version is %s" % repr(image_version)) + LOG.info("Radio Version is %s" % repr(radio_version))
if not any(type in radio_version for type in BASETYPE_LIST): raise errors.RadioError("Unsupported firmware version: `%s'" % @@ -557,8 +557,8 @@ def _do_upload(radio):
image_special_block = _special_block_from_image(radio) radio_special_block = _get_radio_special_block(radio) - print "Image Special Block is " + util.hexprint(image_special_block) - print "Radio Special Block is " + util.hexprint(radio_special_block) + LOG.debug("Image Special Block is " + util.hexprint(image_special_block)) + LOG.debug("Radio Special Block is " + util.hexprint(radio_special_block))
if image_special_block != radio_special_block: raise errors.RadioError("Image not supported by radio: `%s'" % @@ -570,7 +570,7 @@ def _do_upload(radio): _do_status(radio, i)
if len(radio.get_mmap().get_packed()) == 0x1808: - print "Old image, not writing aux block" + LOG.info("Old image, not writing aux block") return # Old image, no aux block
if image_version != radio_version: @@ -776,7 +776,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, index = _mem.txtone - 1 mem.dtcs = UV5R_DTCS[index] else: - print "Bug: txtone is %04x" % _mem.txtone + LOG.warn("Bug: txtone is %04x" % _mem.txtone)
if _mem.rxtone in [0, 0xFFFF]: rxmode = "" @@ -792,7 +792,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, index = _mem.rxtone - 1 mem.rx_dtcs = UV5R_DTCS[index] else: - print "Bug: rxtone is %04x" % _mem.rxtone + LOG.warn("Bug: rxtone is %04x" % _mem.rxtone)
if txmode == "Tone" and not rxmode: mem.tmode = "Tone" @@ -816,8 +816,8 @@ class BaofengUV5R(chirp_common.CloneModeRadio, try: mem.power = levels[_mem.lowpower] except IndexError: - print "Radio reported invalid power level %s (in %s)" % \ - (_mem.power, levels) + LOG.error("Radio reported invalid power level %s (in %s)" % + (_mem.power, levels)) mem.power = levels[0]
mem.mode = _mem.wide and "FM" or "NFM" @@ -1551,8 +1551,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, return self._get_settings() except: import traceback - print "Failed to parse settings:" - traceback.print_exc() + LOG.error("Failed to parse settings: %s", traceback.format_exc()) return None
def set_settings(self, settings): @@ -1583,13 +1582,13 @@ class BaofengUV5R(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): @@ -1597,10 +1596,10 @@ class BaofengUV5R(chirp_common.CloneModeRadio, try: val = element.value value = int(val.get_value() * 10 - 650) - print "Setting fm_presets = %s" % (value) + LOG.debug("Setting fm_presets = %s" % (value)) self._memobj.fm_presets = value except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
diff --git a/chirp/drivers/uvb5.py b/chirp/drivers/uvb5.py index d336a06..8f997b2 100644 --- a/chirp/drivers/uvb5.py +++ b/chirp/drivers/uvb5.py @@ -14,6 +14,7 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import struct +import logging from chirp import chirp_common, directory, bitwise, memmap, errors, util from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ @@ -21,6 +22,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, RadioSettings from textwrap import dedent
+LOG = logging.getLogger(__name__) + mem_format = """ struct memory { lbcd freq[4]; @@ -178,7 +181,7 @@ def do_ident(radio): raise errors.RadioError("Radio did not ack programming mode") radio.pipe.write("\x02") ident = radio.pipe.read(8) - print util.hexprint(ident) + LOG.debug(util.hexprint(ident)) if not ident.startswith('HKT511'): raise errors.RadioError("Unsupported model") radio.pipe.write("\x06") @@ -205,7 +208,7 @@ def do_download(radio): radio.pipe.write(frame) result = radio.pipe.read(20) if frame[1:4] != result[1:4]: - print util.hexprint(result) + LOG.debug(util.hexprint(result)) raise errors.RadioError("Invalid response for address 0x%04x" % i) radio.pipe.write("\x06") ack = radio.pipe.read(1) @@ -213,8 +216,8 @@ def do_download(radio): firstack = ack else: if not ack == firstack: - print "first ack:", util.hexprint(firstack), \ - "ack received:", util.hexprint(ack) + LOG.debug("first ack: %s ack received: %s", + util.hexprint(firstack), util.hexprint(ack)) raise errors.RadioError("Unexpected response") data += result[4:] do_status(radio, "from", i) @@ -755,17 +758,17 @@ class BaofengUVB5(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() elif setting == "beep_tone_disabled": setattr(obj, setting, not int(element.value)) elif setting == "ste_disabled": setattr(obj, setting, not int(element.value)) 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): @@ -777,11 +780,11 @@ class BaofengUVB5(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