# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com
Use new logger module (#2347)
This patch adds logging support to the chirp.py script, including a handful of command line options to control this feature. I plan add these options to chirpw too, but that will require a separate patch that adds proper option parsing.
This patch chases down all references to CHIRP_DEBUG, converting the wrapped print calls to LOG.debug calls. it also eliminates a few plain DEBUG variables and a couple of other one-off variants.
diff --git a/chirp/anytone.py b/chirp/anytone.py index 4b9c785..b7d722b 100644 --- a/chirp/anytone.py +++ b/chirp/anytone.py @@ -16,6 +16,7 @@ import os import struct import time +import logging
from chirp import bitwise from chirp import chirp_common @@ -26,6 +27,8 @@ from chirp import util from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings, \ RadioSettingValueList, RadioSettingValueString, RadioSettingValueBoolean
+LOG = logging.getLogger(__name__) + _mem_format = """ #seekto 0x0100; struct { @@ -164,10 +167,6 @@ def _should_send_addr(memobj, addr): else: return _is_loc_used(memobj, _addr_to_loc(addr))
-def _debug(string): - if "CHIRP_DEBUG" in os.environ or True: - print string - def _echo_write(radio, data): try: radio.pipe.write(data) @@ -201,7 +200,7 @@ def _ident(radio): raise errors.RadioError("Unsupported model") _echo_write(radio, "\x02") response = radio.pipe.read(16) - _debug(util.hexprint(response)) + LOG.debug(util.hexprint(response)) if response[1:8] not in valid_model: print "Response was:\n%s" % util.hexprint(response) raise errors.RadioError("Unsupported model") @@ -227,7 +226,7 @@ def _send(radio, cmd, addr, length, data=None): frame += chr(_checksum(frame[1:])) frame += "\x06" _echo_write(radio, frame) - _debug("Sent:\n%s" % util.hexprint(frame)) + LOG.debug("Sent:\n%s" % util.hexprint(frame)) if data: result = radio.pipe.read(1) if result != "\x06": @@ -236,7 +235,7 @@ def _send(radio, cmd, addr, length, data=None): addr) return result = _read(radio, length + 6) - _debug("Got:\n%s" % util.hexprint(result)) + LOG.debug("Got:\n%s" % util.hexprint(result)) header = result[0:4] data = result[4:-2] ack = result[-1] diff --git a/chirp/baofeng_uv3r.py b/chirp/baofeng_uv3r.py index 52d1a78..0827885 100644 --- a/chirp/baofeng_uv3r.py +++ b/chirp/baofeng_uv3r.py @@ -24,11 +24,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettingValueFloat, RadioSettings
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def _uv3r_prep(radio): radio.pipe.write("\x05PROGRAM") ack = radio.pipe.read(1) diff --git a/chirp/bjuv55.py b/chirp/bjuv55.py index 7dd61be..9fb7e5a 100644 --- a/chirp/bjuv55.py +++ b/chirp/bjuv55.py @@ -28,11 +28,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from textwrap import dedent from chirp import uv5r
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - BJUV55_MODEL = "\x50\xBB\xDD\x55\x63\x98\x4D"
COLOR_LIST = ["Off", "Blue", "Red", "Pink"] diff --git a/chirp/ft1d.py b/chirp/ft1d.py index eb7a0b1..db0259f 100644 --- a/chirp/ft1d.py +++ b/chirp/ft1d.py @@ -17,6 +17,7 @@ import os import re import string +import logging
from chirp import chirp_common, yaesu_clone, directory from chirp import bitwise @@ -25,6 +26,8 @@ from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean from textwrap import dedent
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x049a; struct { @@ -1549,8 +1552,7 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): is_latitude = name.endswith("latitude") lat_long = setting.value.get_value().strip() sign, l_d, l_m, l_s = cls._str_to_latlong(lat_long, is_latitude) - if os.getenv("CHIRP_DEBUG"): - print "%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s) + LOG.debug("%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s)) setattr(obj, "%s_sign" % name, sign) setattr(obj, "%s_degree" % name, l_d) setattr(obj, "%s_minute" % name, l_m) @@ -1587,9 +1589,8 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio):
try: old_val = getattr(obj, setting) - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%r) <= %s" % ( - element.get_name(), old_val, element.value) + LOG.debug("Setting %s(%r) <= %s" % ( + 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" % ( @@ -1623,4 +1624,4 @@ class FT1Radio(yaesu_clone.YaesuCloneModeRadio): val = [FT1_DTMF_CHARS.index(x) for x in rawval] for x in range(len(val), 16): val.append(0xFF) - cls._memobj.dtmf[i].memory = val \ No newline at end of file + cls._memobj.dtmf[i].memory = val diff --git a/chirp/ft2800.py b/chirp/ft2800.py index fb9d10c..feac0ce 100644 --- a/chirp/ft2800.py +++ b/chirp/ft2800.py @@ -15,11 +15,12 @@
import time import os +import logging
from chirp import util, memmap, chirp_common, bitwise, directory, errors from chirp.yaesu_clone import YaesuCloneModeRadio
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
CHUNK_SIZE = 16 def _send(s, data): @@ -41,8 +42,7 @@ def _download(radio): if data == IDBLOCK: break
- if DEBUG: - print "Header:\n%s" % util.hexprint(data) + LOG.debug("Header:\n%s" % util.hexprint(data))
if len(data) != 8: raise Exception("Failed to read header") @@ -54,8 +54,7 @@ def _download(radio): while len(data) < radio._block_sizes[1]: time.sleep(0.1) chunk = radio.pipe.read(38) - if DEBUG: - print "Got: %i:\n%s" % (len(chunk), util.hexprint(chunk)) + LOG.debug("Got: %i:\n%s" % (len(chunk), util.hexprint(chunk))) if len(chunk) == 8: print "END?" elif len(chunk) != 38: @@ -79,8 +78,7 @@ def _download(radio): status.msg = "Cloning from radio" radio.status_fn(status)
- if DEBUG: - print "Total: %i" % len(data) + LOG.debug("Total: %i" % len(data))
return memmap.MemoryMap(data)
@@ -94,8 +92,7 @@ def _upload(radio): _send(radio.pipe, IDBLOCK) time.sleep(1) ack = radio.pipe.read(300) - if DEBUG: - print "Ack was (%i):\n%s" % (len(ack), util.hexprint(ack)) + LOG.debug("Ack was (%i):\n%s" % (len(ack), util.hexprint(ack))) if ack != ACK: raise Exception("Radio did not ack ID")
@@ -108,8 +105,7 @@ def _upload(radio): cs += ord(byte) data += chr(cs & 0xFF)
- if DEBUG: - print "Writing block %i:\n%s" % (block, util.hexprint(data)) + LOG.debug("Writing block %i:\n%s" % (block, util.hexprint(data)))
_send(radio.pipe, data) time.sleep(0.1) diff --git a/chirp/ft60.py b/chirp/ft60.py index 45c92d0..74799ef 100644 --- a/chirp/ft60.py +++ b/chirp/ft60.py @@ -13,7 +13,7 @@ # 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 time, os +import time, os, logging from chirp import chirp_common, yaesu_clone, memmap, bitwise, directory from chirp import errors from chirp.settings import RadioSetting, RadioSettingGroup, \ @@ -22,6 +22,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, RadioSettings from textwrap import dedent
+LOG = logging.getLogger(__name__) + ACK = "\x06"
def _send(pipe, data): @@ -617,8 +619,7 @@ class FT60Radio(yaesu_clone.YaesuCloneModeRadio): obj = getattr(_settings, name) setattr(_settings, name, value)
- if os.getenv("CHIRP_DEBUG"): - print "Setting %s: %s" % (name, value) + LOG.debug("Setting %s: %s" % (name, value)) except Exception, e: print element.get_name() raise diff --git a/chirp/ft7800.py b/chirp/ft7800.py index 451fb08..824bd6d 100644 --- a/chirp/ft7800.py +++ b/chirp/ft7800.py @@ -13,7 +13,7 @@ # 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 time +import time, logging from chirp import chirp_common, yaesu_clone, memmap, directory from chirp import bitwise, errors from textwrap import dedent @@ -25,10 +25,7 @@ import os, re
from collections import defaultdict
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
ACK = chr(0x06)
@@ -540,9 +537,8 @@ class FT7800Radio(FTx800Radio): FTx800Radio.set_memory(self, memory)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -551,9 +547,8 @@ class FT7800Radio(FTx800Radio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(length): @@ -647,8 +642,7 @@ class FT7800Radio(FTx800Radio): break if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -721,8 +715,7 @@ class FT7800Radio(FTx800Radio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-2:]) _settings = self._memobj.dtmf[idx] _settings.memory = newval @@ -735,9 +728,7 @@ class FT7800Radio(FTx800Radio): # normal settings newval = element.value oldval = getattr(_settings, setting) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() diff --git a/chirp/ft817.py b/chirp/ft817.py index 8950f73..319bc46 100644 --- a/chirp/ft817.py +++ b/chirp/ft817.py @@ -22,9 +22,11 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import time, os +import time, os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + CMD_ACK = 0x06
@directory.register @@ -319,8 +321,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): raise Exception("Unable to read block %02X expected %i got %i" % (blocknum, block + 2, len(data)))
- if os.getenv("CHIRP_DEBUG"): - print "Read %i" % len(data) + LOG.debug("Read %i" % len(data)) return data
def _clone_in(self): @@ -382,15 +383,12 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): for _i in range(0, repeat): time.sleep(0.01) checksum = yaesu_clone.YaesuChecksum(pos, pos + block - 1) - if os.getenv("CHIRP_DEBUG"): - print "Block %i - will send from %i to %i byte " % \ - (blocks, - pos, - pos + block) - print util.hexprint(chr(blocks)) - print util.hexprint(self.get_mmap()[pos:pos + block]) - print util.hexprint(chr(checksum.get_calculated( - self.get_mmap()))) + LOG.debug("Block %i - will send from %i to %i byte " % \ + (blocks, pos, pos + block)) + LOG.debug(util.hexprint(chr(blocks))) + LOG.debug(util.hexprint(self.get_mmap()[pos:pos + block])) + LOG.debug(util.hexprint(chr(checksum.get_calculated( + self.get_mmap())))) self.pipe.write(chr(blocks)) self.pipe.write(self.get_mmap()[pos:pos + block]) self.pipe.write(chr(checksum.get_calculated(self.get_mmap()))) @@ -399,8 +397,7 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): time.sleep(delay) buf = self.pipe.read(1) if not buf or buf[0] != chr(CMD_ACK): - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(buf) + LOG.debug(util.hexprint(buf)) raise Exception(_("Radio did not ack block %i") % blocks) pos += block blocks += 1 @@ -1030,9 +1027,8 @@ class FT817Radio(yaesu_clone.YaesuCloneModeRadio): else: obj = _settings setting = element.get_name() - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%s) <= %s" % (setting, - getattr(obj, setting), element.value) + LOG.debug("Setting %s(%s) <= %s" % (setting, + getattr(obj, setting), element.value)) if setting == "contrast": setattr(obj, setting, int(element.value) + 1) elif setting == "callsign": diff --git a/chirp/ft857.py b/chirp/ft857.py index a479623..ebe8e12 100644 --- a/chirp/ft857.py +++ b/chirp/ft857.py @@ -21,9 +21,11 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import os +import os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + @directory.register class FT857Radio(ft817.FT817Radio): """Yaesu FT-857/897""" @@ -956,9 +958,8 @@ class FT857Radio(ft817.FT817Radio): else: obj = _settings setting = element.get_name() - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%s) <= %s" % (setting, - getattr(obj, setting), element.value) + LOG.debug("Setting %s(%s) <= %s" % (setting, + getattr(obj, setting), element.value)) if setting == "arts_idw": self._memobj.arts_idw = \ [self._CALLSIGN_CHARSET_REV[x] for x in diff --git a/chirp/ft90.py b/chirp/ft90.py index bfbddda..b638d47 100644 --- a/chirp/ft90.py +++ b/chirp/ft90.py @@ -19,13 +19,10 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import time, os, traceback, string, re +import time, os, traceback, string, re, logging from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG=False +LOG = logging.getLogger(__name__)
CMD_ACK = chr(0x06)
@@ -289,27 +286,24 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): blocknumbyte = chr(blocknum) payloadbytes = self.get_mmap()[pos:pos+blocksize] checksumbyte = chr(checksum.get_calculated(self.get_mmap())) - if CHIRP_DEBUG: - print "Block %i - will send from %i to %i byte " % \ - (blocknum, pos, pos + blocksize) - print util.hexprint(blocknumbyte) - print util.hexprint(payloadbytes) - print util.hexprint(checksumbyte) + LOG.debug("Block %i - will send from %i to %i byte " % \ + (blocknum, pos, pos + blocksize)) + LOG.debug(util.hexprint(blocknumbyte)) + LOG.debug(util.hexprint(payloadbytes)) + LOG.debug(util.hexprint(checksumbyte)) # send wrapped bytes time.sleep(looppredelay) self.pipe.write(blocknumbyte) self.pipe.write(payloadbytes) self.pipe.write(checksumbyte) tmp = self.pipe.read(blocksize+2) #chew echo - if CHIRP_DEBUG: - print "bytes echoed: " - print util.hexprint(tmp) + LOG.debug("bytes echoed: ") + LOG.debug(util.hexprint(tmp)) # radio is slow to write/ack: time.sleep(looppostdelay) buf = self.pipe.read(1) - if CHIRP_DEBUG: - print "ack recd:" - print util.hexprint(buf) + LOG.debug("ack recd:") + LOG.debug(util.hexprint(buf)) if buf != CMD_ACK: raise Exception("Radio did not ack block %i" % blocknum) pos += blocksize @@ -463,12 +457,10 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
def _decode_cwid(self, cwidarr): cwid = "" - if CHIRP_DEBUG: - print "@ +_decode_cwid:" + LOG.debug("@ +_decode_cwid:") for byte in cwidarr.get_value(): char = int(byte) - if CHIRP_DEBUG: - print char + LOG.debug(char) # bitwise wraps in quotes! get rid of those if char < len(FT90_CWID_CHARS): cwid += FT90_CWID_CHARS[char] @@ -476,21 +468,17 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio):
def _encode_cwid(self, cwidarr): cwid = "" - if CHIRP_DEBUG: - print "@ _encode_cwid:" + LOG.debug("@ _encode_cwid:") for char in cwidarr.get_value(): cwid += chr(FT90_CWID_CHARS.index(char)) - if CHIRP_DEBUG: - print cwid + LOG.debug(cwid) return cwid
def _bbcd2dtmf(self, bcdarr, strlen = 16): # doing bbcd, but with support for ABCD*# - if CHIRP_DEBUG: - print bcdarr.get_value() + LOG.debug(bcdarr.get_value()) string = ''.join("%02X" % b for b in bcdarr) - if CHIRP_DEBUG: - print "@_bbcd2dtmf, received: %s" % string + LOG.debug("@_bbcd2dtmf, received: %s" % string) string = string.replace('E','*').replace('F','#') if strlen <= 16: string = string[:strlen] @@ -501,8 +489,7 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): dtmfstr = dtmfstr.replace('*', 'E').replace('#', 'F') dtmfstr = str.ljust(dtmfstr.strip(), 16, "0" ) bcdarr = list(bytearray.fromhex(dtmfstr)) - if CHIRP_DEBUG: - print "@_dtmf2bbcd, sending: %s" % bcdarr + LOG.debug("@_dtmf2bbcd, sending: %s" % bcdarr) return bcdarr
def get_settings(self): @@ -644,9 +631,7 @@ class FT90Radio(yaesu_clone.YaesuCloneModeRadio): dtmfstrlen = len(str(newval).strip()) setattr(_settings, setting + "_len", dtmfstrlen) newval = self._dtmf2bbcd(newval) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() diff --git a/chirp/ftm350.py b/chirp/ftm350.py index 442cde1..e3fcbfe 100644 --- a/chirp/ftm350.py +++ b/chirp/ftm350.py @@ -16,12 +16,15 @@ import time import struct import os +import logging
from chirp import chirp_common, yaesu_clone, directory, errors, util from chirp import bitwise, memmap from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings from chirp.settings import RadioSettingValueInteger, RadioSettingValueString
+LOG = logging.getLogger(__name__) + mem_format = """ struct mem { u8 used:1, @@ -141,8 +144,8 @@ def _clone_in(radio): radio.pipe.write("\x06") time.sleep(0.05)
- if os.getenv("CHIRP_DEBUG") and (last_addr + 128) != addr: - print "Gap, expecting %04x, got %04x" % (last_addr+128, addr) + if (last_addr + 128) != addr: + LOG.debug("Gap, expecting %04x, got %04x" % (last_addr+128, addr)) last_addr = addr data[addr] = block length += len(block) diff --git a/chirp/h777.py b/chirp/h777.py index bce4b98..5ac0351 100644 --- a/chirp/h777.py +++ b/chirp/h777.py @@ -18,6 +18,7 @@ import time import os import struct import unittest +import logging
from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util @@ -25,7 +26,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettings
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0010; @@ -139,8 +140,7 @@ def _h777_read_block(radio, block_addr, block_size):
cmd = struct.pack(">cHb", 'R', block_addr, BLOCK_SIZE) expectedresponse = "W" + cmd[1:] - if DEBUG: - print("Reading block %04x..." % (block_addr)) + LOG.debug("Reading block %04x..." % (block_addr))
try: serial.write(cmd) @@ -166,9 +166,8 @@ def _h777_write_block(radio, block_addr, block_size): cmd = struct.pack(">cHb", 'W', block_addr, BLOCK_SIZE) data = radio.get_mmap()[block_addr:block_addr + 8]
- if DEBUG: - print("Writing Data:") - print util.hexprint(cmd + data) + LOG.debug("Writing Data:") + LOG.debug(util.hexprint(cmd + data))
try: serial.write(cmd + data) @@ -197,9 +196,8 @@ def do_download(radio): block = _h777_read_block(radio, addr, BLOCK_SIZE) data += block
- if DEBUG: - print "Address: %04x" % addr - print util.hexprint(block) + LOG.debug("Address: %04x" % addr) + LOG.debug(util.hexprint(block))
_h777_exit_programming_mode(radio)
diff --git a/chirp/icomciv.py b/chirp/icomciv.py index 71af300..1d02553 100644 --- a/chirp/icomciv.py +++ b/chirp/icomciv.py @@ -1,9 +1,9 @@
-import struct +import struct, logging from chirp import chirp_common, icf, util, errors, bitwise, directory from chirp.memmap import MemoryMap
-DEBUG = True +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ bbcd number[2]; @@ -80,9 +80,8 @@ class Frame: raw = struct.pack("BBBBBB", 0xFE, 0xFE, src, dst, self._cmd, self._sub) raw += str(self._data) + chr(0xFD)
- if DEBUG: - print "%02x -> %02x (%i):\n%s" % (src, dst, - len(raw), util.hexprint(raw)) + LOG.debug("%02x -> %02x (%i):\n%s" % (src, dst, + len(raw), util.hexprint(raw)))
serial.write(raw) if willecho: @@ -106,8 +105,7 @@ class Frame: raise errors.RadioError("Radio reported error")
src, dst = struct.unpack("BB", data[2:4]) - if DEBUG: - print "%02x <- %02x:\n%s" % (src, dst, util.hexprint(data)) + LOG.debug("%02x <- %02x:\n%s" % (src, dst, util.hexprint(data)))
self._cmd = ord(data[4]) self._sub = ord(data[5]) diff --git a/chirp/idrp.py b/chirp/idrp.py index e20ba07..012bb46 100644 --- a/chirp/idrp.py +++ b/chirp/idrp.py @@ -13,12 +13,11 @@ # 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 serial +import serial, logging
-from chirp import chirp_common, errors -from chirp import util +from chirp import chirp_common, errors, util
-DEBUG_IDRP = False +LOG = logging.getLogger(__name__)
def parse_frames(buf): """Parse frames from the radio""" @@ -49,8 +48,7 @@ def send(pipe, buf): break
data += buf - if DEBUG_IDRP: - print "Got: \n%s" % util.hexprint(buf) + LOG.debug("Got: \n%s" % util.hexprint(buf))
return parse_frames(data)
@@ -97,8 +95,7 @@ def get_freq(pipe): ord(els[2]), ord(els[1]), ord(els[0]))) - if DEBUG_IDRP: - print "Freq: %f" % freq + LOG.debug("Freq: %f" % freq) return freq
raise errors.InvalidDataError("No frequency frame received") diff --git a/chirp/kenwood_live.py b/chirp/kenwood_live.py index 971c08e..6cac1c9 100644 --- a/chirp/kenwood_live.py +++ b/chirp/kenwood_live.py @@ -17,6 +17,9 @@ import threading import os import sys import time +import logging + +LOG = logging.getLogger(__name__)
NOCACHE = os.environ.has_key("CHIRP_NOCACHE")
@@ -29,8 +32,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueBoolean, \ RadioSettingValueString, RadioSettingValueList, RadioSettings
-DEBUG = True - DUPLEX = { 0 : "", 1 : "+", 2 : "-" } MODES = { 0 : "FM", 1 : "AM" } STEPS = list(chirp_common.TUNING_STEPS) @@ -49,8 +50,7 @@ def command(ser, cmd, *args): LOCK.acquire() if args: cmd += " " + " ".join(args) - if DEBUG: - print "PC->RADIO: %s" % cmd + LOG.debug("PC->RADIO: %s" % cmd) ser.write(cmd + "\r")
result = "" @@ -60,8 +60,7 @@ def command(ser, cmd, *args): print "Timeout waiting for data" break
- if DEBUG: - print "D7->PC: %s" % result.strip() + LOG.debug("D7->PC: %s" % result.strip())
LOCK.release()
diff --git a/chirp/kguv8d.py b/chirp/kguv8d.py index 772b04f..d0f779f 100644 --- a/chirp/kguv8d.py +++ b/chirp/kguv8d.py @@ -17,16 +17,14 @@
import time import os +import logging from chirp import util, chirp_common, bitwise, memmap, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ RadioSettingValueInteger, RadioSettingValueString, \ RadioSettings
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
CMD_ID = 128 CMD_END = 129 @@ -304,8 +302,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _packet += payload # calculate and add the checksum to the packet _packet += chr(self._checksum(_packet[1:])) - if CHIRP_DEBUG: - print "Sent:\n%s" % util.hexprint(_packet) + LOG.debug("Sent:\n%s" % util.hexprint(_packet)) self.pipe.write(_packet)
def _read_record(self): @@ -317,9 +314,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, _cs += self._checksum(_packet) _cs %= 256 _rcs = ord(self.pipe.read(1)) - if CHIRP_DEBUG: - print "_cs =", _cs - print "_rcs=", _rcs + LOG.debug("_cs =", _cs) + LOG.debug("_rcs=", _rcs) return (_rcs != _cs, _packet)
# Identify the radio @@ -350,14 +346,12 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, for _i in range(0, 10): self._write_record(CMD_ID) _chksum_err, _resp = self._read_record() - if CHIRP_DEBUG: - print "Got:\n%s" % util.hexprint(_resp) + LOG.debug("Got:\n%s" % util.hexprint(_resp)) if _chksum_err: print "Checksum error: retrying ident..." time.sleep(0.100) continue - if CHIRP_DEBUG: - print "Model %s" % util.hexprint(_resp[0:7]) + LOG.debug("Model %s" % util.hexprint(_resp[0:7])) if _resp[0:7] == self._model: return if len(_resp) == 0: @@ -407,8 +401,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, # TODO: probably should retry a few times here print util.hexprint(resp) raise Exception("Checksum error on read") - if CHIRP_DEBUG: - print "Got:\n%s" % util.hexprint(resp) + LOG.debug("Got:\n%s" % util.hexprint(resp)) image += resp[2:] if self.status_fn: status = chirp_common.Status() @@ -436,11 +429,9 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, req = chr(i / 256) + chr(i % 256) chunk = self.get_mmap()[ptr:ptr + blocksize] self._write_record(CMD_WR, req + chunk) - if CHIRP_DEBUG: - print util.hexprint(req + chunk) + LOG.debug(util.hexprint(req + chunk)) cserr, ack = self._read_record() - if CHIRP_DEBUG: - print util.hexprint(ack) + LOG.debug(util.hexprint(ack)) j = ord(ack[0]) * 256 + ord(ack[1]) if cserr or j != ptr: raise Exception("Radio did not ack block %i" % ptr) @@ -537,9 +528,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, # always set it even if no dtcs is used mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N")
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.txtone, - rxmode, _mem.rxtone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.txtone, + rxmode, _mem.rxtone))
def get_memory(self, number): _mem = self._memobj.memory[number] @@ -549,8 +539,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, mem.number = number _valid = self._memobj.valid[mem.number]
- if CHIRP_DEBUG: - print number, _valid == MEM_VALID + LOG.debug("%d %s", number, _valid == MEM_VALID) if _valid != MEM_VALID: mem.empty = True return mem @@ -618,9 +607,8 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, else: _mem.rxtone = 0
- if CHIRP_DEBUG: - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.txtone, - rx_mode, _mem.rxtone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.txtone, + rx_mode, _mem.rxtone))
def set_memory(self, mem): number = mem.number diff --git a/chirp/kyd.py b/chirp/kyd.py index 2d4223d..e188df9 100644 --- a/chirp/kyd.py +++ b/chirp/kyd.py @@ -17,6 +17,7 @@ import time import os import struct +import logging
from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util @@ -24,7 +25,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettings
-DEBUG = os.getenv("CHIRP_DEBUG") and True or False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0010; @@ -132,8 +133,7 @@ def _nc630a_read_block(radio, block_addr, block_size):
cmd = struct.pack(">cHb", 'R', block_addr, BLOCK_SIZE) expectedresponse = "W" + cmd[1:] - if DEBUG: - print("Reading block %04x..." % (block_addr)) + LOG.debug("Reading block %04x..." % (block_addr))
try: serial.write(cmd) @@ -159,9 +159,8 @@ def _nc630a_write_block(radio, block_addr, block_size): cmd = struct.pack(">cHb", 'W', block_addr, BLOCK_SIZE) data = radio.get_mmap()[block_addr:block_addr + 8]
- if DEBUG: - print("Writing Data:") - print util.hexprint(cmd + data) + LOG.debug("Writing Data:") + LOG.debug(util.hexprint(cmd + data))
try: serial.write(cmd + data) @@ -190,9 +189,8 @@ def do_download(radio): block = _nc630a_read_block(radio, addr, BLOCK_SIZE) data += block
- if DEBUG: - print "Address: %04x" % addr - print util.hexprint(block) + LOG.debug("Address: %04x" % addr) + LOG.debug(util.hexprint(block))
_nc630a_exit_programming_mode(radio)
@@ -301,9 +299,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): if mem.tmode == "DTCS": mem.dtcs_polarity = "%s%s" % (tpol, rpol)
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, - rxmode, _mem.rx_tone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, + rxmode, _mem.rx_tone))
def get_memory(self, number): bitpos = (1 << ((number - 1) % 8)) @@ -387,9 +384,8 @@ class NC630aRadio(chirp_common.CloneModeRadio): else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone))
def set_memory(self, mem): bitpos = (1 << ((mem.number - 1) % 8)) diff --git a/chirp/leixen.py b/chirp/leixen.py index 1977f0c..285fe84 100644 --- a/chirp/leixen.py +++ b/chirp/leixen.py @@ -24,11 +24,6 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x0184; struct { diff --git a/chirp/puxing.py b/chirp/puxing.py index 88cbe79..f38b41e 100644 --- a/chirp/puxing.py +++ b/chirp/puxing.py @@ -20,11 +20,6 @@ import os from chirp import util, chirp_common, bitwise, errors, directory from chirp.wouxun_common import wipe_memory, do_download, do_upload
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def _puxing_prep(radio): radio.pipe.write("\x02PROGRA") ack = radio.pipe.read(1) diff --git a/chirp/th9800.py b/chirp/th9800.py index 3edc310..d1a1b0b 100644 --- a/chirp/th9800.py +++ b/chirp/th9800.py @@ -24,12 +24,10 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from chirp_common import format_freq import os import time +import logging from datetime import date
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
TH9800_MEM_FORMAT = """ struct mem { @@ -323,8 +321,7 @@ class TYTTH9800Base(chirp_common.Radio): _prev_active = self.get_active("chan_active", mem.number) self.set_active("chan_active", mem.number, not mem.empty) if mem.empty or not _prev_active: - if CHIRP_DEBUG: - print "initializing memory channel %d" % mem.number + LOG.debug("initializing memory channel %d" % mem.number) _mem.set_raw(BLANK_MEMORY)
if mem.empty: @@ -390,8 +387,7 @@ class TYTTH9800Base(chirp_common.Radio): _mem.step = STEPS.index(mem.tuning_step)
for setting in mem.extra: - if CHIRP_DEBUG: - print "@set_mem:", setting.get_name(), setting.value + LOG.debug("@set_mem:", setting.get_name(), setting.value) setattr(_mem, setting.get_name(), setting.value)
def get_settings(self): @@ -559,9 +555,7 @@ class TYTTH9800Base(chirp_common.Radio): oldval = getattr(_settings, setting) newval = element.value
- if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() @@ -666,12 +660,12 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): m = today.month d = today.day _info = radio._memobj.info - if CHIRP_DEBUG: - ly = _info.prog_yr - lm = _info.prog_mon - ld = _info.prog_day - print "Updating last program date:%d/%d/%d" % (lm,ld,ly) - print " to today:%d/%d/%d" % (m,d,y) + + ly = _info.prog_yr + lm = _info.prog_mon + ld = _info.prog_day + LOG.debug("Updating last program date:%d/%d/%d" % (lm,ld,ly)) + LOG.debug(" to today:%d/%d/%d" % (m,d,y))
_info.prog_yr = y _info.prog_mon = m @@ -680,8 +674,7 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): offset = 0x0100 for addr in range(offset, memsize, blocksize): mapaddr = addr + radio._mmap_offset - offset - if CHIRP_DEBUG: - print "addr: 0x%04X, mmapaddr: 0x%04X" % (addr, mapaddr) + 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) @@ -703,8 +696,7 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80):
# Checksum? final_data = radio.pipe.read(3) - if CHIRP_DEBUG: - print "final:", util.hexprint(final_data) + LOG.debug("final:", util.hexprint(final_data))
@directory.register class TYTTH9800Radio(TYTTH9800Base, chirp_common.CloneModeRadio, diff --git a/chirp/th_uv3r.py b/chirp/th_uv3r.py index 5e3e2c0..3b670fe 100644 --- a/chirp/th_uv3r.py +++ b/chirp/th_uv3r.py @@ -19,11 +19,6 @@ import os from chirp import chirp_common, bitwise, errors, directory from chirp.wouxun_common import do_download, do_upload
-if os.getenv("CHIRP_DEBUG"): - DEBUG = True -else: - DEBUG = False - def tyt_uv3r_prep(radio): try: radio.pipe.write("PROGRAMa") diff --git a/chirp/thd72.py b/chirp/thd72.py index 0d80adc..aa414de 100644 --- a/chirp/thd72.py +++ b/chirp/thd72.py @@ -15,9 +15,9 @@
from chirp import chirp_common, errors, util, directory from chirp import bitwise, memmap -import time, struct, sys +import time, struct, sys, logging
-DEBUG = True +LOG = logging.getLogger(__name__)
# TH-D72 memory map # 0x0000..0x0200: startup password and other stuff @@ -452,13 +452,11 @@ class THD72Radio(chirp_common.CloneModeRadio): start = time.time()
data = "" - if DEBUG: - print "PC->D72: %s" % cmd + LOG.debug("PC->D72: %s" % cmd) self.pipe.write(cmd + "\r") while not data.endswith("\r") and (time.time() - start) < timeout: data += self.pipe.read(1) - if DEBUG: - print "D72->PC: %s" % data.strip() + LOG.debug("D72->PC: %s" % data.strip()) return data.strip()
def get_id(self): diff --git a/chirp/tk8102.py b/chirp/tk8102.py index 32e8621..4cf291e 100644 --- a/chirp/tk8102.py +++ b/chirp/tk8102.py @@ -15,6 +15,7 @@
import struct import os +import logging
from chirp import chirp_common, directory, memmap, errors, util from chirp import bitwise @@ -22,6 +23,8 @@ from chirp.settings import RadioSettingGroup, RadioSetting from chirp.settings import RadioSettingValueBoolean, RadioSettingValueList from chirp.settings import RadioSettingValueString, RadioSettings
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x0030; struct { @@ -317,9 +320,8 @@ class KenwoodTKx102Radio(chirp_common.CloneModeRadio): else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone)) def set_memory(self, mem): _mem = self._memobj.memory[mem.number - 1]
diff --git a/chirp/tmv71_ll.py b/chirp/tmv71_ll.py index dac7f36..201412e 100644 --- a/chirp/tmv71_ll.py +++ b/chirp/tmv71_ll.py @@ -13,11 +13,11 @@ # 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 struct, time +import struct, time, logging
from chirp import memmap, chirp_common, errors
-DEBUG = True +LOG = logging.getLogger(__name__)
POS_MODE = 5 POS_DUP = 6 @@ -50,13 +50,11 @@ def command(s, cmd, timeout=0.5): start = time.time()
data = "" - if DEBUG: - print "PC->V71: %s" % cmd + LOG.debug("PC->V71: %s" % cmd) s.write(cmd + "\r") while not data.endswith("\r") and (time.time() - start) < timeout: data += s.read(1) - if DEBUG: - print "V71->PC: %s" % data.strip() + LOG.debug("V71->PC: %s" % data.strip()) return data.strip()
def get_id(s): diff --git a/chirp/uv5r.py b/chirp/uv5r.py index 6fcbae1..646d6e2 100644 --- a/chirp/uv5r.py +++ b/chirp/uv5r.py @@ -16,6 +16,7 @@ import struct import time import os +import logging
from chirp import chirp_common, errors, util, directory, memmap from chirp import bitwise @@ -25,10 +26,7 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueFloat, InvalidValueError, RadioSettings from textwrap import dedent
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x0008; @@ -394,8 +392,7 @@ def _firmware_version_from_image(radio): version = _firmware_version_from_data(radio.get_mmap(), radio._fw_ver_file_start, radio._fw_ver_file_stop) - if CHIRP_DEBUG: - print "_firmware_version_from_image: " + util.hexprint(version) + LOG.debug("_firmware_version_from_image: " + util.hexprint(version)) return version
def _special_block_from_data(data, special_block_start, special_block_stop): @@ -404,8 +401,7 @@ def _special_block_from_data(data, special_block_start, special_block_stop):
def _special_block_from_image(radio): special_block = _special_block_from_data(radio.get_mmap(), 0x0CFA, 0x0D01) - if CHIRP_DEBUG: - print "_special_block_from_image: " + util.hexprint(special_block) + LOG.debug("_special_block_from_image: " + util.hexprint(special_block)) return special_block
def _do_ident(radio, magic): @@ -504,19 +500,16 @@ def _do_download(radio): raise errors.RadioError("Incorrect 'Model' selected.")
# Main block - if CHIRP_DEBUG: - print "downloading main block..." + LOG.debug("downloading main block...") for i in range(0, 0x1800, 0x40): data += _read_block(radio, i, 0x40) _do_status(radio, i) - if CHIRP_DEBUG: - print "done." - print "downloading aux block..." + LOG.debug("done.") + LOG.debug("downloading aux block...") # Auxiliary block starts at 0x1ECO (?) for i in range(0x1EC0, 0x2000, 0x40): data += _read_block(radio, i, 0x40) - if CHIRP_DEBUG: - print "done." + LOG.debug("done.") return memmap.MemoryMap(data)
def _send_block(radio, addr, data): @@ -916,8 +909,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio,
def _is_orig(self): version_tag = _firmware_version_from_image(self) - if CHIRP_DEBUG: - print "@_is_orig, version_tag:", util.hexprint(version_tag) + LOG.debug("@_is_orig, version_tag: %s", util.hexprint(version_tag)) try: if 'BFB' in version_tag: idx = version_tag.index("BFB") + 3 diff --git a/chirp/vx170.py b/chirp/vx170.py index 20aac04..eaa7dbc 100644 --- a/chirp/vx170.py +++ b/chirp/vx170.py @@ -19,11 +19,6 @@ from textwrap import dedent import time, os from chirp import ft7800
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x018A; struct { diff --git a/chirp/vx2.py b/chirp/vx2.py index 3156806..6c6b912 100644 --- a/chirp/vx2.py +++ b/chirp/vx2.py @@ -19,12 +19,9 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueInteger, RadioSettingValueList, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings -import os, traceback, re +import os, traceback, re, logging
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False +LOG = logging.getLogger(__name__)
MEM_FORMAT = """ #seekto 0x7F52; @@ -410,9 +407,8 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): return VX2BankModel(self)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -421,9 +417,8 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(0, length): @@ -648,8 +643,7 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): for c in dtmfsetting.digits: if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -676,8 +670,7 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-1:]) - 1 _settings = self._memobj.dtmf[idx] _settings.digits = newval @@ -698,12 +691,10 @@ class VX2Radio(yaesu_clone.YaesuCloneModeRadio): newval = self._encode_chars(newval) if setting == "openmsg": newval = self._encode_chars(newval, 6) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() raise
- \ No newline at end of file + diff --git a/chirp/vx3.py b/chirp/vx3.py index 99d0951..0575a46 100644 --- a/chirp/vx3.py +++ b/chirp/vx3.py @@ -21,7 +21,9 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueString, \ RadioSettings from textwrap import dedent -import os, re +import os, re, logging + +LOG = logging.getLogger(__name__)
#interesting offsets which may be checksums needed later #0x0393 checksum1? @@ -29,11 +31,6 @@ import os, re #0x0409 checksum2? #0x04C9 checksum2a?
-if os.getenv("CHIRP_DEBUG"): - CHIRP_DEBUG = True -else: - CHIRP_DEBUG = False - MEM_FORMAT = """ #seekto 0x7F4A; u8 checksum; @@ -499,9 +496,8 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): return VX3BankModel(self)
def _decode_chars(self, inarr): - if CHIRP_DEBUG: - print "@_decode_chars, type: %s" % type(inarr) - print inarr + LOG.debug("@_decode_chars, type: %s" % type(inarr)) + LOG.debug(inarr) outstr = "" for i in inarr: if i == 0xFF: @@ -510,9 +506,8 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): return outstr.rstrip()
def _encode_chars(self, instr, length = 16): - if CHIRP_DEBUG: - print "@_encode_chars, type: %s" % type(instr) - print instr + LOG.debug("@_encode_chars, type: %s" % type(instr)) + LOG.debug(instr) outarr = [] instr = str(instr) for i in range(length): @@ -785,8 +780,7 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): for c in dtmfsetting.memory: if c < len(DTMFCHARSET): dtmfstr += DTMFCHARSET[c] - if CHIRP_DEBUG: - print dtmfstr + LOG.debug(dtmfstr) dtmfentry = RadioSettingValueString(0, 16, dtmfstr) dtmfentry.set_charset(DTMFCHARSET + list(" ")) rs = RadioSetting(name, name.upper(), dtmfentry) @@ -861,8 +855,7 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): newval.append(DTMFCHARSET.index(dtmfstr[i])) else: newval.append(0xFF) - if CHIRP_DEBUG: - print newval + LOG.debug(newval) idx = int(setting[-1:]) _settings = self._memobj.dtmf[idx] _settings.memory = newval @@ -885,11 +878,9 @@ class VX3Radio(yaesu_clone.YaesuCloneModeRadio): newval = self._encode_chars(newval) if setting == "openmsg": newval = self._encode_chars(newval, 6) - if CHIRP_DEBUG: - print "Setting %s(%s) <= %s" % (setting, - oldval, newval) + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) setattr(_settings, setting, newval) except Exception, e: print element.get_name() raise - \ No newline at end of file + diff --git a/chirp/vx8.py b/chirp/vx8.py index 02490a1..45fff7a 100644 --- a/chirp/vx8.py +++ b/chirp/vx8.py @@ -15,6 +15,7 @@
import os import re +import logging
from chirp import chirp_common, yaesu_clone, directory from chirp import bitwise @@ -23,6 +24,8 @@ from chirp.settings import RadioSettingValueInteger, RadioSettingValueString from chirp.settings import RadioSettingValueList, RadioSettingValueBoolean from textwrap import dedent
+LOG = logging.getLogger(__name__) + MEM_FORMAT = """ #seekto 0x047f; struct { @@ -1461,8 +1464,7 @@ class VX8DRadio(VX8Radio): is_latitude = name.endswith("latitude") lat_long = setting.value.get_value().strip() sign, l_d, l_m, l_s = cls._str_to_latlong(lat_long, is_latitude) - if os.getenv("CHIRP_DEBUG"): - print "%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s) + LOG.debug("%s: %d %d %d %d" % (name, sign, l_d, l_m, l_s)) setattr(obj, "%s_sign" % name, sign) setattr(obj, "%s_degree" % name, l_d) setattr(obj, "%s_minute" % name, l_m) @@ -1499,9 +1501,8 @@ class VX8DRadio(VX8Radio):
try: old_val = getattr(obj, setting) - if os.getenv("CHIRP_DEBUG"): - print "Setting %s(%r) <= %s" % ( - element.get_name(), old_val, element.value) + LOG.debug("Setting %s(%r) <= %s" % ( + 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" % ( diff --git a/chirp/wouxun.py b/chirp/wouxun.py index 6feec42..4a3dd0b 100644 --- a/chirp/wouxun.py +++ b/chirp/wouxun.py @@ -17,6 +17,7 @@
import time import os +import logging from chirp import util, chirp_common, bitwise, memmap, errors, directory from chirp.settings import RadioSetting, RadioSettingGroup, \ RadioSettingValueBoolean, RadioSettingValueList, \ @@ -25,6 +26,8 @@ from chirp.settings import RadioSetting, RadioSettingGroup, \ from chirp.wouxun_common import wipe_memory, do_download, do_upload from textwrap import dedent
+LOG = logging.getLogger(__name__) + FREQ_ENCODE_TABLE = [ 0x7, 0xa, 0x0, 0x9, 0xb, 0x2, 0xe, 0x1, 0x3, 0xf ]
def encode_freq(freq): @@ -717,9 +720,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, # always set it even if no dtcs is used mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N")
- if os.getenv("CHIRP_DEBUG"): - print "Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, - rxmode, _mem.rx_tone) + LOG.debug("Got TX %s (%i) RX %s (%i)" % (txmode, _mem.tx_tone, + rxmode, _mem.rx_tone))
def _is_txinh(self, _mem): raw_tx = "" @@ -817,9 +819,8 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, else: _mem.rx_tone = 0xFFFF
- if os.getenv("CHIRP_DEBUG"): - print "Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, - rx_mode, _mem.rx_tone) + LOG.debug("Set TX %s (%i) RX %s (%i)" % (tx_mode, _mem.tx_tone, + rx_mode, _mem.rx_tone))
def set_memory(self, mem): _mem = self._memobj.memory[mem.number - 1] diff --git a/chirp/wouxun_common.py b/chirp/wouxun_common.py index 3c78b3a..5b51e93 100644 --- a/chirp/wouxun_common.py +++ b/chirp/wouxun_common.py @@ -18,8 +18,11 @@
import struct import os +import logging from chirp import util, chirp_common, memmap
+LOG = logging.getLogger(__name__) + def wipe_memory(_mem, byte): """Cleanup a memory""" _mem.set_raw(byte * (_mem.size() / 8)) @@ -29,8 +32,7 @@ def do_download(radio, start, end, blocksize): image = "" for i in range(start, end, blocksize): cmd = struct.pack(">cHb", "R", i, blocksize) - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(cmd) + LOG.debug(util.hexprint(cmd)) radio.pipe.write(cmd) length = len(cmd) + blocksize resp = radio.pipe.read(length) @@ -61,8 +63,7 @@ def do_upload(radio, start, end, blocksize): chunk = radio.get_mmap()[ptr:ptr+blocksize] ptr += blocksize radio.pipe.write(cmd + chunk) - if os.getenv("CHIRP_DEBUG"): - print util.hexprint(cmd + chunk) + LOG.debug(util.hexprint(cmd + chunk))
ack = radio.pipe.read(1) if not ack == "\x06": diff --git a/chirp/yaesu_clone.py b/chirp/yaesu_clone.py index 57958c3..e8ec732 100644 --- a/chirp/yaesu_clone.py +++ b/chirp/yaesu_clone.py @@ -16,9 +16,11 @@ CMD_ACK = 0x06
from chirp import chirp_common, util, memmap, errors -import time, os +import time, os, logging from textwrap import dedent
+LOG = logging.getLogger(__name__) + def _safe_read(pipe, count): buf = "" first = True @@ -49,8 +51,7 @@ def _chunk_read(pipe, count, status_fn): status.max = count status.cur = len(data) status_fn(status) - if os.getenv("CHIRP_DEBUG"): - print "Read %i/%i" % (len(data), count) + LOG.debug("Read %i/%i" % (len(data), count)) return data
def __clone_in(radio): @@ -91,8 +92,7 @@ def _chunk_write(pipe, data, status_fn, block): chunk = data[i:i+block] pipe.write(chunk) count += len(chunk) - if os.getenv("CHIRP_DEBUG"): - print "@_chunk_write, count: %i, blocksize: %i" % (count,block) + LOG.debug("@_chunk_write, count: %i, blocksize: %i" % (count,block)) time.sleep(delay)
status = chirp_common.Status() @@ -120,8 +120,7 @@ def __clone_out(radio): for block in radio._block_lengths: blocks += 1 if blocks != len(radio._block_lengths): - if os.getenv("CHIRP_DEBUG"): - print "Sending %i-%i" % (pos, pos+block) + LOG.debug("Sending %i-%i" % (pos, pos+block)) pipe.write(radio.get_mmap()[pos:pos+block]) buf = pipe.read(1) if buf and buf[0] != chr(CMD_ACK): diff --git a/chirpui/reporting.py b/chirpui/reporting.py index c48c6bb..efe18c1 100644 --- a/chirpui/reporting.py +++ b/chirpui/reporting.py @@ -28,16 +28,18 @@ import threading import os import time +import logging
from chirp import CHIRP_VERSION, platform
REPORT_URL = "http://chirp.danplanet.com/report/report.php?do_report" ENABLED = True -DEBUG = os.getenv("CHIRP_DEBUG") == "y" THREAD_SEM = threading.Semaphore(10) # Maximum number of outstanding threads LAST = 0 LAST_TYPE = None
+LOG = logging.getLogger(__name__) + try: # Don't let failure to import any of these modules cause trouble from chirpui import config @@ -45,18 +47,14 @@ try: except: ENABLED = False
-def debug(string): - if DEBUG: - print string - def should_report(): if not ENABLED: - debug("Not reporting due to recent failure") + LOG.debug("Not reporting due to recent failure") return False
conf = config.get() if conf.get_bool("no_report"): - debug("Reporting disabled") + LOG.debug("Reporting disabled") return False
return True @@ -70,7 +68,7 @@ def _report_model_usage(model, direction, success): model = "%s_%s" % (model.VENDOR, model.MODEL) data = "%s,%s,%s" % (model, direction, success)
- debug("Reporting model usage: %s" % data) + LOG.debug("Reporting model usage: %s" % data)
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_stats(CHIRP_VERSION, @@ -84,7 +82,7 @@ def _report_model_usage(model, direction, success): def _report_exception(stack): global ENABLED
- debug("Reporting exception") + LOG.debug("Reporting exception")
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_exception(CHIRP_VERSION, @@ -98,7 +96,7 @@ def _report_exception(stack): def _report_misc_error(module, data): global ENABLED
- debug("Reporting misc error with %s" % module) + LOG.debug("Reporting misc error with %s" % module)
proxy = xmlrpclib.ServerProxy(REPORT_URL) id = proxy.report_misc_error(CHIRP_VERSION, @@ -109,12 +107,12 @@ def _report_misc_error(module, data): return id != 0
def _check_for_updates(callback): - debug("Checking for updates") + LOG.debug("Checking for updates") proxy = xmlrpclib.ServerProxy(REPORT_URL) ver = proxy.check_for_updates(CHIRP_VERSION, platform.get_platform().os_version_string())
- debug("Server reports version %s is latest" % ver) + LOG.debug("Server reports version %s is latest" % ver) callback(ver) return True
@@ -128,7 +126,7 @@ class ReportThread(threading.Thread): try: return self.__func(*self.__args) except Exception, e: - debug("Failed to report: %s" % e) + LOG.debug("Failed to report: %s" % e) return False
def run(self): @@ -139,7 +137,7 @@ class ReportThread(threading.Thread): ENABLED = False elif (time.time() - start) > 15: # Reporting took too long - debug("Time to report was %.2f sec -- Disabling" % \ + LOG.debug("Time to report was %.2f sec -- Disabling" % \ (time.time()-start)) ENABLED = False
@@ -151,13 +149,13 @@ def dispatch_thread(func, *args):
# If reporting is disabled or failing, bail if not should_report(): - debug("Reporting is disabled") + LOG.debug("Reporting is disabled") return
# If the time between now and the last report is less than 5 seconds, bail delta = time.time() - LAST if delta < 5 and func == LAST_TYPE: - debug("Throttling...") + LOG.debug("Throttling...") return
LAST = time.time() @@ -165,7 +163,7 @@ def dispatch_thread(func, *args):
# If there are already too many threads running, bail if not THREAD_SEM.acquire(False): - debug("Too many threads already running") + LOG.debug("Too many threads already running") return
t = ReportThread(func, *args)