[chirp_devel] [PATCH 10/17] Use logging in kenwood*.py (#2347)

Zachary T Welch
Wed Mar 4 21:15:06 PST 2015


# HG changeset patch
# User Zachary T Welch <zach at 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),




More information about the chirp_devel mailing list