# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID fda8ac4f6f03be45ec1cda8b1cb1a3e7ef8c506b
Use logging in drivers/[lp]*.py (#2347)
diff --git a/chirp/drivers/leixen.py b/chirp/drivers/leixen.py index 97ab555..f8d85b5 100644 --- a/chirp/drivers/leixen.py +++ b/chirp/drivers/leixen.py @@ -15,6 +15,7 @@
import struct import os +import logging
from chirp import chirp_common, directory, memmap, errors, util from chirp import bitwise @@ -24,6 +25,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x0184; struct { @@ -252,8 +255,9 @@ def make_frame(cmd, addr, data=""):
def send(radio, frame): - # print "%04i P>R: %s" % \ - # (len(frame), util.hexprint(frame).replace("\n", "\n ")) + # LOG.debug("%04i P>R: %s" % + # (len(frame), + # util.hexprint(frame).replace("\n", "\n "))) try: radio.pipe.write(frame) except Exception, e: @@ -262,16 +266,16 @@ def send(radio, frame):
def recv(radio, readdata=True): hdr = radio.pipe.read(4) - # print "%04i P<R: %s" % \ - # (len(hdr), util.hexprint(hdr).replace("\n", "\n ")) + # LOG.debug("%04i P<R: %s" % + # (len(hdr), util.hexprint(hdr).replace("\n", "\n "))) if hdr == "\x09\x00\x09": raise errors.RadioError("Radio rejected command.") cmd, length, addr = struct.unpack(">BBH", hdr) length -= 2 if readdata: data = radio.pipe.read(length) - # print " P<R: %s" % \ - # util.hexprint(hdr + data).replace("\n", "\n ") + # LOG.debug(" P<R: %s" % + # util.hexprint(hdr + data).replace("\n", "\n ")) if len(data) != length: raise errors.RadioError("Radio sent %i bytes (expected %i)" % ( len(data), length)) @@ -284,7 +288,8 @@ def recv(radio, readdata=True): def do_ident(radio): send(radio, "\x02\x06LEIXEN\x17") ident = radio.pipe.read(9) - print " P<R: %s" % util.hexprint(ident).replace("\n", "\n ") + LOG.debug(" P<R: %s" % + util.hexprint(ident).replace("\n", "\n ")) if ident != "\x06\x06leixen\x13": raise errors.RadioError("Radio refused program mode") radio.pipe.write("\x06\x00\x06") @@ -329,8 +334,8 @@ def do_upload(radio): for addr in range(start, end, 0x10): frame = make_frame("W", addr, radio._mmap[addr:addr + 0x10]) send(radio, frame) - # print " P<R: %s" % \ - # util.hexprint(frame).replace("\n", "\n ") + # LOG.debug(" P<R: %s" % + # util.hexprint(frame).replace("\n", "\n ")) radio.pipe.write("\x06\x00\x06") ack = radio.pipe.read(3) if ack != "\x06\x00\x06": @@ -592,7 +597,7 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): filtered += char else: filtered += " " - print "Filtered: %s" % filtered + LOG.debug("Filtered: %s" % filtered) return filtered
rs = RadioSetting("messages.user1", "User-defined Message 1", @@ -780,8 +785,7 @@ class LeixenVV898Radio(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): @@ -809,7 +813,7 @@ class LeixenVV898Radio(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 == "keylock_off": setattr(obj, setting, not int(element.value)) @@ -840,10 +844,10 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): elif setting == "lptime": setattr(obj, setting, int(element.value) + 5) 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
@classmethod diff --git a/chirp/drivers/puxing.py b/chirp/drivers/puxing.py index 1295123..7a1ad55 100644 --- a/chirp/drivers/puxing.py +++ b/chirp/drivers/puxing.py @@ -17,9 +17,13 @@
import time import os +import logging + from chirp import util, chirp_common, bitwise, errors, directory from chirp.drivers.wouxun import wipe_memory, do_download, do_upload
+LOG = logging.getLogger(__name__) +
def _puxing_prep(radio): radio.pipe.write("\x02PROGRA") @@ -30,7 +34,7 @@ def _puxing_prep(radio): radio.pipe.write("M\x02") ident = radio.pipe.read(8) if len(ident) != 8: - print util.hexprint(ident) + LOG.debug(util.hexprint(ident)) raise Exception("Radio did not send identification")
radio.pipe.write("\x06") @@ -173,8 +177,8 @@ class Puxing777Radio(chirp_common.CloneModeRadio): try: rf.valid_bands = [PUXING_777_BANDS[limit_idx]] except IndexError: - print "Invalid band index %i (0x%02x)" % \ - (limit_idx, self._memobj.model.limits) + LOG.error("Invalid band index %i (0x%02x)" % + (limit_idx, self._memobj.model.limits)) rf.valid_bands = [PUXING_777_BANDS[1]] elif self._memobj.model.model == PUXING_MODELS[328]: # There are PX-777 that says to be model 328 ... @@ -356,7 +360,7 @@ def puxing_2r_prep(radio):
radio.pipe.write(ack) ident = radio.pipe.read(16) - print "Radio ident: %s (%i)" % (repr(ident), len(ident)) + LOG.info("Radio ident: %s (%i)" % (repr(ident), len(ident)))
def puxing_2r_download(radio): @@ -475,8 +479,8 @@ class Puxing2RRadio(chirp_common.CloneModeRadio): try: mem.name += PX2R_CHARSET[i] except Exception: - print "Unknown name char %i: 0x%02x (mem %i)" % (count, - i, number) + LOG.error("Unknown name char %i: 0x%02x (mem %i)" % + (count, i, number)) mem.name += " " count += 1 mem.name = mem.name.rstrip()