[chirp_devel] [PATCH 1 of 1] Add a new FileBackedRadio subclass between CloneModeRadio and Radio
Tom Hayward
Fri Apr 6 09:11:19 PDT 2012
# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1333721605 25200
# Node ID 34584e37cb7086abed774829515fb7dcf50d4ca3
# Parent 925f294665e14cb3527b4a682c505b9855952e29
Add a new FileBackedRadio subclass between CloneModeRadio and Radio
This helps to distinguish between purely file-based drivers (such as
CSV and XML) and a file-backed radio that can be uploaded (such as
all the current clone-type radios). This also changes the logic in
chirpui/clone.py that filters out drivers that can't be connected to
an actual device.
Related to Bug #102
diff -r 925f294665e1 -r 34584e37cb70 chirp/chirp_common.py
--- a/chirp/chirp_common.py Fri Apr 06 09:09:33 2012 -0600
+++ b/chirp/chirp_common.py Fri Apr 06 07:13:25 2012 -0700
@@ -904,28 +904,10 @@
return msgs
-class CloneModeRadio(Radio):
- """A clone-mode radio does a full memory dump in and out and we store
- an image of the radio into an image file"""
-
- _memsize = 0
-
+class FileBackedRadio(Radio):
+ """A file-backed radio stores its data in a file"""
FILE_EXTENSION = "img"
- def __init__(self, pipe):
- self.errors = []
- self._mmap = None
-
- if isinstance(pipe, str):
- self.pipe = None
- self.load_mmap(pipe)
- elif isinstance(pipe, memmap.MemoryMap):
- self.pipe = None
- self._mmap = pipe
- self.process_mmap()
- else:
- Radio.__init__(self, pipe)
-
def save(self, filename):
self.save_mmap(filename)
@@ -953,20 +935,12 @@
except IOError,e:
raise Exception("File Access Error")
- def sync_in(self):
- "Initiate a radio-to-PC clone operation"
- pass
-
- def sync_out(self):
- "Initiate a PC-to-radio clone operation"
- pass
+ def get_mmap(self):
+ return self._mmap
def get_memsize(self):
return self._memsize
- def get_mmap(self):
- return self._mmap
-
@classmethod
def match_model(cls, filedata, filename):
"""Given contents of a stored file (@filedata), return True if
@@ -979,6 +953,35 @@
# memories of the same size.
return len(filedata) == cls._memsize
+
+class CloneModeRadio(FileBackedRadio):
+ """A clone-mode radio does a full memory dump in and out and we store
+ an image of the radio into an image file"""
+
+ _memsize = 0
+
+ def __init__(self, pipe):
+ self.errors = []
+ self._mmap = None
+
+ if isinstance(pipe, str):
+ self.pipe = None
+ self.load_mmap(pipe)
+ elif isinstance(pipe, memmap.MemoryMap):
+ self.pipe = None
+ self._mmap = pipe
+ self.process_mmap()
+ else:
+ Radio.__init__(self, pipe)
+
+ def sync_in(self):
+ "Initiate a radio-to-PC clone operation"
+ pass
+
+ def sync_out(self):
+ "Initiate a PC-to-radio clone operation"
+ pass
+
class LiveRadio(Radio):
pass
diff -r 925f294665e1 -r 34584e37cb70 chirp/directory.py
--- a/chirp/directory.py Fri Apr 06 09:09:33 2012 -0600
+++ b/chirp/directory.py Fri Apr 06 07:13:25 2012 -0700
@@ -99,7 +99,7 @@
filedata = ""
for radio in DRV_TO_RADIO.values():
- if not issubclass(radio, chirp_common.CloneModeRadio):
+ if not issubclass(radio, chirp_common.FileBackedRadio):
continue
if radio.match_model(filedata, image_file):
return radio(image_file)
diff -r 925f294665e1 -r 34584e37cb70 chirp/generic_csv.py
--- a/chirp/generic_csv.py Fri Apr 06 09:09:33 2012 -0600
+++ b/chirp/generic_csv.py Fri Apr 06 07:13:25 2012 -0700
@@ -22,7 +22,7 @@
pass
@directory.register
-class CSVRadio(chirp_common.CloneModeRadio, chirp_common.IcomDstarSupport):
+class CSVRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
VENDOR = "Generic"
MODEL = "CSV"
FILE_EXTENSION = "csv"
@@ -57,7 +57,7 @@
self.memories.append(m)
def __init__(self, pipe):
- chirp_common.CloneModeRadio.__init__(self, None)
+ chirp_common.FileBackedRadio.__init__(self, None)
self._filename = pipe
if self._filename and os.path.exists(self._filename):
diff -r 925f294665e1 -r 34584e37cb70 chirp/xml.py
--- a/chirp/xml.py Fri Apr 06 09:09:33 2012 -0600
+++ b/chirp/xml.py Fri Apr 06 07:13:25 2012 -0700
@@ -62,7 +62,7 @@
return banks
@directory.register
-class XMLRadio(chirp_common.CloneModeRadio, chirp_common.IcomDstarSupport):
+class XMLRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
VENDOR = "Generic"
MODEL = "XML"
FILE_EXTENSION = "chirp"
diff -r 925f294665e1 -r 34584e37cb70 chirpui/clone.py
--- a/chirpui/clone.py Fri Apr 06 09:09:33 2012 -0600
+++ b/chirpui/clone.py Fri Apr 06 07:13:25 2012 -0700
@@ -65,7 +65,8 @@
def __make_vendor(self, model):
vendors = {}
for rclass in sorted(directory.DRV_TO_RADIO.values()):
- if rclass.VENDOR == "Generic":
+ if not issubclass(rclass, chirp_common.CloneModeRadio) and \
+ not issubclass(rclass, chirp_common.LiveRadio):
continue
if not vendors.has_key(rclass.VENDOR):
More information about the chirp_devel
mailing list