# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID e6b88ed8e34f0d051c38a6052ca26f3d812bf62c
Use logging in drivers/ft*.py (#2347)
diff --git a/chirp/drivers/ft1d.py b/chirp/drivers/ft1d.py index a17bdee..9897ab6 100644 --- a/chirp/drivers/ft1d.py +++ b/chirp/drivers/ft1d.py @@ -429,17 +429,17 @@ class FT1BankModel(chirp_common.BankModel): vfo_bak = self._radio._memobj.vfo_info[(vfo_index * 2) + 1]
if vfo.checksum != vfo_bak.checksum: - print "Warning: VFO settings are inconsistent with backup" + LOG.warn("VFO settings are inconsistent with backup") else: if ((chosen_bank[vfo_index] is None) and (vfo.bank_index != 0xFFFF)): - print "Disabling banks for VFO %d" % vfo_index + LOG.info("Disabling banks for VFO %d" % vfo_index) vfo.bank_index = 0xFFFF vfo.mr_index = 0xFFFF vfo.bank_enable = 0xFFFF elif ((chosen_bank[vfo_index] is not None) and (vfo.bank_index == 0xFFFF)): - print "Enabling banks for VFO %d" % vfo_index + LOG.info("Enabling banks for VFO %d" % vfo_index) vfo.bank_index = chosen_bank[vfo_index] vfo.mr_index = chosen_mr[vfo_index] vfo.bank_enable = 0x0000 @@ -982,7 +982,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): # There is probably a more pythonesque way to do this if int(aprs_meta[index].sender_callsign[0]) != 255: callsign = str(aprs_meta[index].sender_callsign).rstrip("\xFF") - # print "Callsign %s %s" % ( callsign, list(callsign) ) + # LOG.debug("Callsign %s %s" % (callsign, list(callsign))) val = RadioSettingValueString(0, 9, callsign) rs = RadioSetting( "aprs_beacon.src_callsign%d" % index, @@ -1019,7 +1019,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): path = ''.join(c for c in path if c in string.printable).strip() path = str(path).replace("\xE0", "*") - # print "path %s %s" % ( path, list(path) ) + # LOG.debug("path %s %s" % (path, list(path))) val = RadioSettingValueString(0, 32, path) rs = RadioSetting( "aprs_beacon.path%d" % index, "Digipath", val) @@ -1033,7 +1033,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): try: val = RadioSettingValueString(0, 134, body.strip()) except Exception as e: - print "Error in APRS beacon at index", index + LOG.error("Error in APRS beacon at index %s", index) raise e rs = RadioSetting("aprs_beacon.body%d" % index, "Body", val) menu.append(rs) @@ -1487,8 +1487,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): 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
@staticmethod @@ -1578,11 +1577,11 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): continue try: if element.has_apply_callback(): - print "Using apply callback" + LOG.debug("Using apply callback") try: element.run_apply_callback() except NotImplementedError as e: - print e + LOG.error(e) continue
# Find the object containing setting. @@ -1603,10 +1602,10 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): 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" % ( - element.get_name(), e) + LOG.error("Setting %s is not in the memory map: %s" % + (element.get_name(), e)) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
def apply_ff_padded_yaesu(cls, setting, obj): diff --git a/chirp/drivers/ft2800.py b/chirp/drivers/ft2800.py index 52efe27..9c39ad1 100644 --- a/chirp/drivers/ft2800.py +++ b/chirp/drivers/ft2800.py @@ -59,9 +59,9 @@ def _download(radio): chunk = radio.pipe.read(38) LOG.debug("Got: %i:\n%s" % (len(chunk), util.hexprint(chunk))) if len(chunk) == 8: - print "END?" + LOG.debug("END?") elif len(chunk) != 38: - print "Should fail?" + LOG.debug("Should fail?") break # raise Exception("Failed to get full data block") else: @@ -91,7 +91,7 @@ def _upload(radio): data = radio.pipe.read(256) if not data: break - print "What is this garbage?\n%s" % util.hexprint(data) + LOG.debug("What is this garbage?\n%s" % util.hexprint(data))
_send(radio.pipe, IDBLOCK) time.sleep(1) @@ -203,7 +203,7 @@ class FT2800Radio(YaesuCloneModeRadio): raise except Exception, e: raise errors.RadioError("Failed to communicate with radio: %s" % e) - print "Downloaded in %.2f sec" % (time.time() - start) + LOG.info("Downloaded in %.2f sec" % (time.time() - start)) self.process_mmap()
def sync_out(self): @@ -216,7 +216,7 @@ class FT2800Radio(YaesuCloneModeRadio): raise except Exception, e: raise errors.RadioError("Failed to communicate with radio: %s" % e) - print "Uploaded in %.2f sec" % (time.time() - start) + LOG.info("Uploaded in %.2f sec" % (time.time() - start))
def process_mmap(self): self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) diff --git a/chirp/drivers/ft50_ll.py b/chirp/drivers/ft50_ll.py index 7d93d62..abf4b48 100644 --- a/chirp/drivers/ft50_ll.py +++ b/chirp/drivers/ft50_ll.py @@ -15,6 +15,9 @@
from chirp import chirp_common, util, errors, memmap import time +import logging + +LOG = logging.getLogger(__name__)
ACK = chr(0x06)
@@ -49,11 +52,11 @@ def read_exact(s, count): i = 0 while len(data) < count: if i == 3: - print util.hexprint(data) + LOG.debug(util.hexprint(data)) raise errors.RadioError("Failed to read %i (%i) from radio" % (count, len(data))) elif i > 0: - print "Retry %i" % i + LOG.info("Retry %i" % i) data += s.read(count - len(data)) i += 1
@@ -66,7 +69,7 @@ def download(radio): radio.pipe.setTimeout(1)
for block in radio._block_lengths: - print "Doing block %i" % block + LOG.debug("Doing block %i" % block) if block > 112: step = 16 else: @@ -74,9 +77,9 @@ def download(radio): for i in range(0, block, step): # data += read_exact(radio.pipe, step) chunk = radio.pipe.read(step*2) - print "Length of chunk: %i" % len(chunk) + LOG.debug("Length of chunk: %i" % len(chunk)) data += chunk - print "Reading %i" % i + LOG.debug("Reading %i" % i) time.sleep(0.1) send(radio.pipe, ACK) if radio.status_fn: @@ -88,10 +91,10 @@ def download(radio):
r = radio.pipe.read(100) send(radio.pipe, ACK) - print "R: %i" % len(r) - print util.hexprint(r) + LOG.debug("R: %i" % len(r)) + LOG.debug(util.hexprint(r))
- print "Got: %i Expecting %i" % (len(data), radio._memsize) + LOG.debug("Got: %i Expecting %i" % (len(data), radio._memsize))
return memmap.MemoryMap(data)
@@ -176,7 +179,7 @@ def get_offset(mmap):
def set_offset(mmap, offset): val = util.bcd_encode(int(offset * 1000), width=4)[:3] - print "Offfset:\n%s" % util.hexprint(val) + LOG.debug("Offset:\n%s" % util.hexprint(val)) mmap[POS_OFFSET] = val
@@ -312,5 +315,5 @@ def update_checksum(map): for i in range(0, 3722): cs += ord(map[i]) cs %= 256 - print "Checksum old=%02x new=%02x" % (ord(map[3722]), cs) + LOG.debug("Checksum old=%02x new=%02x" % (ord(map[3722]), cs)) map[3722] = cs diff --git a/chirp/drivers/ft60.py b/chirp/drivers/ft60.py index 1dc11d5..6c53a5b 100644 --- a/chirp/drivers/ft60.py +++ b/chirp/drivers/ft60.py @@ -47,7 +47,7 @@ def _download(radio): elif chunk: raise Exception("Received invalid response from radio") time.sleep(1) - print "Trying again..." + LOG.info("Trying again...")
if not data: raise Exception("Radio is not responding") @@ -128,7 +128,7 @@ def _decode_name(mem): try: name += CHARSET[i] except IndexError: - print "Unknown char index: %i " % (i) + LOG.error("Unknown char index: %i " % (i)) return name
@@ -655,7 +655,7 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio): value = element.value
if element.has_apply_callback(): - print "Using apply callback" + LOG.debug("Using apply callback") element.run_apply_callback() else: obj = getattr(_settings, name) @@ -663,7 +663,7 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio):
LOG.debug("Setting %s: %s" % (name, value)) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
def get_raw_memory(self, number): diff --git a/chirp/drivers/ft7800.py b/chirp/drivers/ft7800.py index 3e21d57..a391a8b 100644 --- a/chirp/drivers/ft7800.py +++ b/chirp/drivers/ft7800.py @@ -211,8 +211,8 @@ def _upload(radio): for block in radio._block_lengths: for _i in range(0, block, radio._block_size): length = min(radio._block_size, block) - # print "i=%i length=%i range: %i-%i" % (i, length, - # cur, cur+length) + # LOG.debug("i=%i length=%i range: %i-%i" % + # (i, length, cur, cur+length)) _send(radio.pipe, radio.get_mmap()[cur:cur+length]) if radio.pipe.read(1) != ACK: raise errors.RadioError("Radio did not ack block at %i" % cur) @@ -323,7 +323,7 @@ class FTx800Radio(yaesu_clone.YaesuCloneModeRadio): raise except Exception, e: raise errors.RadioError("Failed to communicate with radio: %s" % e) - print "Download finished in %i seconds" % (time.time() - start) + LOG.info("Download finished in %i seconds" % (time.time() - start)) self.check_checksums() self.process_mmap()
@@ -339,7 +339,7 @@ class FTx800Radio(yaesu_clone.YaesuCloneModeRadio): raise except Exception, e: raise errors.RadioError("Failed to communicate with radio: %s" % e) - print "Upload finished in %i seconds" % (time.time() - start) + LOG.info("Upload finished in %i seconds" % (time.time() - start))
def get_raw_memory(self, number): return repr(self._memobj.memory[number-1]) @@ -767,7 +767,7 @@ class FT7800Radio(FTx800Radio): LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
MEM_FORMAT_8800 = """ diff --git a/chirp/drivers/ft817.py b/chirp/drivers/ft817.py index d571caf..1dd94bf 100644 --- a/chirp/drivers/ft817.py +++ b/chirp/drivers/ft817.py @@ -362,7 +362,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): "but the radio is a US one. " "Please choose the correct model and try again."))
- print "Clone completed in %i seconds" % (time.time() - start) + LOG.info("Clone completed in %i seconds" % (time.time() - start))
return memmap.MemoryMap(data)
@@ -405,7 +405,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): status.cur = blocks self.status_fn(status)
- print "Clone completed in %i seconds" % (time.time() - start) + LOG.info("Clone completed in %i seconds" % (time.time() - start))
def sync_in(self): try: @@ -661,7 +661,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): else: # radio have some graphical chars that are not supported # we replace those with a * - print "Replacing char %x with *" % i + LOG.info("Replacing char %x with *" % i) mem.name += "*" mem.name = mem.name.rstrip() else: @@ -1095,7 +1095,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): else: setattr(obj, setting, element.value) except: - print element.get_name() + LOG.debug(element.get_name()) raise
diff --git a/chirp/drivers/ft857.py b/chirp/drivers/ft857.py index eec4d5a..ca00e30 100644 --- a/chirp/drivers/ft857.py +++ b/chirp/drivers/ft857.py @@ -1093,7 +1093,7 @@ class FT857Radio(ft817.FT817Radio): else: setattr(obj, setting, element.value) except: - print element.get_name() + LOG.debug(element.get_name()) raise
diff --git a/chirp/drivers/ft90.py b/chirp/drivers/ft90.py index 3f5e2c6..f777d94 100644 --- a/chirp/drivers/ft90.py +++ b/chirp/drivers/ft90.py @@ -278,8 +278,8 @@ struct { status.cur = blocknum self.status_fn(status)
- print "Clone completed in %i seconds, blocks read: %i" % \ - (time.time() - start, blocknum) + LOG.info("Clone completed in %i seconds, blocks read: %i" % + (time.time() - start, blocknum))
return memmap.MemoryMap(data)
@@ -325,7 +325,7 @@ struct { status.cur = blocknum self.status_fn(status)
- print "Clone completed in %i seconds" % (time.time() - start) + LOG.info("Clone completed in %i seconds" % (time.time() - start))
def sync_in(self): try: @@ -671,5 +671,5 @@ struct { LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise diff --git a/chirp/drivers/ftm350.py b/chirp/drivers/ftm350.py index f1a0b69..fde98f7 100644 --- a/chirp/drivers/ftm350.py +++ b/chirp/drivers/ftm350.py @@ -141,8 +141,8 @@ def _clone_in(radio): for i in frame[:-1]: cs = (cs + ord(i)) % 256 if cs != checksum: - print "Calc: %02x Real: %02x Len: %i" % (cs, checksum, - len(block)) + LOG.debug("Calc: %02x Real: %02x Len: %i" % + (cs, checksum, len(block))) raise errors.RadioError("Block failed checksum")
radio.pipe.write("\x06")