# HG changeset patch
# User Charles Stewart <chuckination@gmail.com>
# Date 1428197022 14400
#      Sat Apr 04 21:23:42 2015 -0400
# Node ID e7e4bf926bc47f200f3265dd0cbc6a0528083e6f
# Parent  4e970afe0a97d3d5f52165a1705c848f5e670825
[ts2000] PEP-8 cleanups for ts2000.py and kenwood_live.py drivers. Fixes #217

diff -r 4e970afe0a97 -r e7e4bf926bc4 chirp/drivers/kenwood_live.py
--- a/chirp/drivers/kenwood_live.py	Sun Mar 29 00:55:40 2015 -0400
+++ b/chirp/drivers/kenwood_live.py	Sat Apr 04 21:23:42 2015 -0400
@@ -77,6 +77,7 @@

     return result.strip()

+
 def get_id(ser):
     """Get the ID of the radio attached to @ser"""
     global LAST_BAUD
@@ -85,14 +86,13 @@
     bauds.insert(0, LAST_BAUD)

     global LAST_DELIMITER
-    command_delimiters = [("\r"," "), (";","")]
+    command_delimiters = [("\r", " "), (";", "")]

     for i in bauds:
-        curj = 0
-        for j in command_delimiters:
-            curj += 1
-            LAST_DELIMITER = j
-            LOG.info("Trying ID at baud %i with delimiter check #%i" % (i, curj))
+        for delimiter in command_delimiters:
+            LAST_DELIMITER = delimiter
+            LOG.info("Trying ID at baud %i with delimiter \"%s\"" %
+                     (i, repr(delimiter)))
             ser.setBaudrate(i)
             ser.write(LAST_DELIMITER[0])
             ser.read(25)
@@ -110,6 +110,7 @@

     raise errors.RadioError("No response from radio")

+
 def get_tmode(tone, ctcss, dcs):
     """Get the tone mode based on the values of the tone, ctcss, dcs"""
     if dcs and int(dcs) == 1:
@@ -121,6 +122,7 @@
     else:
         return ""

+
 def iserr(result):
     """Returns True if the @result from a radio is an error"""
     return result in ["N", "?"]
diff -r 4e970afe0a97 -r e7e4bf926bc4 chirp/drivers/ts2000.py
--- a/chirp/drivers/ts2000.py	Sun Mar 29 00:55:40 2015 -0400
+++ b/chirp/drivers/ts2000.py	Sat Apr 04 21:23:42 2015 -0400
@@ -16,7 +16,8 @@
 import re
 from chirp import chirp_common, directory, util, errors
 from chirp.drivers import kenwood_live
-from chirp.drivers.kenwood_live import NOCACHE, KenwoodLiveRadio, command, iserr
+from chirp.drivers.kenwood_live import KenwoodLiveRadio, \
+    command, iserr, NOCACHE

 TS2000_SSB_STEPS = [1.0, 2.5, 5.0, 10.0]
 TS2000_FM_STEPS = [5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0, 100.0]
@@ -29,6 +30,7 @@
 TS2000_TONES = list(chirp_common.OLD_TONES)
 TS2000_TONES.remove(69.3)

+
 @directory.register
 class TS2000Radio(KenwoodLiveRadio):
     """Kenwood TS-2000"""
@@ -77,14 +79,9 @@
     def _cmd_cur_memory(self, number):
         return "MC"

-    def _cmd_get_split(self, number):
-        return "MR1%03i" % number
-
-    def _cmd_set_split(self, number, spec):
-        return "MW1%03i%s" % (number, spec)
-
     def _cmd_erase_memory(self, number):
-        # write a memory channel that's effectively zeroed except the channel number
+        # write a memory channel that's effectively zeroed except
+        # for the channel number
         return "MW%04i%035i" % (number, 0)

     def erase_memory(self, number):
@@ -98,7 +95,7 @@

     def get_memory(self, number):
         if number < 0 or number > self._upper:
