[chirp_devel] [PATCH] Change match_model() to receive the filename of the image in question

Dan Smith
Tue Apr 3 17:53:37 PDT 2012


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1333499602 25200
# Node ID 742c736df8c6457ad91cec0c25c34b16c2d630de
# Parent  20ad7776a3832c5b3d1d356c3cd432a96b1acffe
Change match_model() to receive the filename of the image in question
and move detection of file-extension-based types to their respective
classes. The exception here is regular ICF files, which need to be
driverized and then they can be done this way as well.
Catch-all bug #93

diff -r 20ad7776a383 -r 742c736df8c6 chirp/alinco.py
--- a/chirp/alinco.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/alinco.py	Tue Apr 03 17:33:22 2012 -0700
@@ -298,7 +298,7 @@
     _range = [(28000000, 29695000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x28)
 
@@ -312,7 +312,7 @@
     _range = [(50000000, 53995000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x00) and filedata[0x65] == chr(0x50)
             
@@ -326,7 +326,7 @@
     _range = [(118000000, 173000000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x01) and filedata[0x65] == chr(0x44)
 
@@ -340,7 +340,7 @@
     _range = [(216000000, 280000000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x02) and filedata[0x65] == chr(0x22)
 
@@ -354,7 +354,7 @@
     _range = [(350000000, 511000000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x04) and filedata[0x65] == chr(0x00)
 
@@ -384,7 +384,7 @@
     _valid_tones = DJ596_TONES
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x64] == chr(0x45) and filedata[0x65] == chr(0x01)
 
@@ -398,6 +398,6 @@
     _range = [(216000000, 280000000)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize and \
             filedata[0x60:0x64] == "2009"
diff -r 20ad7776a383 -r 742c736df8c6 chirp/chirp_common.py
--- a/chirp/chirp_common.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/chirp_common.py	Tue Apr 03 17:33:22 2012 -0700
@@ -968,7 +968,7 @@
         return self._mmap
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         """Given contents of a stored file (@filedata), return True if 
         this radio driver handles the represented model"""
 
diff -r 20ad7776a383 -r 742c736df8c6 chirp/directory.py
--- a/chirp/directory.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/directory.py	Tue Apr 03 17:33:22 2012 -0700
@@ -85,15 +85,6 @@
         rf.set_params(float(lat), float(lon), email, passwd)
         return rf
     
-    if image_file.lower().endswith(".chirp"):
-        return get_radio("Generic_XML")(image_file)
-
-    if image_file.lower().endswith(".csv"):
-        return get_radio("Generic_CSV")(image_file)
-
-    if icf.is_9x_icf(image_file):
-        return get_radio("Icom_IC91_92AD_ICF")(image_file)
-
     if icf.is_icf_file(image_file):
         tempf = tempfile.mktemp()
         icf_to_image(image_file, tempf)
@@ -107,7 +98,7 @@
     for radio in DRV_TO_RADIO.values():
         if not issubclass(radio, chirp_common.CloneModeRadio):
             continue
-        if radio.match_model(filedata):
+        if radio.match_model(filedata, image_file):
             return radio(image_file)
     raise errors.ImageDetectFailed("Unknown file format")
 
diff -r 20ad7776a383 -r 742c736df8c6 chirp/ft2800.py
--- a/chirp/ft2800.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/ft2800.py	Tue Apr 03 17:33:22 2012 -0700
@@ -265,5 +265,5 @@
         _nam.name = mem.name.ljust(6)[:6]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize
diff -r 20ad7776a383 -r 742c736df8c6 chirp/ft817.py
--- a/chirp/ft817.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/ft817.py	Tue Apr 03 17:33:22 2012 -0700
@@ -479,7 +479,7 @@
         return msgs
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize
 
 @directory.register
diff -r 20ad7776a383 -r 742c736df8c6 chirp/icw32.py
--- a/chirp/icw32.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/icw32.py	Tue Apr 03 17:33:22 2012 -0700
@@ -184,7 +184,7 @@
         return [ICW32ARadioVHF(self._mmap), ICW32ARadioUHF(self._mmap)]
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         if not len(filedata) == cls._memsize:
             return False
         return filedata[-16:] == "IcomCloneFormat3"
diff -r 20ad7776a383 -r 742c736df8c6 chirp/vx5.py
--- a/chirp/vx5.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/vx5.py	Tue Apr 03 17:33:22 2012 -0700
@@ -181,5 +181,5 @@
         return chirp_common.name8(name)
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize
diff -r 20ad7776a383 -r 742c736df8c6 chirp/vx7.py
--- a/chirp/vx7.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/vx7.py	Tue Apr 03 17:33:22 2012 -0700
@@ -290,7 +290,7 @@
         return msgs
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == cls._memsize
 
     def get_bank_model(self):
diff -r 20ad7776a383 -r 742c736df8c6 chirp/wouxun.py
--- a/chirp/wouxun.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/wouxun.py	Tue Apr 03 17:33:22 2012 -0700
@@ -349,7 +349,7 @@
                 raise Exception("Character `%s' not supported")
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         # New-style image (CHIRP 0.1.12)
         if len(filedata) == 8192 and filedata[0x60:0x64] != "2009":
             return True
@@ -496,7 +496,7 @@
         self._memobj = bitwise.parse(puxing_mem_format, self._mmap)
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         if len(filedata) > 0x080B and \
                 ord(filedata[0x080B]) != PUXING_MODELS[777]:
             return False
@@ -711,7 +711,7 @@
         return rf
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return (len(filedata) == cls._memsize) and \
             filedata[-16:] != "IcomCloneFormat3"
 
@@ -1011,7 +1011,7 @@
         self._set_memory(mem, _rmem)
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return len(filedata) == 3648
 
     def get_raw_memory(self, number):
diff -r 20ad7776a383 -r 742c736df8c6 chirp/yaesu_clone.py
--- a/chirp/yaesu_clone.py	Tue Apr 03 12:47:50 2012 -0700
+++ b/chirp/yaesu_clone.py	Tue Apr 03 17:33:22 2012 -0700
@@ -183,7 +183,7 @@
         clone_out(self)
 
     @classmethod
-    def match_model(cls, filedata):
+    def match_model(cls, filedata, filename):
         return filedata[:5] == cls._model
 
     def _wipe_memory_banks(self, mem):



More information about the chirp_devel mailing list