[chirp_devel] [PATCH 07/17] Use logging in drivers/t*.py (#2347)
Zachary T Welch
Wed Mar 4 21:15:03 PST 2015
# HG changeset patch
# User Zachary T Welch <zach at 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)
More information about the chirp_devel
mailing list