[chirp_devel] [csv] Friendlier defaults for missing cToneFreq/rToneFreq columns in csv import - Fixes #1577
On Thu, Apr 24, 2014 at 8:09 PM, chirp.cordless@xoxy.net wrote:
Patch attached. -dan
I haven't tested it yet, but I see a few issues with style.
- Don't mix tabs and spaces. We prefer spaces.
- 0 is a number. You can (and should) use True and False in Python to represent booleans. This is a style thing, but it becomes important when another developer does a test like "1 is True". This evaluates False because the "is" operator is testing identity; 1 and True are different things.
Here's a Python trick you may not be aware of: + _file_has_rTone = 0 + _file_has_cTone = 0 + for header in headers: + if header == "rToneFreq": + _file_has_rTone = 1 + elif header == "cToneFreq": + _file_has_cTone = 1
Is equivalent to: _file_has_rTone = "rToneFreq" in headers _file_has_cTone = "cToneFreq" in headers
Short and sweet. It will iterate the list twice instead of once, but I think that's acceptable for readability.
Tom KD7LXL
I don't mean to nitpick, and I know I've ignored this for too long anyway. However, I don't really like this:
- def _clean_tmode(self, headers, line, mem):
""" If there is exactly one of [rToneFreq, cToneFreq] columns in the
csv file, use it for both rtone & ctone. Makes TSQL use friendlier."""
if not hasattr(self, "_file_has_rTone"):
self._file_has_rTone = "rToneFreq" in headers
if not hasattr(self, "_file_has_cTone"):
self._file_has_cTone = "cToneFreq" in headers
...because it modifies self in the middle of a method. Would you mind if we set those in __init__, perhaps just to None, and then set them True/False when we start the load?
If you don't want to spin it again, I'll just apply as-is and chalk it up to OCD, but I really think it'd be nicer.
--Dan
Patch attached -dan
- try:
fontsize = CONF.get_int("diff_fontsize", "developer")
- except Exception:
fontsize = 11
If you're going to add hidden configuration options (which I think is probably reasonable for these sorts of things), lets start a README.developers in the top level directory where we at least mention that they exist.
Also, please don't just catch Exception, here, catch whatever ConfigParser raises if it's not there.
- fontdesc = pango.FontDescription("Courier 11")
- fontdesc = pango.FontDescription("Courier %i" % fontsize)
I think some fonts don't have all the sizes between 1 and infinity. What happens if you specify something unsupported? If it's something we can catch and fall back to 11 again, that'd be good. That said, if it's a hidden developer-only tunable, it's not a huge deal.
But in general, if this makes things easier for you, I'm cool with it.
Thanks!
--Dan
participants (3)
-
chirp.cordless@xoxy.net
-
Dan Smith
-
Tom Hayward