[chirp_devel] [PATCH 00/17] change prints to logging calls
This series primarily converts all of the remaining print calls to logging calls, creating a LOG object in each module if necessary. Once again, I used my best judgement, but others might find that the log message levels need to be adjusted for optimal effectiveness.
It also updates the run_tests to initialize the logger module, as that ensures that handers are set up properly and output is diverted away from the console.
Zachary T Welch (17): Use logging in run_tests (#2347) Use logging in mainapp.py (#2347) Use logging in yaeosu_clone.py (#2347) Use logging in wouxun*.py (#2347) Use logging in vx*.py (#2347) Use logging in uv*.py (#2347) Use logging in drivers/t*.py (#2347) Use logging in rfinder.py (#2347) Use logging in drivers/[lp]*.py (#2347) Use logging in kenwood*.py (#2347) Use logging in drivers/k*.py (#2347) Use logging in idrp.py (#2347) Use logging in ic9x*.py (#2347) Use logging in icf.py (#2347) Use logging in drivers/ft*.py (#2347) Use logging in drivers/[ab]*.py (#2347) Use logging in drivers/[hi]*.py (#2347)
chirp/drivers/alinco.py | 23 +++++++++++--------- chirp/drivers/anytone.py | 30 +++++++++++++------------- chirp/drivers/ap510.py | 11 ++++++---- chirp/drivers/baofeng_uv3r.py | 20 +++++++++++------- chirp/drivers/bjuv55.py | 7 ++++-- chirp/drivers/ft1d.py | 25 +++++++++++----------- chirp/drivers/ft2800.py | 10 ++++----- chirp/drivers/ft50_ll.py | 23 +++++++++++--------- chirp/drivers/ft60.py | 8 +++---- chirp/drivers/ft7800.py | 10 ++++----- chirp/drivers/ft817.py | 8 +++---- chirp/drivers/ft857.py | 2 +- chirp/drivers/ft90.py | 8 +++---- chirp/drivers/ftm350.py | 4 ++-- chirp/drivers/h777.py | 10 ++++----- chirp/drivers/ic9x.py | 16 ++++++++------ chirp/drivers/ic9x_ll.py | 24 ++++++++++++--------- chirp/drivers/icf.py | 48 ++++++++++++++++++++++-------------------- chirp/drivers/icomciv.py | 29 +++++++++++++------------ chirp/drivers/icq7.py | 13 ++++++++---- chirp/drivers/icw32.py | 8 +++++-- chirp/drivers/icx8x.py | 8 +++++-- chirp/drivers/idrp.py | 2 +- chirp/drivers/kenwood_hmk.py | 12 +++++++---- chirp/drivers/kenwood_itm.py | 12 +++++++---- chirp/drivers/kenwood_live.py | 16 +++++++------- chirp/drivers/kguv8d.py | 11 +++++----- chirp/drivers/kyd.py | 20 +++++++++--------- chirp/drivers/leixen.py | 34 +++++++++++++++++------------- chirp/drivers/puxing.py | 16 ++++++++------ chirp/drivers/rfinder.py | 27 ++++++++++++------------ chirp/drivers/th9800.py | 14 ++++++------ chirp/drivers/th_uv3r.py | 5 ++++- chirp/drivers/th_uvf8d.py | 8 ++++--- chirp/drivers/thd72.py | 10 ++++----- chirp/drivers/thuv1f.py | 11 ++++++---- chirp/drivers/tk8102.py | 8 +++---- chirp/drivers/tmv71.py | 5 ++++- chirp/drivers/tmv71_ll.py | 6 +++--- chirp/drivers/uv5r.py | 47 ++++++++++++++++++++--------------------- chirp/drivers/uvb5.py | 21 ++++++++++-------- chirp/drivers/vx2.py | 2 +- chirp/drivers/vx3.py | 2 +- chirp/drivers/vx5.py | 3 ++- chirp/drivers/vx7.py | 7 ++++-- chirp/drivers/vx8.py | 19 ++++++++--------- chirp/drivers/vxa700.py | 12 +++++------ chirp/drivers/wouxun.py | 32 +++++++++++++++------------- chirp/drivers/wouxun_common.py | 2 +- chirp/drivers/yaesu_clone.py | 14 ++++++------ chirp/ui/mainapp.py | 41 +++++++++++++++++------------------- tests/run_tests | 11 ++++++++++ 52 files changed, 426 insertions(+), 349 deletions(-)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 75131cd46ef28b4f69d88224eff4c538cc517cc0
Use logging in run_tests (#2347)
We need to use logging in run_tests, if only to catch the new output being generated by the drivers. This patch captures a debug.log for the entire test run while squelching output on the console. The prevents spurious error messages from being displayed. This may be improved upon in subsequent patches, but this is necessary to prevent anyone from seeing confusing output when running the tests.
diff --git a/tests/run_tests b/tests/run_tests index 9cc05b3..689fe92 100755 --- a/tests/run_tests +++ b/tests/run_tests @@ -31,6 +31,17 @@ os.chdir(scriptdir)
sys.path.insert(0, "../")
+import logging +from chirp import logger + +class LoggerOpts(object): + quiet = 2 + verbose = 0 + log_file = os.path.join('logs', 'debug.log') + log_level = logging.DEBUG + +logger.handle_options(LoggerOpts()) + from chirp import CHIRP_VERSION from chirp.drivers import * from chirp import chirp_common, directory
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 4da48c2ab5a52057cc3de317f1296297c819bdd9
Use logging in mainapp.py (#2347)
diff --git a/chirp/ui/mainapp.py b/chirp/ui/mainapp.py index 24f226d..707af99 100644 --- a/chirp/ui/mainapp.py +++ b/chirp/ui/mainapp.py @@ -211,8 +211,8 @@ class ChirpMain(gtk.Window): common.show_error("Can't diff the same tab!") return
- print "Selected %s@%i and %s@%i" % (sel_a, sel_chan_a, - sel_b, sel_chan_b) + LOG.debug("Selected %s@%i and %s@%i" % + (sel_a, sel_chan_a, sel_b, sel_chan_b)) name_a = os.path.basename(sel_a) name_a = name_a[:name_a.rindex(")")] name_b = os.path.basename(sel_b) @@ -352,7 +352,7 @@ of file. radio = self._do_manual_select(fname) if not radio: return - print "Manually selected %s" % radio + LOG.debug("Manually selected %s" % radio) except Exception, e: common.log_exception() common.show_error(os.path.basename(fname) + ": " + str(e)) @@ -545,9 +545,9 @@ of file. continue try: shutil.copy(fn, stock_dir) - print "Copying %s -> %s" % (fn, stock_dir) + LOG.debug("Copying %s -> %s" % (fn, stock_dir)) except Exception, e: - print "ERROR: Unable to copy %s to %s: %s" % (fn, stock_dir, e) + LOG.error("Unable to copy %s to %s: %s" % (fn, stock_dir, e)) return False return True
@@ -557,7 +557,7 @@ of file. try: os.mkdir(stock_dir) except Exception, e: - print "ERROR: Unable to create directory: %s" % stock_dir + LOG.error("Unable to create directory: %s" % stock_dir) return if not self.copy_shipped_stock_configs(stock_dir): return @@ -661,9 +661,8 @@ of file.
self._show_instructions(rclass, rclass.get_prompts().pre_download)
- print "User selected %s %s on port %s" % (rclass.VENDOR, - rclass.MODEL, - settings.port) + LOG.debug("User selected %s %s on port %s" % + (rclass.VENDOR, rclass.MODEL, settings.port))
try: ser = serial.Serial(port=settings.port, @@ -702,7 +701,7 @@ of file. prompts = radio.get_prompts()
if prompts.display_pre_upload_prompt_before_opening_port is True: - print "Opening port after pre_upload prompt." + LOG.debug("Opening port after pre_upload prompt.") self._show_instructions(radio, prompts.pre_upload)
if isinstance(radio, chirp_common.ExperimentalRadio) and \ @@ -723,7 +722,7 @@ of file. return
if prompts.display_pre_upload_prompt_before_opening_port is False: - print "Opening port before pre_upload prompt." + LOG.debug("Opening port before pre_upload prompt.") self._show_instructions(radio, prompts.pre_upload)
radio.set_pipe(ser) @@ -911,8 +910,7 @@ of file. fn = tempfile.mktemp(".csv") filename, headers = urllib.urlretrieve(query, fn) if not os.path.exists(filename): - print "Failed, headers were:" - print str(headers) + LOG.error("Failed, headers were: %s", headers) common.show_error(_("RepeaterBook query failed")) self.window.set_cursor(None) return @@ -990,7 +988,7 @@ of file. args.append("=".join((name.replace(" ", "").lower(), contents))) query += "&".join(args) - print query + LOG.debug(query) d.destroy() return query
@@ -1005,8 +1003,7 @@ of file. fn = tempfile.mktemp(".csv") filename, headers = urllib.urlretrieve(url, fn) if not os.path.exists(filename): - print "Failed, headers were:" - print str(headers) + LOG.error("Failed, headers were: %s", str(headers)) common.show_error(_("Query failed")) return
@@ -1362,7 +1359,7 @@ of file. d.label.set_line_wrap(True) r = d.run() if r == gtk.RESPONSE_OK: - print "Chose language %s" % d.choice.get_active_text() + LOG.debug("Chose language %s" % d.choice.get_active_text()) conf = config.get() conf.set("language", d.choice.get_active_text(), "state") d.destroy() @@ -1641,7 +1638,7 @@ of file. num = self.tabs.get_n_pages() while num > 0: num -= 1 - print "Closing %i" % num + LOG.debug("Closing %i" % num) try: self.do_close(self.tabs.get_nth_page(num)) except ModifiedError: @@ -1701,7 +1698,7 @@ of file. if os.path.exists(path): self.set_icon_from_file(path) else: - print "Icon %s not found" % path + LOG.warn("Icon %s not found" % path)
def _updates(self, version): if not version: @@ -1710,7 +1707,7 @@ of file. if version == CHIRP_VERSION: return
- print "Server reports version %s is available" % version + LOG.info("Server reports version %s is available" % version)
# Report new updates every seven days intv = 3600 * 24 * 7 @@ -1735,7 +1732,7 @@ of file. import gtk_osxapplication macapp = gtk_osxapplication.OSXApplication() except ImportError, e: - print "No MacOS support: %s" % e + LOG.error("No MacOS support: %s" % e) return
menu_bar.hide() @@ -1753,7 +1750,7 @@ of file. macapp.set_use_quartz_accelerators(False) macapp.ready()
- print "Initialized MacOS support" + LOG.debug("Initialized MacOS support")
def __init__(self, *args, **kwargs): gtk.Window.__init__(self, *args, **kwargs)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 9f5b9ed71ed3df4ed9d4ad727db0583a9e872604
Use logging in yaeosu_clone.py (#2347)
diff --git a/chirp/drivers/yaesu_clone.py b/chirp/drivers/yaesu_clone.py index ddaa1d2..3b8b070 100644 --- a/chirp/drivers/yaesu_clone.py +++ b/chirp/drivers/yaesu_clone.py @@ -30,15 +30,15 @@ def _safe_read(pipe, count): first = True for _i in range(0, 60): buf += pipe.read(count - len(buf)) - # print "safe_read: %i/%i\n" % (len(buf), count) + # LOG.debug("safe_read: %i/%i\n" % (len(buf), count)) if buf: if first and buf[0] == chr(CMD_ACK): - # print "Chewed an ack" + # LOG.debug("Chewed an ack") buf = buf[1:] # Chew an echo'd ack if using a 2-pin cable first = False if len(buf) == count: break - print util.hexprint(buf) + LOG.debug(util.hexprint(buf)) return buf
@@ -50,7 +50,7 @@ def _chunk_read(pipe, count, status_fn): if data: if data[0] == chr(CMD_ACK): data = data[1:] # Chew an echo'd ack if using a 2-pin cable - # print "Chewed an ack" + # LOG.debug("Chewed an ack") status = chirp_common.Status() status.msg = "Cloning from radio" status.max = count @@ -81,7 +81,7 @@ def __clone_in(radio): if len(data) != radio.get_memsize(): raise errors.RadioError("Received incomplete image from radio")
- print "Clone completed in %i seconds" % (time.time() - start) + LOG.debug("Clone completed in %i seconds" % (time.time() - start))
return memmap.MemoryMap(data)
@@ -143,7 +143,7 @@ def __clone_out(radio):
pipe.read(pos) # Chew the echo if using a 2-pin cable
- print "Clone completed in %i seconds" % (time.time() - start) + LOG.debug("Clone completed in %i seconds" % (time.time() - start))
def _clone_out(radio): @@ -222,7 +222,7 @@ class YaesuCloneModeRadio(chirp_common.CloneModeRadio): if checksum.get_existing(self._mmap) != \ checksum.get_calculated(self._mmap): raise errors.RadioError("Checksum Failed [%s]" % checksum) - print "Checksum %s: OK" % checksum + LOG.debug("Checksum %s: OK" % checksum)
def sync_in(self): self._mmap = _clone_in(self)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 745d7b32a7e813e69ffd470907fd8e35b8c8356e
Use logging in wouxun*.py (#2347)
diff --git a/chirp/drivers/wouxun.py b/chirp/drivers/wouxun.py index dc03314..17f4b7a 100644 --- a/chirp/drivers/wouxun.py +++ b/chirp/drivers/wouxun.py @@ -50,7 +50,7 @@ def decode_freq(data): freq *= 10 freq += FREQ_ENCODE_TABLE.index((data >> shift) & 0xf) shift -= 4 - # print "data %04x freq %d shift %d" % (data, freq, shift) + # LOG.debug("data %04x freq %d shift %d" % (data, freq, shift)) return freq
@@ -245,8 +245,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, self.pipe.write(query.next()) resp = self.pipe.read(9) if len(resp) != 9: - print "Got:\n%s" % util.hexprint(resp) - print "Retrying identification..." + LOG.debug("Got:\n%s" % util.hexprint(resp)) + LOG.info("Retrying identification...") time.sleep(1) continue if resp[2:8] != self._model: @@ -297,7 +297,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio,
def process_mmap(self): if len(self._mmap.get_packed()) != 8192: - print "NOTE: Fixing old-style Wouxun image" + LOG.info("Fixing old-style Wouxun image") # Originally, CHIRP's wouxun image had eight bytes of # static data, followed by the first memory at offset # 0x0008. Between 0.1.11 and 0.1.12, this was fixed to 16 @@ -652,13 +652,13 @@ class KGUVD1PRadio(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): @@ -672,14 +672,15 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, value = int(val[1].get_value()*10-760) else: value = 0xffff - print "Setting fm_presets_%1i[%1i] = %s" % (bank, index, value) + LOG.debug("Setting fm_presets_%1i[%1i] = %s" % + (bank, index, value)) if bank == 0: setting = self._memobj.fm_presets_0 else: setting = self._memobj.fm_presets_1 setting[index] = value except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
def _set_freq_settings(self, settings): @@ -689,7 +690,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, element.get_name(), encode_freq(int(element.value))) except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
def get_raw_memory(self, number): @@ -1384,13 +1385,13 @@ class KGUV6DRadio(KGUVD1PRadio): 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): @@ -1404,14 +1405,15 @@ class KGUV6DRadio(KGUVD1PRadio): value = int(val[1].get_value()*10-760) else: value = 0xffff - print "Setting fm_presets_%1i[%1i] = %s" % (bank, index, value) + LOG.debug("Setting fm_presets_%1i[%1i] = %s" % + (bank, index, value)) if bank == 0: setting = self._memobj.fm_presets_0 else: setting = self._memobj.fm_presets_1 setting[index] = value except Exception, e: - print element.get_name() + LOG.debug(element.get_name()) raise
@classmethod diff --git a/chirp/drivers/wouxun_common.py b/chirp/drivers/wouxun_common.py index 9399eae..ec65d38 100644 --- a/chirp/drivers/wouxun_common.py +++ b/chirp/drivers/wouxun_common.py @@ -39,7 +39,7 @@ def do_download(radio, start, end, blocksize): length = len(cmd) + blocksize resp = radio.pipe.read(length) if len(resp) != (len(cmd) + blocksize): - print util.hexprint(resp) + LOG.debug(util.hexprint(resp)) raise Exception("Failed to read full block (%i!=%i)" % (len(resp), len(cmd) + blocksize))
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 8df3538abeffbee6d71f1d89eba9dced39c0864f
Use logging in vx*.py (#2347)
diff --git a/chirp/drivers/vx2.py b/chirp/drivers/vx2.py index b7beec1..dfec883 100644 --- a/chirp/drivers/vx2.py +++ b/chirp/drivers/vx2.py @@ -747,5 +747,5 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): 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/vx3.py b/chirp/drivers/vx3.py index b18e056..b187b79 100644 --- a/chirp/drivers/vx3.py +++ b/chirp/drivers/vx3.py @@ -961,5 +961,5 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): 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/vx5.py b/chirp/drivers/vx5.py index 1afe676..aa6d4bd 100644 --- a/chirp/drivers/vx5.py +++ b/chirp/drivers/vx5.py @@ -99,7 +99,8 @@ class VX5BankModel(chirp_common.BankModel): _bank_used = self._radio._memobj.bank_used[bank.index] for i in range(0, len(_members)): if _members[i].status == 0xFF: - # print "empty found, inserting %d at %d" % (memory.number, i) + # LOG.debug("empty found, inserting %d at %d" % + # (memory.number, i)) if self._radio._memobj.current_bank == 0xFF: self._radio._memobj.current_bank = bank.index _members[i].status = 0x00 diff --git a/chirp/drivers/vx7.py b/chirp/drivers/vx7.py index 8aab994..1d7b11a 100644 --- a/chirp/drivers/vx7.py +++ b/chirp/drivers/vx7.py @@ -16,6 +16,9 @@ from chirp.drivers import yaesu_clone from chirp import chirp_common, directory, bitwise from textwrap import dedent +import logging + +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0611; @@ -280,8 +283,8 @@ class VX7Radio(yaesu_clone.YaesuCloneModeRadio): try: mem.power = levels[_mem.power] 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]
for i in _mem.name: diff --git a/chirp/drivers/vx8.py b/chirp/drivers/vx8.py index e35d05c..d65e77c 100644 --- a/chirp/drivers/vx8.py +++ b/chirp/drivers/vx8.py @@ -415,17 +415,17 @@ class VX8BankModel(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.debug("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 @@ -1400,8 +1400,7 @@ class VX8DRadio(VX8Radio): 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 @@ -1491,11 +1490,11 @@ class VX8DRadio(VX8Radio): 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. @@ -1516,10 +1515,10 @@ class VX8DRadio(VX8Radio): 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/vxa700.py b/chirp/drivers/vxa700.py index a484754..3aa39d5 100644 --- a/chirp/drivers/vxa700.py +++ b/chirp/drivers/vxa700.py @@ -18,15 +18,13 @@ from chirp import bitwise
import time import struct +import logging
- -def _debug(string): - pass - print string +LOG = logging.getLogger(__name__)
def _send(radio, data): - _debug("Sending %s" % repr(data)) + LOG.debug("Sending %s" % repr(data)) radio.pipe.write(data) radio.pipe.flush() echo = radio.pipe.read(len(data)) @@ -46,7 +44,7 @@ def _spoonfeed(radio, data): # so just blindly send the data echo = radio.pipe.read(1) if echo != byte: - print "%02x != %02x" % (ord(echo), ord(byte)) + LOG.debug("%02x != %02x" % (ord(echo), ord(byte))) raise errors.RadioError("No echo?") # count += 1
@@ -105,7 +103,7 @@ def _upload(radio): ack = "\x06" time.sleep(0.5) if ack != "\x06": - print repr(ack) + LOG.debug(repr(ack)) raise errors.RadioError("Radio did not ack block %i" % (i / 132)) # radio.pipe.read(1) if radio.status_fn:
# 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
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 5b0844df84c456a6848b314a7ea1434679750683
Use logging in drivers/t*.py (#2347)
diff --git a/chirp/drivers/th9800.py b/chirp/drivers/th9800.py index 2d7e3c6..730594b 100644 --- a/chirp/drivers/th9800.py +++ b/chirp/drivers/th9800.py @@ -594,7 +594,7 @@ class TYTTH9800Base(chirp_common.Radio): 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
@@ -637,7 +637,7 @@ def _identify(radio): raise errors.RadioError("Radio did not ACK first command: %x" % ord(ack)) except: - print util.hexprint(ack) + LOG.debug(util.hexprint(ack)) raise errors.RadioError("Unable to communicate with the radio")
radio.pipe.write("M\x02") @@ -652,19 +652,19 @@ def _identify(radio): def _download(radio, memsize=0x10000, blocksize=0x80): """Download from TYT TH-9800""" data = _identify(radio) - print "ident:", util.hexprint(data) + LOG.info("ident:", util.hexprint(data)) offset = 0x100 for addr in range(offset, memsize, blocksize): msg = struct.pack(">cHB", "R", addr, blocksize) radio.pipe.write(msg) block = radio.pipe.read(blocksize + 4) if len(block) != (blocksize + 4): - print util.hexprint(block) + LOG.debug(util.hexprint(block)) raise errors.RadioError("Radio sent a short block") radio.pipe.write("A") ack = radio.pipe.read(1) if ack != "A": - print util.hexprint(ack) + LOG.debug(util.hexprint(ack)) raise errors.RadioError("Radio NAKed block") data += block[4:]
@@ -715,11 +715,11 @@ def _upload(radio, memsize=0xF400, blocksize=0x80): 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) + LOG.debug(util.hexprint(msg)) radio.pipe.write(msg) ack = radio.pipe.read(1) if ack != "A": - print util.hexprint(ack) + LOG.debug(util.hexprint(ack)) raise errors.RadioError("Radio did not ack block 0x%04X" % addr)
if radio.status_fn: diff --git a/chirp/drivers/th_uv3r.py b/chirp/drivers/th_uv3r.py index f01b6d5..77eca93 100644 --- a/chirp/drivers/th_uv3r.py +++ b/chirp/drivers/th_uv3r.py @@ -16,9 +16,12 @@ """TYT uv3r radio management module"""
import os +import logging from chirp import chirp_common, bitwise, errors, directory from chirp.drivers.wouxun import do_download, do_upload
+LOG = logging.getLogger(__name__) +
def tyt_uv3r_prep(radio): try: @@ -260,7 +263,7 @@ class TYTUV3RRadio(chirp_common.CloneModeRadio): c = THUV3R_CHARSET.index(" ") name.append(c) _mem.name = name - print repr(_mem) + LOG.debug(repr(_mem))
@classmethod def match_model(cls, filedata, filename): diff --git a/chirp/drivers/th_uvf8d.py b/chirp/drivers/th_uvf8d.py index c0ffa10..80b5a46 100644 --- a/chirp/drivers/th_uvf8d.py +++ b/chirp/drivers/th_uvf8d.py @@ -22,8 +22,8 @@ # TODO: [setting] Tail Eliminate # TODO: [setting] Tail Mode
- import struct +import logging
from chirp import chirp_common, bitwise, errors, directory, memmap, util from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -31,6 +31,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings
+LOG = logging.getLogger(__name__) +
def uvf8d_identify(radio): """Do identify handshake with TYT TH-UVF8D""" @@ -442,7 +444,7 @@ class TYTUVF8DRadio(chirp_common.CloneModeRadio): e.flags[7 - ((mem.number - 1) % 8)] = True
if _mem.get_raw() == ("\xFF" * 32): - print "Initializing empty memory" + LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 32)
_mem.rx_freq = mem.freq / 10 @@ -625,7 +627,7 @@ class TYTUVF8DRadio(chirp_common.CloneModeRadio): _settings.rxsave = 0 continue if element.get_name().endswith('_channel'): - print element.value, type(element.value) + LOG.debug(element.value, type(element.value)) setattr(_settings, element.get_name(), int(element.value) - 1) continue if not isinstance(element, RadioSetting): diff --git a/chirp/drivers/thd72.py b/chirp/drivers/thd72.py index d503740..a1167c6 100644 --- a/chirp/drivers/thd72.py +++ b/chirp/drivers/thd72.py @@ -209,7 +209,7 @@ class THD72Radio(chirp_common.CloneModeRadio): self.pipe.read(32) try: id = self.get_id() - print "Radio %s at %i baud" % (id, baud) + LOG.info("Radio %s at %i baud" % (id, baud)) return True except errors.RadioError: pass @@ -224,7 +224,7 @@ class THD72Radio(chirp_common.CloneModeRadio): if block not in self._dirty_blocks: self._dirty_blocks.append(block) self._dirty_blocks.sort() - print "dirty blocks:", self._dirty_blocks + print("dirty blocks: ", self._dirty_blocks)
def get_channel_name(self, number): if number < 999: @@ -299,7 +299,7 @@ class THD72Radio(chirp_common.CloneModeRadio): return mem
def set_memory(self, mem): - print "set_memory(%d)" % mem.number + LOG.debug("set_memory(%d)" % mem.number) if mem.number < 0 or mem.number > (max(THD72_SPECIAL.values()) + 1): raise errors.InvalidMemoryLocation( "Number must be between 0 and 999") @@ -397,7 +397,7 @@ class THD72Radio(chirp_common.CloneModeRadio): self.pipe.setRTS() self.pipe.read(1) data = "" - print "reading blocks %d..%d" % (blocks[0], blocks[-1]) + LOG.debug("reading blocks %d..%d" % (blocks[0], blocks[-1])) total = len(blocks) count = 0 for i in allblocks: @@ -432,7 +432,7 @@ class THD72Radio(chirp_common.CloneModeRadio): self.pipe.getCTS() self.pipe.setRTS() self.pipe.read(1) - print "writing blocks %d..%d" % (blocks[0], blocks[-1]) + LOG.debug("writing blocks %d..%d" % (blocks[0], blocks[-1])) total = len(blocks) count = 0 for i in blocks: diff --git a/chirp/drivers/thuv1f.py b/chirp/drivers/thuv1f.py index 73ec10c..3771633 100644 --- a/chirp/drivers/thuv1f.py +++ b/chirp/drivers/thuv1f.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, errors, util, directory, memmap from chirp import bitwise @@ -22,6 +23,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings
+LOG = logging.getLogger(__name__) +
def uvf1_identify(radio): """Do identify handshake with TYT TH-UVF1""" @@ -31,7 +34,7 @@ def uvf1_identify(radio): raise errors.RadioError("Radio did not respond") radio.pipe.write("\x02") ident = radio.pipe.read(16) - print "Ident:\n%s" % util.hexprint(ident) + LOG.info("Ident:\n%s" % util.hexprint(ident)) radio.pipe.write("\x06") ack = radio.pipe.read(1) if ack != "\x06": @@ -83,7 +86,7 @@ def uvf1_upload(radio): radio.pipe.write(msg) ack = radio.pipe.read(1) if ack != "\x06": - print repr(ack) + LOG.debug(repr(ack)) raise errors.RadioError("Radio did not ack block %i" % i) status = chirp_common.Status() status.cur = i @@ -352,7 +355,7 @@ class TYTTHUVF1Radio(chirp_common.CloneModeRadio): return
if _mem.get_raw() == ("\xFF" * 16): - print "Initializing empty memory" + LOG.debug("Initializing empty memory") _mem.set_raw("\x00" * 16)
_mem.rx_freq = mem.freq / 10 @@ -459,7 +462,7 @@ class TYTTHUVF1Radio(chirp_common.CloneModeRadio): RadioSettingValueBoolean(_settings.disnm)))
def _filter(name): - print repr(str(name)) + LOG.debug(repr(str(name))) return str(name).rstrip("\xFF").rstrip()
group.append( diff --git a/chirp/drivers/tk8102.py b/chirp/drivers/tk8102.py index 50ea12b..8fe8211 100644 --- a/chirp/drivers/tk8102.py +++ b/chirp/drivers/tk8102.py @@ -64,7 +64,7 @@ def make_frame(cmd, addr, length, data=""):
def send(radio, frame): - # print "%04i P>R: %s" % (len(frame), util.hexprint(frame)) + # LOG.debug("%04i P>R: %s" % (len(frame), util.hexprint(frame))) radio.pipe.write(frame)
@@ -73,7 +73,7 @@ def recv(radio, readdata=True): cmd, addr, length = struct.unpack(">BHB", hdr) if readdata: data = radio.pipe.read(length) - # print " P<R: %s" % util.hexprint(hdr + data) + # LOG.debug(" P<R: %s" % util.hexprint(hdr + data)) if len(data) != length: raise errors.RadioError("Radio sent %i bytes (expected %i)" % ( len(data), length)) @@ -93,7 +93,7 @@ def do_ident(radio): if ident[1:5] != radio.MODEL.split("-")[1]: raise errors.RadioError("Incorrect model: TK-%s, expected %s" % ( ident[1:5], radio.MODEL)) - print "Model: %s" % util.hexprint(ident) + LOG.info("Model: %s" % util.hexprint(ident)) radio.pipe.write("\x06") ack = radio.pipe.read(1)
@@ -413,7 +413,7 @@ class KenwoodTKx102Radio(chirp_common.CloneModeRadio): @classmethod def match_model(cls, filedata, filename): model = filedata[0x03D1:0x03D5] - print model + LOG.debug(model) return model == cls.MODEL.split("-")[1]
diff --git a/chirp/drivers/tmv71.py b/chirp/drivers/tmv71.py index 94c97a9..7c85c38 100644 --- a/chirp/drivers/tmv71.py +++ b/chirp/drivers/tmv71.py @@ -15,6 +15,9 @@
from chirp import chirp_common, errors, util from chirp.drivers import tmv71_ll +import logging + +LOG = logging.getLogger(__name__)
class TMV71ARadio(chirp_common.CloneModeRadio): @@ -38,7 +41,7 @@ class TMV71ARadio(chirp_common.CloneModeRadio): self.pipe.read(32) try: id = tmv71_ll.get_id(self.pipe) - print "Radio %s at %i baud" % (id, baud) + LOG.info("Radio %s at %i baud" % (id, baud)) return True except errors.RadioError: pass diff --git a/chirp/drivers/tmv71_ll.py b/chirp/drivers/tmv71_ll.py index 2fd4d86..50a100b 100644 --- a/chirp/drivers/tmv71_ll.py +++ b/chirp/drivers/tmv71_ll.py @@ -146,14 +146,14 @@ def get_mem_offset(number):
def get_raw_mem(map, number): base = get_mem_offset(number) - # print "Offset for %i is %04x" % (number, base) + # LOG.debug("Offset for %i is %04x" % (number, base)) return map[base:base+MEM_LOC_SIZE]
def get_used(map, number): pos = MEM_FLG_BASE + (number * 2) flag = ord(map[pos]) - print "Flag byte is %02x" % flag + LOG.debug("Flag byte is %02x" % flag) return not (flag & 0x80)
@@ -239,7 +239,7 @@ def get_tone(mmap, offset):
def set_tone(mmap, tone, offset): - print tone + LOG.debug(tone) mmap[offset] = chirp_common.TONES.index(tone)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 8ca3afd50181b7c69b3e620257d709e03998e95b
Use logging in rfinder.py (#2347)
diff --git a/chirp/drivers/rfinder.py b/chirp/drivers/rfinder.py index ee0bc79..35dbe70 100644 --- a/chirp/drivers/rfinder.py +++ b/chirp/drivers/rfinder.py @@ -16,10 +16,13 @@ import urllib import hashlib import re +import logging
from math import pi, cos, acos, sin, atan2 from chirp import chirp_common, CHIRP_VERSION
+LOG = logging.getLogger(__name__) + EARTH_RADIUS = 3963.1
SCHEMA = [ @@ -174,8 +177,8 @@ class RFinderParser:
def fetch_data(self, user, pw, coords, radius): """Fetches the data for a set of parameters""" - print user - print pw + LOG.debug(user) + LOG.debug(pw) args = { "email": urllib.quote_plus(user), "pass": hashlib.new("md5", pw).hexdigest(), @@ -188,7 +191,7 @@ class RFinderParser: _url = "https://www.rfinder.net/query.php?%s" % \ ("&".join(["%s=%s" % (k, v) for k, v in args.items()]))
- print "Query URL: %s" % _url + LOG.debug("Query URL: %s" % _url)
f = urllib.urlopen(_url) data = f.read() @@ -210,7 +213,7 @@ class RFinderParser: try: vals[SCHEMA[i]] = _vals[i] except IndexError: - print "No such vals %s" % SCHEMA[i] + LOG.error("No such vals %s" % SCHEMA[i]) self.__cheat = vals
mem.name = vals["TRUSTEE"] @@ -238,7 +241,7 @@ class RFinderParser: bear = fuzzy_to(self.__lat, self.__lon, lat, lon) mem.comment = "(%imi %s) %s" % (dist, bear, mem.comment) except Exception, e: - print "Failed to calculate distance: %s" % e + LOG.error("Failed to calculate distance: %s" % e)
return mem
@@ -257,13 +260,11 @@ class RFinderParser: self.__memories.append(mem) except Exception, e: import traceback - import sys - traceback.print_exc(file=sys.stdout) - print "Error in received data, cannot continue" - print e - print self.__cheat - print line - print "\n\n" + LOG.error(traceback.format_exc()) + LOG.error("Error in received data, cannot continue") + LOG.error(e) + LOG.error(self.__cheat) + LOG.error(line)
def get_memories(self): """Return the Memory objects associated with the fetched data""" @@ -328,7 +329,7 @@ def _test(): rfp.parse_data(data)
for mem in rfp.get_memories(): - print mem + LOG.debug(mem)
if __name__ == "__main__": _test()
# 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()
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 624d074d4e57405cbaee5d8661613a72ebb848a4
Use logging in kenwood*.py (#2347)
diff --git a/chirp/drivers/kenwood_hmk.py b/chirp/drivers/kenwood_hmk.py index 7e76f33..ba3fe1a 100644 --- a/chirp/drivers/kenwood_hmk.py +++ b/chirp/drivers/kenwood_hmk.py @@ -15,10 +15,13 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import csv +import logging
from chirp import chirp_common, errors, directory from chirp.drivers import generic_csv
+LOG = logging.getLogger(__name__) +
class OmittedHeaderError(Exception): """An internal exception to indicate that a header was omitted""" @@ -92,8 +95,8 @@ class HMKRadio(generic_csv.CSVRadio): continue
if len(header) > len(line): - print "Line %i has %i columns, expected %i" % \ - (lineno, len(line), len(header)) + LOG.debug("Line %i has %i columns, expected %i" % + (lineno, len(line), len(header))) self.errors.append("Column number mismatch on line %i" % lineno) continue @@ -112,7 +115,7 @@ class HMKRadio(generic_csv.CSVRadio): if mem.number is None: raise Exception("Invalid Location field" % lineno) except Exception, e: - print "Line %i: %s" % (lineno, e) + LOG.error("Line %i: %s" % (lineno, e)) self.errors.append("Line %i: %s" % (lineno, e)) continue
@@ -121,7 +124,8 @@ class HMKRadio(generic_csv.CSVRadio): good += 1
if not good: - print self.errors + for e in errors: + LOG.error(e) raise errors.InvalidDataError("No channels found")
@classmethod diff --git a/chirp/drivers/kenwood_itm.py b/chirp/drivers/kenwood_itm.py index a0fec83..57c3076 100644 --- a/chirp/drivers/kenwood_itm.py +++ b/chirp/drivers/kenwood_itm.py @@ -15,10 +15,13 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import csv +import logging
from chirp import chirp_common, errors, directory from chirp.drivers import generic_csv
+LOG = logging.getLogger(__name__) +
class OmittedHeaderError(Exception): """An internal exception to indicate that a header was omitted""" @@ -102,8 +105,8 @@ class ITMRadio(generic_csv.CSVRadio): break
if len(header) > len(line): - print "Line %i has %i columns, expected %i" % \ - (lineno, len(line), len(header)) + LOG.error("Line %i has %i columns, expected %i" % + (lineno, len(line), len(header))) self.errors.append("Column number mismatch on line %i" % lineno) continue @@ -116,7 +119,7 @@ class ITMRadio(generic_csv.CSVRadio): if mem.number is None: raise Exception("Invalid Location field" % lineno) except Exception, e: - print "Line %i: %s" % (lineno, e) + LOG.error("Line %i: %s" % (lineno, e)) self.errors.append("Line %i: %s" % (lineno, e)) continue
@@ -125,7 +128,8 @@ class ITMRadio(generic_csv.CSVRadio): good += 1
if not good: - print self.errors + for e in errors: + LOG.error(e) raise errors.InvalidDataError("No channels found")
@classmethod diff --git a/chirp/drivers/kenwood_live.py b/chirp/drivers/kenwood_live.py index f440b17..3973276 100644 --- a/chirp/drivers/kenwood_live.py +++ b/chirp/drivers/kenwood_live.py @@ -54,7 +54,7 @@ def command(ser, cmd, *args): while not result.endswith("\r"): result += ser.read(8) if (time.time() - start) > 0.5: - print "Timeout waiting for data" + LOG.error("Timeout waiting for data") break
LOG.debug("D7->PC: %s" % result.strip()) @@ -74,7 +74,7 @@ def get_id(ser): bauds.insert(0, LAST_BAUD)
for i in bauds: - print "Trying ID at baud %i" % i + LOG.info("Trying ID at baud %i" % i) ser.setBaudrate(i) ser.write("\r") ser.read(25) @@ -166,7 +166,7 @@ class KenwoodLiveRadio(chirp_common.LiveRadio): self.__memcache[mem.number] = mem return mem elif " " not in result: - print "Not sure what to do with this: `%s'" % result + LOG.error("Not sure what to do with this: `%s'" % result) raise errors.RadioError("Unexpected result returned from radio")
value = result.split(" ")[1] @@ -350,7 +350,7 @@ class THD7Radio(KenwoodOldLiveRadio): if spec[11] and spec[11].isdigit(): mem.dtcs = chirp_common.DTCS_CODES[int(spec[11][:-1]) - 1] else: - print "Unknown or invalid DCS: %s" % spec[11] + LOG.warn("Unknown or invalid DCS: %s" % spec[11]) if spec[13]: mem.offset = int(spec[13]) else: @@ -489,7 +489,7 @@ class THD7Radio(KenwoodOldLiveRadio): elif isinstance(element.value, RadioSettingValueString): self._kenwood_set(element.get_name(), str(element.value)) else: - print "Unknown type %s" % element.value + LOG.error("Unknown type %s" % element.value)
@directory.register @@ -561,7 +561,7 @@ class TMD700Radio(KenwoodOldLiveRadio): if spec[11] and spec[11].isdigit(): mem.dtcs = chirp_common.DTCS_CODES[int(spec[11][:-1]) - 1] else: - print "Unknown or invalid DCS: %s" % spec[11] + LOG.warn("Unknown or invalid DCS: %s" % spec[11]) if spec[13]: mem.offset = int(spec[13]) else: @@ -811,7 +811,7 @@ class THF6ARadio(KenwoodLiveRadio): if spec[11] and spec[11].isdigit(): mem.dtcs = chirp_common.DTCS_CODES[int(spec[11])] else: - print "Unknown or invalid DCS: %s" % spec[11] + LOG.warn("Unknown or invalid DCS: %s" % spec[11]) if spec[12]: mem.offset = int(spec[12]) else: @@ -830,7 +830,7 @@ class THF6ARadio(KenwoodLiveRadio): duplex = 0 offset = 0 else: - print "Bug: unsupported duplex `%s'" % mem.duplex + LOG.warn("Bug: unsupported duplex `%s'" % mem.duplex) spec = ( "%011i" % mem.freq, "%X" % THF6A_STEPS.index(mem.tuning_step),
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID bf9127c9169b04a0cd81e23910a6c69a5eea7a39
Use logging in drivers/k*.py (#2347)
diff --git a/chirp/drivers/kguv8d.py b/chirp/drivers/kguv8d.py index ab27a76..cf130ce 100644 --- a/chirp/drivers/kguv8d.py +++ b/chirp/drivers/kguv8d.py @@ -314,8 +314,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _cs += self._checksum(_packet) _cs %= 256 _rcs = ord(self.pipe.read(1)) - LOG.debug("_cs =", _cs) - LOG.debug("_rcs=", _rcs) + LOG.debug("_cs =%x", _cs) + LOG.debug("_rcs=%x", _rcs) return (_rcs != _cs, _packet)
# Identify the radio @@ -348,7 +348,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _chksum_err, _resp = self._read_record() LOG.debug("Got:\n%s" % util.hexprint(_resp)) if _chksum_err: - print "Checksum error: retrying ident..." + LOG.error("Checksum error: retrying ident...") time.sleep(0.100) continue LOG.debug("Model %s" % util.hexprint(_resp[0:7])) @@ -399,7 +399,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, cs_error, resp = self._read_record() if cs_error: # TODO: probably should retry a few times here - print util.hexprint(resp) + LOG.debug(util.hexprint(resp)) raise Exception("Checksum error on read") LOG.debug("Got:\n%s" % util.hexprint(resp)) image += resp[2:] @@ -926,6 +926,5 @@ class KGUV8DRadio(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 diff --git a/chirp/drivers/kyd.py b/chirp/drivers/kyd.py index a6db68a..87c46cc 100644 --- a/chirp/drivers/kyd.py +++ b/chirp/drivers/kyd.py @@ -110,7 +110,7 @@ def _nc630a_enter_programming_mode(radio): raise errors.RadioError("Error communicating with radio")
if not ident.startswith("P32073"): - print util.hexprint(ident) + LOG.debug(util.hexprint(ident)) raise errors.RadioError("Radio returned unknown identification string")
try: @@ -176,7 +176,7 @@ def _nc630a_write_block(radio, block_addr, block_size):
def do_download(radio): - print "download" + LOG.debug("download") _nc630a_enter_programming_mode(radio)
data = "" @@ -312,8 +312,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): def get_memory(self, number): bitpos = (1 << ((number - 1) % 8)) bytepos = ((number - 1) / 8) - print "bitpos %s" % bitpos - print "bytepos %s" % bytepos + LOG.debug("bitpos %s" % bitpos) + LOG.debug("bytepos %s" % bytepos)
_mem = self._memobj.memory[number - 1] _skp = self._memobj.skipflags[bytepos] @@ -347,7 +347,7 @@ class NC630aRadio(chirp_common.CloneModeRadio): mem.power = NC630A_POWER_LEVELS[_mem.highpower]
mem.skip = "" if (_skp & bitpos) else "S" - print "mem.skip %s" % mem.skip + LOG.debug("mem.skip %s" % mem.skip)
mem.extra = RadioSettingGroup("Extra", "extra")
@@ -396,8 +396,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): def set_memory(self, mem): bitpos = (1 << ((mem.number - 1) % 8)) bytepos = ((mem.number - 1) / 8) - print "bitpos %s" % bitpos - print "bytepos %s" % bytepos + LOG.debug("bitpos %s" % bitpos) + LOG.debug("bytepos %s" % bytepos)
_mem = self._memobj.memory[mem.number - 1] _skp = self._memobj.skipflags[bytepos] @@ -430,7 +430,7 @@ class NC630aRadio(chirp_common.CloneModeRadio): _skp |= bitpos else: _skp &= ~bitpos - print "_skp %s" % _skp + LOG.debug("_skp %s" % _skp)
for setting in mem.extra: setattr(_mem, setting.get_name(), setting.value) @@ -499,8 +499,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): obj = self._memobj.settings setting = element.get_name()
- 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
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 03cbbe8e442df0f3fd004a5c00ae4ff81329a2b0
Use logging in idrp.py (#2347)
diff --git a/chirp/drivers/idrp.py b/chirp/drivers/idrp.py index 3ba3f9b..f7c115d 100644 --- a/chirp/drivers/idrp.py +++ b/chirp/drivers/idrp.py @@ -30,7 +30,7 @@ def parse_frames(buf): start = buf.index("\xfe\xfe") end = buf[start:].index("\xfd") + start + 1 except Exception: - print "Unable to parse frames" + LOG.error("Unable to parse frames") break
frames.append(buf[start:end])
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 938eb4c894f4a2c4ae99be4c1e79e205f6be79b2
Use logging in ic9x*.py (#2347)
diff --git a/chirp/drivers/ic9x.py b/chirp/drivers/ic9x.py index 405b114..bdccf22 100644 --- a/chirp/drivers/ic9x.py +++ b/chirp/drivers/ic9x.py @@ -15,11 +15,14 @@
import time import threading +import logging
from chirp.drivers import ic9x_ll, icf from chirp import chirp_common, errors, util, directory from chirp import bitwise
+LOG = logging.getLogger(__name__) + IC9XA_SPECIAL = {} IC9XB_SPECIAL = {}
@@ -107,7 +110,7 @@ class IC9xRadio(icf.IcomLiveRadio):
def _maybe_send_magic(self): if (time.time() - self.__last) > 1: - print "Sending magic" + LOG.debug("Sending magic") ic9x_ll.send_magic(self.pipe) self.__last = time.time()
@@ -171,15 +174,15 @@ class IC9xRadio(icf.IcomLiveRadio):
for i in range(lo, hi + 1): try: - print "Getting %i" % i + LOG.debug("Getting %i" % i) mem = self.get_memory(i) if mem: memories.append(mem) - print "Done: %s" % mem + LOG.debug("Done: %s" % mem) except errors.InvalidMemoryLocation: pass except errors.InvalidDataError, e: - print "Error talking to radio: %s" % e + LOG.error("Error talking to radio: %s" % e) break
return memories @@ -256,9 +259,8 @@ class IC9xRadio(icf.IcomLiveRadio): if banks[i] != cached_names[i]: need_update = True self.__bankcache[i] = banks[i] - print "Updating %s: %s -> %s" % (chr(i + ord("A")), - cached_names[i], - banks[i]) + LOG.dbeug("Updating %s: %s -> %s" % + (chr(i + ord("A")), cached_names[i], banks[i]))
if need_update: self._lock.acquire() diff --git a/chirp/drivers/ic9x_ll.py b/chirp/drivers/ic9x_ll.py index c23ab10..c114ad7 100644 --- a/chirp/drivers/ic9x_ll.py +++ b/chirp/drivers/ic9x_ll.py @@ -14,10 +14,13 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import struct +import logging
from chirp import chirp_common, util, errors, bitwise from chirp.memmap import MemoryMap
+LOG = logging.getLogger(__name__) + TUNING_STEPS = [ 5.0, 6.25, 8.33, 9.0, 10.0, 12.5, 15, 20, 25, 30, 50, 100, 125, 200 ] @@ -58,7 +61,7 @@ def _ic9x_parse_frames(buf): start = buf.index("\xfe\xfe") end = buf[start:].index("\xfd") + start + 1 except Exception, e: - print "No trailing bit" + LOG.error("No trailing bit") break
framedata = buf[start:end] @@ -69,9 +72,9 @@ def _ic9x_parse_frames(buf): frame.from_raw(framedata[2:-1]) frames.append(frame) except errors.InvalidDataError, e: - print "Broken frame: %s" % e + LOG.error("Broken frame: %s" % e)
- # print "Parsed %i frames" % len(frames) + # LOG.debug("Parsed %i frames" % len(frames))
return frames
@@ -83,7 +86,7 @@ def ic9x_send(pipe, buf): # Add header and trailer realbuf = "\xfe\xfe" + buf + "\xfd"
- # print "Sending:\n%s" % util.hexprint(realbuf) + # LOG.debug("Sending:\n%s" % util.hexprint(realbuf))
pipe.write(realbuf) pipe.flush() @@ -140,7 +143,7 @@ class IC92Frame: def send(self, pipe, verbose=False): """Send the frame to the radio via @pipe""" if verbose: - print "Sending:\n%s" % util.hexprint(self.get_raw()) + LOG.debug("Sending:\n%s" % util.hexprint(self.get_raw()))
response = ic9x_send(pipe, self.get_raw())
@@ -334,7 +337,8 @@ class IC92MemoryFrame(IC92Frame): if mem.number < 0: self.set_iscall(True) mem.number = abs(mem.number) - 1 - print "Memory is %i (call %s)" % (mem.number, self.get_iscall()) + LOG.debug("Memory is %i (call %s)" % + (mem.number, self.get_iscall()))
_mem = bitwise.parse(MEMORY_FRAME_FORMAT, self).mem
@@ -439,7 +443,7 @@ def send_magic(pipe): resp = _send_magic_38400(pipe) if resp: return - print "Switching from 38400 to 4800" + LOG.info("Switching from 38400 to 4800") pipe.setBaudrate(4800) resp = _send_magic_4800(pipe) pipe.setBaudrate(38400) @@ -450,7 +454,7 @@ def send_magic(pipe): resp = _send_magic_4800(pipe) if resp: return - print "Switching from 4800 to 38400" + LOG.info("Switching from 4800 to 38400") pipe.setBaudrate(38400) resp = _send_magic_38400(pipe) if resp: @@ -498,8 +502,8 @@ def set_memory(pipe, vfo, memory): frame.set_memory(memory) frame.set_vfo(vfo)
- # print "Sending (%i):" % (len(frame.get_raw())) - # print util.hexprint(frame.get_raw()) + # LOG.debug("Sending (%i):" % (len(frame.get_raw()))) + # LOG.debug(util.hexprint(frame.get_raw()))
rframe = frame.send(pipe)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID e0e417ed9de5677fdbc6a988aafcaba369c83ee9
Use logging in icf.py (#2347)
diff --git a/chirp/drivers/icf.py b/chirp/drivers/icf.py index 06e7b2b..b51d8cb 100644 --- a/chirp/drivers/icf.py +++ b/chirp/drivers/icf.py @@ -16,11 +16,14 @@ import struct import re import time +import logging
from chirp import chirp_common, errors, util, memmap from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettings
+LOG = logging.getLogger(__name__) + CMD_CLONE_OUT = 0xE2 CMD_CLONE_IN = 0xE3 CMD_CLONE_DAT = 0xE4 @@ -106,7 +109,7 @@ class RadioStream:
self.data = rest except errors.InvalidDataError, e: - print "Failed to parse frame (cmd=%i): %s" % (cmd, e) + LOG.error("Failed to parse frame (cmd=%i): %s" % (cmd, e)) return []
return frames @@ -184,11 +187,11 @@ def send_clone_frame(pipe, cmd, data, raw=False, checksum=False): frame = "\xfe\xfe\xee\xef%s%s%s\xfd" % (chr(cmd), hed, cs)
if SAVE_PIPE: - print "Saving data..." + LOG.debug("Saving data...") SAVE_PIPE.write(frame)
- # print "Sending:\n%s" % util.hexprint(frame) - # print "Sending:\n%s" % util.hexprint(hed[6:]) + # LOG.debug("Sending:\n%s" % util.hexprint(frame)) + # LOG.debug("Sending:\n%s" % util.hexprint(hed[6:])) if cmd == 0xe4: # Uncomment to avoid cloning to the radio # return frame @@ -209,7 +212,7 @@ def process_bcd(bcddata): i += 2 data += struct.pack("B", val) except ValueError, e: - print "Failed to parse byte: %s" % e + LOG.error("Failed to parse byte: %s" % e) break
return data @@ -230,8 +233,8 @@ def process_data_frame(frame, _mmap): try: _mmap[saddr] = data except IndexError: - print "Error trying to set %i bytes at %05x (max %05x)" % \ - (bytes, saddr, len(_mmap)) + LOG.error("Error trying to set %i bytes at %05x (max %05x)" % + (bytes, saddr, len(_mmap))) return saddr, saddr + length
@@ -241,13 +244,13 @@ def start_hispeed_clone(radio, cmd): "\xEE\xEF\xE8" + \ radio.get_model() + \ "\x00\x00\x02\x01\xFD" - print "Starting HiSpeed:\n%s" % util.hexprint(buf) + LOG.debug("Starting HiSpeed:\n%s" % util.hexprint(buf)) radio.pipe.write(buf) radio.pipe.flush() resp = radio.pipe.read(128) - print "Response:\n%s" % util.hexprint(resp) + LOG.debug("Response:\n%s" % util.hexprint(resp))
- print "Switching to 38400 baud" + LOG.info("Switching to 38400 baud") radio.pipe.setBaudrate(38400)
buf = ("\xFE" * 14) + \ @@ -255,7 +258,7 @@ def start_hispeed_clone(radio, cmd): chr(cmd) + \ radio.get_model()[:3] + \ "\x00\xFD" - print "Starting HiSpeed Clone:\n%s" % util.hexprint(buf) + LOG.debug("Starting HiSpeed Clone:\n%s" % util.hexprint(buf)) radio.pipe.write(buf) radio.pipe.flush()
@@ -264,8 +267,8 @@ def _clone_from_radio(radio): md = get_model_data(radio.pipe)
if md[0:4] != radio.get_model(): - print "This model: %s" % util.hexprint(md[0:4]) - print "Supp model: %s" % util.hexprint(radio.get_model()) + LOG.info("This model: %s" % util.hexprint(md[0:4])) + LOG.info("Supp model: %s" % util.hexprint(radio.get_model())) raise errors.RadioError("I can't talk to this model")
if radio.is_hispeed(): @@ -274,7 +277,7 @@ def _clone_from_radio(radio): send_clone_frame(radio.pipe, CMD_CLONE_OUT, radio.get_model(), raw=True)
- print "Sent clone frame" + LOG.debug("Sent clone frame")
stream = RadioStream(radio.pipe)
@@ -290,17 +293,16 @@ def _clone_from_radio(radio): if frame.cmd == CMD_CLONE_DAT: src, dst = process_data_frame(frame, _mmap) if last_size != (dst - src): - print "ICF Size change from %i to %i at %04x" % (last_size, - dst - src, - src) + LOG.debug("ICF Size change from %i to %i at %04x" % + (last_size, dst - src, src)) last_size = dst - src if addr != src: - print "ICF GAP %04x - %04x" % (addr, src) + LOG.debug("ICF GAP %04x - %04x" % (addr, src)) addr = dst elif frame.cmd == CMD_CLONE_END: - print "End frame (%i):\n%s" % (len(frame.payload), - util.hexprint(frame.payload)) - print "Last addr: %04x" % addr + LOG.debug("End frame (%i):\n%s" % + (len(frame.payload), util.hexprint(frame.payload))) + LOG.debug("Last addr: %04x" % addr)
if radio.status_fn: status = chirp_common.Status() @@ -393,7 +395,7 @@ def _clone_to_radio(radio): frames += stream.get_frames(True) result = frames[-1] except IndexError: - print "Waiting for clone result..." + LOG.debug("Waiting for clone result...") time.sleep(0.5)
if len(frames) == 0: @@ -445,7 +447,7 @@ def convert_data_line(line): i += 2 _mmap += struct.pack("B", val) except ValueError, e: - print "Failed to parse byte: %s" % e + LOG.debug("Failed to parse byte: %s" % e) break
return _mmap
# 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")
# 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
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID a79b84a0f26185dd16b7fb4e40e10ae320e87087
Use logging in drivers/[hi]*.py (#2347)
diff --git a/chirp/drivers/h777.py b/chirp/drivers/h777.py index 236c2a9..d48d34c 100644 --- a/chirp/drivers/h777.py +++ b/chirp/drivers/h777.py @@ -117,7 +117,7 @@ def _h777_enter_programming_mode(radio): raise errors.RadioError("Error communicating with radio")
if not ident.startswith("P3107"): - print util.hexprint(ident) + LOG.debug(util.hexprint(ident)) raise errors.RadioError("Radio returned unknown identification string")
try: @@ -183,7 +183,7 @@ def _h777_write_block(radio, block_addr, block_size):
def do_download(radio): - print "download" + LOG.debug("download") _h777_enter_programming_mode(radio)
data = "" @@ -502,15 +502,15 @@ class H777Radio(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 == "voxlevel": setattr(obj, setting, int(element.value) - 1) 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
diff --git a/chirp/drivers/icomciv.py b/chirp/drivers/icomciv.py index 04ff53e..dd32ae7 100644 --- a/chirp/drivers/icomciv.py +++ b/chirp/drivers/icomciv.py @@ -90,9 +90,9 @@ class Frame: if willecho: echo = serial.read(len(raw)) if echo != raw and echo: - print "Echo differed (%i/%i)" % (len(raw), len(echo)) - print util.hexprint(raw) - print util.hexprint(echo) + LOG.debug("Echo differed (%i/%i)" % (len(raw), len(echo))) + LOG.debug(util.hexprint(raw)) + LOG.debug(util.hexprint(echo))
def read(self, serial): """Read the frame from @serial""" @@ -100,7 +100,7 @@ class Frame: while not data.endswith(chr(0xFD)): char = serial.read(1) if not char: - print "Read %i bytes total" % len(data) + LOG.debug("Read %i bytes total" % len(data)) raise errors.RadioError("Timeout") data += char
@@ -190,7 +190,7 @@ class IcomCIVRadio(icf.IcomLiveRadio): echo_test = "\xfe\xfe\xe0\xe0\xfa\xfd" self.pipe.write(echo_test) resp = self.pipe.read(6) - print "Echo:\n%s" % util.hexprint(resp) + LOG.debug("Echo:\n%s" % util.hexprint(resp)) return resp == echo_test
def __init__(self, *args, **kwargs): @@ -202,7 +202,7 @@ class IcomCIVRadio(icf.IcomLiveRadio):
if self.pipe: self._willecho = self._detect_echo() - print "Interface echo: %s" % self._willecho + LOG.debug("Interface echo: %s" % self._willecho) self.pipe.setTimeout(1)
# f = Frame() @@ -211,8 +211,9 @@ class IcomCIVRadio(icf.IcomLiveRadio): # # res = f.read(self.pipe) # if res: - # print "Result: %x->%x (%i)" % (res[0], res[1], len(f.get_data())) - # print util.hexprint(f.get_data()) + # LOG.debug("Result: %x->%x (%i)" % + # (res[0], res[1], len(f.get_data()))) + # LOG.debug(util.hexprint(f.get_data())) # # self._id = f.get_data()[0] self._rf = chirp_common.RadioFeatures() @@ -237,7 +238,7 @@ class IcomCIVRadio(icf.IcomLiveRadio): return repr(f.get_obj())
def get_memory(self, number): - print "Getting %i" % number + LOG.debug("Getting %i" % number) f = self._classes["mem"]() f.set_location(number) self._send_frame(f) @@ -253,7 +254,7 @@ class IcomCIVRadio(icf.IcomLiveRadio): return mem
memobj = f.get_obj() - print repr(memobj) + LOG.debug(repr(memobj))
mem.freq = int(memobj.freq) mem.mode = self._rf.valid_modes[memobj.mode] @@ -307,11 +308,11 @@ class IcomCIVRadio(icf.IcomLiveRadio): memobj.ctone = int(mem.ctone * 10) memobj.rtone = int(mem.rtone * 10)
- print repr(memobj) + LOG.debug(repr(memobj)) self._send_frame(f)
f = self._recv_frame() - print "Result:\n%s" % util.hexprint(f.get_data()) + LOG.debug("Result:\n%s" % util.hexprint(f.get_data()))
@directory.register @@ -415,8 +416,8 @@ def probe_model(ser): return CIV_MODELS[(model, controller)]
if f.get_data(): - print "Got data, but not 1 byte:" - print util.hexprint(f.get_data()) + LOG.debug("Got data, but not 1 byte:") + LOG.debug(util.hexprint(f.get_data())) raise errors.RadioError("Unknown response")
raise errors.RadioError("Unsupported model") diff --git a/chirp/drivers/icq7.py b/chirp/drivers/icq7.py index 44ec43e..04cf63e 100644 --- a/chirp/drivers/icq7.py +++ b/chirp/drivers/icq7.py @@ -14,6 +14,8 @@ # along with this program. If not, see http://www.gnu.org/licenses/.
import struct +import logging + from chirp.drivers import icf from chirp import chirp_common, directory, bitwise from chirp.chirp_common import to_GHz, from_GHz @@ -22,6 +24,9 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettingValueFloat, RadioSettings
+ +LOG = logging.getLogger(__name__) + MEM_FORMAT = """ struct { bbcd freq[3]; @@ -154,7 +159,7 @@ class ICQ7Radio(icf.IcomCloneModeRadio): try: mem.tuning_step = STEPS[_mem.tune_step] except IndexError: - print "Invalid tune step index %i" % _mem.tune_step + LOG.error("Invalid tune step index %i" % _mem.tune_step) mem.tmode = TMODES[_flag.tmode] mem.duplex = DUPLEX[_flag.duplex] if mem.freq < 30000000: @@ -328,11 +333,11 @@ class ICQ7Radio(icf.IcomCloneModeRadio): 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 diff --git a/chirp/drivers/icw32.py b/chirp/drivers/icw32.py index 356d81a..dc08ea0 100644 --- a/chirp/drivers/icw32.py +++ b/chirp/drivers/icw32.py @@ -13,9 +13,13 @@ # 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 logging + from chirp.drivers import icf from chirp import chirp_common, util, directory, bitwise
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x%x; struct { @@ -174,10 +178,10 @@ class ICW32ARadio(icf.IcomCloneModeRadio): _flg.am = mem.mode == "AM"
if self._memobj.state.left_scanning: - print "Canceling scan on left VFO" + LOG.debug("Canceling scan on left VFO") self._memobj.state.left_scanning = 0 if self._memobj.state.right_scanning: - print "Canceling scan on right VFO" + LOG.debug("Canceling scan on right VFO") self._memobj.state.right_scanning = 0
def get_sub_devices(self): diff --git a/chirp/drivers/icx8x.py b/chirp/drivers/icx8x.py index bf17f1a..6a5c8b0 100644 --- a/chirp/drivers/icx8x.py +++ b/chirp/drivers/icx8x.py @@ -13,9 +13,13 @@ # 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 logging + from chirp.drivers import icf, icx8x_ll from chirp import chirp_common, errors, directory
+LOG = logging.getLogger(__name__) +
def _isuhf(pipe): try: @@ -25,7 +29,7 @@ def _isuhf(pipe): except: raise errors.RadioError("Unable to probe radio band")
- print "Radio is a %s82" % (uhf and "U" or "V") + LOG.debug("Radio is a %s82" % (uhf and "U" or "V"))
return uhf
@@ -102,7 +106,7 @@ class ICx8xRadio(icf.IcomCloneModeRadio, chirp_common.IcomDstarSupport): # that flag. if isinstance(pipe, str): self._isuhf = (ord(self._mmap[0x1930]) != 0) - # print "Found %s image" % (self.isUHF and "UHF" or "VHF") + # LOG.debug("Found %s image" % (self.isUHF and "UHF" or "VHF")) else: self._isuhf = None
participants (1)
-
Zachary T Welch