-            raise errors.InvalidMemoryLocation( \
+            raise errors.InvalidMemoryLocation(
                 "Number must be between 0 and %i" % self._upper)
         if number in self._memcache and not NOCACHE:
             return self._memcache[number]
@@ -111,8 +108,6 @@
             self._memcache[mem.number] = mem
             return mem

-        spec = result[2:]
-
         mem = self._parse_mem_spec(result)
         self._memcache[mem.number] = mem

@@ -122,41 +117,42 @@
             self._parse_split_spec(mem, result)

         return mem
-
+
     def _parse_mem_spec(self, spec):
         mem = chirp_common.Memory()

         # pad string so indexes match Kenwood docs
         spec = " " + spec
-
+
         # use the same variable names as the Kenwood docs
-        _p1  = spec[3]
-        _p2  = spec[4]
-        _p3  = spec[5:7]
-        _p4  = spec[7:18]
-        _p5  = spec[18]
-        _p6  = spec[19]
-        _p7  = spec[20]
-        _p8  = spec[21:23]
-        _p9  = spec[23:25]
+        #_p1  = spec[3]
+        _p2 = spec[4]
+        _p3 = spec[5:7]
+        _p4 = spec[7:18]
+        _p5 = spec[18]
+        _p6 = spec[19]
+        _p7 = spec[20]
+        _p8 = spec[21:23]
+        _p9 = spec[23:25]
         _p10 = spec[25:28]
-        _p11 = spec[28]
+        #_p11 = spec[28]
         _p12 = spec[29]
         _p13 = spec[30:39]
         _p14 = spec[39:41]
-        _p15 = spec[41]
+        #_p15 = spec[41]
         _p16 = spec[42:49]

-        mem.number = int(_p2 + _p3) # concat bank num and chan num
+        mem.number = int(_p2 + _p3)     # concat bank num and chan num
         mem.freq = int(_p4)
         mem.mode = TS2000_MODES[int(_p5)]
         mem.skip = ["", "S"][int(_p6)]
         mem.tmode = TS2000_TMODES[int(_p7)]
-        mem.rtone = self._kenwood_valid_tones[int(_p8) - 1] # PL is 1 indexed
-        mem.ctone = self._kenwood_valid_tones[int(_p9) - 1] # CTCSS is 1 indexed
-        mem.dtcs = chirp_common.DTCS_CODES[int(_p10)]       # DCS is 0 indexed
+        # PL and T-SQL are 1 indexed, DTCS is 0 indexed
+        mem.rtone = self._kenwood_valid_tones[int(_p8) - 1]
+        mem.ctone = self._kenwood_valid_tones[int(_p9) - 1]
+        mem.dtcs = chirp_common.DTCS_CODES[int(_p10)]
         mem.duplex = TS2000_DUPLEX[int(_p12)]
-        mem.offset = int(_p13) # 9-digit
+        mem.offset = int(_p13)  # 9-digit
         if mem.mode in ["AM", "FM"]:
             mem.tuning_step = TS2000_FM_STEPS[int(_p14)]
         else:
@@ -164,12 +160,12 @@
         mem.name = _p16

         return mem
-
+
     def _parse_split_spec(self, mem, spec):

         # pad string so indexes match Kenwood docs
         spec = " " + spec
-
+
         # use the same variable names as the Kenwood docs
         split_freq = int(spec[7:18])
         if mem.freq != split_freq:
@@ -180,7 +176,7 @@

     def set_memory(self, memory):
         if memory.number < 0 or memory.number > self._upper:
-            raise errors.InvalidMemoryLocation( \
+            raise errors.InvalidMemoryLocation(
                 "Number must be between 0 and %i" % self._upper)

         spec = self._make_mem_spec(memory)
@@ -198,19 +194,20 @@
                 if match is not None:
                     cur_mem = int(match.group(1))
                     if cur_mem == memory.number:
-                        cur_mem = command(self.pipe, *self._cmd_recall_memory(memory.number))
+                        cur_mem = command(self.pipe,
+                                    *self._cmd_recall_memory(memory.number))
         else:
             raise errors.InvalidDataError("Radio refused %i" % memory.number)

         # FIXME
-        if memory.duplex == "split" and self._kenwood_split:
+        if memory.duplex == "split" and self._kenwood_split:
             spec = "".join(self._make_split_spec(memory))
             result = command(self.pipe, *self._cmd_set_split(memory.number,
                                                              spec))
             if iserr(result):
-                raise errors.InvalidDataError("Radio refused %i" % \
-                                                  memory.number)
-
+                raise errors.InvalidDataError("Radio refused %i" %
+                                              memory.number)
+
     def _make_mem_spec(self, mem):
         if mem.duplex in " +-":
             duplex = util.get_dict_rev(TS2000_DUPLEX, mem.duplex)
@@ -232,11 +229,12 @@
             ctone = 0
             dtcs = 0
         else:
-            rtone = (self._kenwood_valid_tones.index(mem.rtone) + 1)    # PL is 1 indexed
-            ctone = (self._kenwood_valid_tones.index(mem.ctone) + 1)    # CTCSS is 1 indexed
-            dtcs = (chirp_common.DTCS_CODES.index(mem.dtcs))            # DCS is 0 indexed
+            # PL and T-SQL are 1 indexed, DTCS is 0 indexed
+            rtone = (self._kenwood_valid_tones.index(mem.rtone) + 1)
+            ctone = (self._kenwood_valid_tones.index(mem.ctone) + 1)
+            dtcs = (chirp_common.DTCS_CODES.index(mem.dtcs))

-        spec = ( \
+        spec = (
             "%011i" % mem.freq,
             "%i" % (TS2000_MODES.index(mem.mode)),
             "%i" % (mem.skip == "S"),
@@ -244,23 +242,21 @@
             "%02i" % (rtone),
             "%02i" % (ctone),
             "%03i" % (dtcs),
-            "0", # REVERSE status
+            "0",    # REVERSE status
             "%i" % duplex,
             "%09i" % offset,
             "%02i" % step,
-            "0", # Memory Group number (0-9)
+            "0",    # Memory Group number (0-9)
             "%s" % mem.name,
         )

         return spec
-
+
     def _make_split_spec(self, mem):
         if mem.duplex in " +-":
             duplex = util.get_dict_rev(TS2000_DUPLEX, mem.duplex)
-            offset = mem.offset
         elif mem.duplex == "split":
             duplex = 0
-            offset = 0
         else:
             print "Bug: unsupported duplex `%s'" % mem.duplex
         if mem.mode in ["AM", "FM"]:
@@ -275,11 +271,12 @@
             ctone = 0
             dtcs = 0
         else:
-            rtone = (self._kenwood_valid_tones.index(mem.rtone) + 1)    # PL is 1 indexed
-            ctone = (self._kenwood_valid_tones.index(mem.ctone) + 1)    # CTCSS is 1 indexed
-            dtcs = (chirp_common.DTCS_CODES.index(mem.dtcs))            # DCS is 0 indexed
+            # PL and T-SQL are 1 indexed, DTCS is 0 indexed
+            rtone = (self._kenwood_valid_tones.index(mem.rtone) + 1)
+            ctone = (self._kenwood_valid_tones.index(mem.ctone) + 1)
+            dtcs = (chirp_common.DTCS_CODES.index(mem.dtcs))

-        spec = ( \
+        spec = (
             "%011i" % mem.offset,
             "%i" % (TS2000_MODES.index(mem.mode)),
             "%i" % (mem.skip == "S"),
@@ -287,11 +284,11 @@
             "%02i" % (rtone),
             "%02i" % (ctone),
             "%03i" % (dtcs),
-            "0", # REVERSE status
+            "0",    # REVERSE status
             "%i" % duplex,
             "%09i" % 0,
             "%02i" % step,
-            "0", # Memory Group number (0-9)
+            "0",    # Memory Group number (0-9)
             "%s" % mem.name,
         )

