[chirp_devel] [PATCH 1 of 2] Rename chirp/xml.py to chirp/generic_xml.py so it doesn't conflict with the xml module
Tom Hayward
Tue Apr 10 09:00:48 PDT 2012
# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1334073618 21600
# Node ID 806b80ebe58e7d62f62ee9d6e9ab0fc929236e49
# Parent 86b87e37879200f579a4edee085b3238ea0800c1
Rename chirp/xml.py to chirp/generic_xml.py so it doesn't conflict with the xml module.
Required for Feature #114
diff -r 86b87e378792 -r 806b80ebe58e chirp/generic_xml.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/chirp/generic_xml.py Tue Apr 10 10:00:18 2012 -0600
@@ -0,0 +1,152 @@
+# Copyright 2008 Dan Smith <dsmith at danplanet.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import libxml2
+
+from chirp import chirp_common, errors, xml_ll, platform, directory
+
+def validate_doc(doc):
+ basepath = platform.get_platform().executable_path()
+ path = os.path.abspath(os.path.join(basepath, "chirp.xsd"))
+ if not os.path.exists(path):
+ path = "/usr/share/chirp/chirp.xsd"
+
+ try:
+ ctx = libxml2.schemaNewParserCtxt(path)
+ schema = ctx.schemaParse()
+ except libxml2.parserError, e:
+ print "Unable to load schema: %s" % e
+ print "Path: %s" % path
+ raise errors.RadioError("Unable to load schema")
+
+ del ctx
+
+ errs = []
+ warnings = []
+
+ def err(msg, arg=None):
+ errs.append("ERROR: %s" % msg)
+
+ def wrn(msg, arg=None):
+ print "WARNING: %s" % msg
+ warnings.append("WARNING: %s" % msg)
+
+ validCtx = schema.schemaNewValidCtxt()
+ validCtx.setValidityErrorHandler(err, wrn)
+ err = validCtx.schemaValidateDoc(doc)
+ print os.linesep.join(warnings)
+ if err:
+ print "---DOC---\n%s\n------" % doc.serialize(format=1)
+ print os.linesep.join(errs)
+ raise errors.RadioError("Schema error")
+
+def default_banks():
+ banks = []
+
+ for i in range(0, 26):
+ banks.append("Bank-%s" % (chr(ord("A") + i)))
+
+ return banks
+
+ at directory.register
+class XMLRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
+ VENDOR = "Generic"
+ MODEL = "XML"
+ FILE_EXTENSION = "chirp"
+
+ def __init__(self, pipe):
+ chirp_common.FileBackedRadio.__init__(self, None)
+ self._filename = pipe
+ if self._filename and os.path.exists(self._filename):
+ self.doc = libxml2.parseFile(self._filename)
+ validate_doc(self.doc)
+ else:
+ self.doc = libxml2.newDoc("1.0")
+ radio = self.doc.newChild(None, "radio", None)
+ radio.newChild(None, "memories", None)
+ radio.newChild(None, "banks", None)
+ radio.newProp("version", "0.1.1")
+
+ def get_features(self):
+ rf = chirp_common.RadioFeatures()
+ rf.has_bank = False
+ #rf.has_bank_index = True
+ rf.requires_call_lists = False
+ rf.has_implicit_calls = False
+ rf.memory_bounds = (0, 1000)
+ rf.valid_characters = chirp_common.CHARSET_ASCII
+ rf.valid_name_length = 999
+ rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS"]
+ return rf
+
+ def load(self, filename=None):
+ if not self._filename and not filename:
+ raise errors.RadioError("Need a location to load from")
+
+ if filename:
+ self._filename = filename
+
+ self.doc = libxml2.parseFile(self._filename)
+ validate_doc(self.doc)
+
+ def save(self, filename=None):
+ if not self._filename and not filename:
+ raise errors.RadioError("Need a location to save to")
+
+ if filename:
+ self._filename = filename
+
+ f = file(self._filename, "w")
+ f.write(self.doc.serialize(format=1))
+ f.close()
+
+ def get_memories(self, lo=0, hi=999):
+ mems = []
+ for i in range(lo, hi):
+ try:
+ mems.append(xml_ll.get_memory(self.doc, i))
+ except errors.InvalidMemoryLocation:
+ pass
+
+ return mems
+
+ def get_memory(self, number):
+ mem = xml_ll.get_memory(self.doc, number)
+
+ return mem
+
+ def set_memory(self, mem):
+ xml_ll.set_memory(self.doc, mem)
+
+ def erase_memory(self, number):
+ xml_ll.del_memory(self.doc, number)
+
+ @classmethod
+ def match_model(cls, filedata, filename):
+ return filename.lower().endswith("." + cls.FILE_EXTENSION)
+
+if __name__ == "__main__":
+ r = XMLRadio("testmem.chirp")
+
+ print r.get_memory(3)
+
+ m = chirp_common.Memory()
+ m.name = "TestMem2"
+ m.freq = 123.456
+ m.number = 10
+
+ #r.set_memory(m)
+ #r.erase_memory(10)
diff -r 86b87e378792 -r 806b80ebe58e chirp/xml.py
--- a/chirp/xml.py Mon Apr 09 18:38:22 2012 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-# Copyright 2008 Dan Smith <dsmith at danplanet.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import libxml2
-
-from chirp import chirp_common, errors, xml_ll, platform, directory
-
-def validate_doc(doc):
- basepath = platform.get_platform().executable_path()
- path = os.path.abspath(os.path.join(basepath, "chirp.xsd"))
- if not os.path.exists(path):
- path = "/usr/share/chirp/chirp.xsd"
-
- try:
- ctx = libxml2.schemaNewParserCtxt(path)
- schema = ctx.schemaParse()
- except libxml2.parserError, e:
- print "Unable to load schema: %s" % e
- print "Path: %s" % path
- raise errors.RadioError("Unable to load schema")
-
- del ctx
-
- errs = []
- warnings = []
-
- def err(msg, arg=None):
- errs.append("ERROR: %s" % msg)
-
- def wrn(msg, arg=None):
- print "WARNING: %s" % msg
- warnings.append("WARNING: %s" % msg)
-
- validCtx = schema.schemaNewValidCtxt()
- validCtx.setValidityErrorHandler(err, wrn)
- err = validCtx.schemaValidateDoc(doc)
- print os.linesep.join(warnings)
- if err:
- print "---DOC---\n%s\n------" % doc.serialize(format=1)
- print os.linesep.join(errs)
- raise errors.RadioError("Schema error")
-
-def default_banks():
- banks = []
-
- for i in range(0, 26):
- banks.append("Bank-%s" % (chr(ord("A") + i)))
-
- return banks
-
- at directory.register
-class XMLRadio(chirp_common.FileBackedRadio, chirp_common.IcomDstarSupport):
- VENDOR = "Generic"
- MODEL = "XML"
- FILE_EXTENSION = "chirp"
-
- def __init__(self, pipe):
- chirp_common.FileBackedRadio.__init__(self, None)
- self._filename = pipe
- if self._filename and os.path.exists(self._filename):
- self.doc = libxml2.parseFile(self._filename)
- validate_doc(self.doc)
- else:
- self.doc = libxml2.newDoc("1.0")
- radio = self.doc.newChild(None, "radio", None)
- radio.newChild(None, "memories", None)
- radio.newChild(None, "banks", None)
- radio.newProp("version", "0.1.1")
-
- def get_features(self):
- rf = chirp_common.RadioFeatures()
- rf.has_bank = False
- #rf.has_bank_index = True
- rf.requires_call_lists = False
- rf.has_implicit_calls = False
- rf.memory_bounds = (0, 1000)
- rf.valid_characters = chirp_common.CHARSET_ASCII
- rf.valid_name_length = 999
- rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS"]
- return rf
-
- def load(self, filename=None):
- if not self._filename and not filename:
- raise errors.RadioError("Need a location to load from")
-
- if filename:
- self._filename = filename
-
- self.doc = libxml2.parseFile(self._filename)
- validate_doc(self.doc)
-
- def save(self, filename=None):
- if not self._filename and not filename:
- raise errors.RadioError("Need a location to save to")
-
- if filename:
- self._filename = filename
-
- f = file(self._filename, "w")
- f.write(self.doc.serialize(format=1))
- f.close()
-
- def get_memories(self, lo=0, hi=999):
- mems = []
- for i in range(lo, hi):
- try:
- mems.append(xml_ll.get_memory(self.doc, i))
- except errors.InvalidMemoryLocation:
- pass
-
- return mems
-
- def get_memory(self, number):
- mem = xml_ll.get_memory(self.doc, number)
-
- return mem
-
- def set_memory(self, mem):
- xml_ll.set_memory(self.doc, mem)
-
- def erase_memory(self, number):
- xml_ll.del_memory(self.doc, number)
-
- @classmethod
- def match_model(cls, filedata, filename):
- return filename.lower().endswith("." + cls.FILE_EXTENSION)
-
-if __name__ == "__main__":
- r = XMLRadio("testmem.chirp")
-
- print r.get_memory(3)
-
- m = chirp_common.Memory()
- m.name = "TestMem2"
- m.freq = 123.456
- m.number = 10
-
- #r.set_memory(m)
- #r.erase_memory(10)
diff -r 86b87e378792 -r 806b80ebe58e chirpui/editorset.py
--- a/chirpui/editorset.py Mon Apr 09 18:38:22 2012 -0700
+++ b/chirpui/editorset.py Tue Apr 10 10:00:18 2012 -0600
@@ -17,7 +17,7 @@
import gtk
import gobject
-from chirp import chirp_common, directory, generic_csv, xml
+from chirp import chirp_common, directory, generic_csv, generic_xml
from chirpui import memedit, dstaredit, bankedit, common, importdialog
from chirpui import inputdialog, reporting, settingsedit
@@ -279,7 +279,7 @@
if filen.lower().endswith(".csv"):
dst_radio = generic_csv.CSVRadio(filen)
elif filen.lower().endswith(".chirp"):
- dst_radio = xml.XMLRadio(filen)
+ dst_radio = generic_xml.XMLRadio(filen)
else:
raise Exception(_("Unsupported file type"))
except Exception, e:
diff -r 86b87e378792 -r 806b80ebe58e chirpui/importdialog.py
--- a/chirpui/importdialog.py Mon Apr 09 18:38:22 2012 -0700
+++ b/chirpui/importdialog.py Tue Apr 10 10:00:18 2012 -0600
@@ -17,7 +17,7 @@
import gobject
import pango
-from chirp import errors, chirp_common, xml, import_logic
+from chirp import errors, chirp_common, generic_xml, import_logic
from chirpui import common
class WaitWindow(gtk.Window):
@@ -225,7 +225,7 @@
print "One or more of the radios doesn't support banks"
return
- if not isinstance(self.dst_radio, xml.XMLRadio) and \
+ if not isinstance(self.dst_radio, generic_xml.XMLRadio) and \
len(dst_banks) != len(src_banks):
print "Source and destination radios have a different number of banks"
else:
diff -r 86b87e378792 -r 806b80ebe58e chirpui/mainapp.py
--- a/chirpui/mainapp.py Mon Apr 09 18:38:22 2012 -0700
+++ b/chirpui/mainapp.py Tue Apr 10 10:00:18 2012 -0600
@@ -34,7 +34,7 @@
except ImportError,e:
common.log_exception()
common.show_error("\nThe Pyserial module is not installed!")
-from chirp import platform, xml, generic_csv, directory, util
+from chirp import platform, generic_xml, generic_csv, directory, util
from chirp import ic9x, kenwood_live, idrp, vx7, vx5
from chirp import CHIRP_VERSION, chirp_common, detect, errors
from chirp import icf, ic9x_icf
More information about the chirp_devel
mailing list