[chirp_devel] [PATCH 1 of 2] Make Radio able to return multiple MemoryMapping objects

Dan Smith
Mon Apr 1 17:16:12 PDT 2013


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1364861756 25200
# Node ID d04801a1c0302d80d0dbfbc617b707da7ebcc389
# Parent  25c89f1e7aff1857b2a76a6bb8148ac15558a804
Make Radio able to return multiple MemoryMapping objects

This lays the groundwork for things like Scan Lists. Start by just defining
the new interface, making it call the old one, and updating import_logic
and the tests to match.

Related to #741

diff -r 25c89f1e7aff -r d04801a1c030 chirp/chirp_common.py
--- a/chirp/chirp_common.py	Mon Apr 01 16:40:48 2013 -0700
+++ b/chirp/chirp_common.py	Mon Apr 01 17:15:56 2013 -0700
@@ -981,9 +981,14 @@
         """Set the memory object @memory"""
         pass
 
-    def get_bank_model(self):
-        """Returns either a BankModel or None if not supported"""
-        return None
+    def get_mapping_models(self):
+        """Returns a list of MappingModel objects (or an empty list)"""
+        if hasattr(self, "get_bank_model"):
+            # FIXME: Backwards compatibility for old bank models
+            bank_model = self.get_bank_model()
+            if bank_model:
+                return [bank_model]
+        return []
 
     def get_raw_memory(self, number):
         """Return a raw string describing the memory at @number"""
diff -r 25c89f1e7aff -r d04801a1c030 chirp/import_logic.py
--- a/chirp/import_logic.py	Mon Apr 01 16:40:48 2013 -0700
+++ b/chirp/import_logic.py	Mon Apr 01 17:15:56 2013 -0700
@@ -210,18 +210,24 @@
                                     ", ".join(errs))
 
     return dst_mem
-        
+
+def _get_bank_model(radio):
+    for model in radio.get_mapping_models():
+        if isinstance(model, chirp_common.BankModel):
+            return model
+    return None
+
 def import_bank(dst_radio, src_radio, dst_mem, src_mem):
     """Attempt to set the same banks for @mem(by index) in @dst_radio that
     it has in @src_radio"""
 
-    dst_bm = dst_radio.get_bank_model()
+    dst_bm = _get_bank_model(dst_radio)
     if not dst_bm:
         return
 
     dst_banks = dst_bm.get_mappings()
 
-    src_bm = src_radio.get_bank_model()
+    src_bm = _get_bank_model(src_radio)
     if not src_bm:
         return
 
@@ -243,5 +249,3 @@
 
         except IndexError:
             pass
-
-    
diff -r 25c89f1e7aff -r d04801a1c030 tests/unit/test_import_logic.py
--- a/tests/unit/test_import_logic.py	Mon Apr 01 16:40:48 2013 -0700
+++ b/tests/unit/test_import_logic.py	Mon Apr 01 17:15:56 2013 -0700
@@ -347,8 +347,8 @@
                      chirp_common.Bank(src_bm, 3, '3'),
                      ]
 
-        self.mox.StubOutWithMock(dst_radio, 'get_bank_model')
-        self.mox.StubOutWithMock(src_radio, 'get_bank_model')
+        self.mox.StubOutWithMock(dst_radio, 'get_mapping_models')
+        self.mox.StubOutWithMock(src_radio, 'get_mapping_models')
         self.mox.StubOutWithMock(dst_bm, 'get_mappings')
         self.mox.StubOutWithMock(src_bm, 'get_mappings')
         self.mox.StubOutWithMock(dst_bm, 'get_memory_mappings')
@@ -356,9 +356,9 @@
         self.mox.StubOutWithMock(dst_bm, 'remove_memory_from_mapping')
         self.mox.StubOutWithMock(dst_bm, 'add_memory_to_mapping')
 
-        dst_radio.get_bank_model().AndReturn(dst_bm)
+        dst_radio.get_mapping_models().AndReturn([dst_bm])
         dst_bm.get_mappings().AndReturn(dst_banks)
-        src_radio.get_bank_model().AndReturn(src_bm)
+        src_radio.get_mapping_models().AndReturn([src_bm])
         src_bm.get_mappings().AndReturn(src_banks)
         src_bm.get_memory_mappings(src_mem).AndReturn([src_banks[0]])
         dst_bm.get_memory_mappings(dst_mem).AndReturn([dst_banks[1]])



More information about the chirp_devel mailing list