[chirp_devel] [developer] Control address format for full-file dump/diff - #1767
chirp.cordless at xoxy.net
Thu Jul 17 18:24:48 PDT 2014
On Jul 15, 2014, at 6:26 PM, Dan Smith - dsmith at danplanet.com wrote:
>> The second thing is that my own preferred format is "both"
>> which sort of breaks your model:
>>>> out + "%04i x%04X: " % ((i * line_sz), (i * line_sz))
>
> I think you could do this:
>
> result fmt % locals()
>
> and then I could make a format like this to get what you want:
>
> "%(line_sz)04i %(line_sz)04X"
>
> Should be less code than what you have now and more flexible I think.
> Just catch ValueError, TypeError, and KeyError and you should be safe
> for error handling I think.
>
> --Dan
I hadn't seen that form of string formatting before, and it makes
this flexible approach much more reasonable. However, it doesn't
_quite_ work because the config read seems to object to the "(name)"
embedded in the format. Stack trace at the end if you're curious.
I tried several forms of quoting and escaping without success.
But I've got a variant that does work, and I'm happier with it because it
presents fewer ways for the user to do something strange.
The core of it is a config variable of the form
hexdump_addrfmt = %04i x%04X
and this code:
addrfmt = addrfmt.replace ("%", "%(addr)")
...
out += addrfmt % { "addr" : i * line_sz }
So far the only exceptions I've been able to throw are OverflowError
for %c, and ValueError for %Q. Catching Overflow and replacing with %03i
causes a very strange display, but a display results.
All the integer formats, as well as %s, %r, and even %E all do something
reasonable.
Shall I submit a patch based on this approach?
-dan
=====================================
Traceback (most recent call last):
File "/Users/dan/chirpwork/dev_work/chirp.hg/chirpui/mainapp.py", line 1418, in mh
self.do_diff_radio()
File "/Users/dan/chirpwork/dev_work/chirp.hg/chirpui/mainapp.py", line 227, in do_diff_radio
a = util.hexprint(eset_a.rthread.radio._mmap.get_packed())
File "/Users/dan/chirpwork/dev_work/chirp.hg/chirp/util.py", line 35, in hexprint
addrfmt = CONF.get("hexdump_addrfmt", "developer")
File "/Users/dan/chirpwork/dev_work/chirp.hg/chirpui/config.py", line 69, in get
return self._config.get(key, section or self._section)
File "/Users/dan/chirpwork/dev_work/chirp.hg/chirpui/config.py", line 46, in get
return self.__config.get(section, key)
File "/opt/kk7ds/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py", line 615, in get
return self._interpolate(section, option, value, d)
File "/opt/kk7ds/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py", line 661, in _interpolate
option, section, rawval, e.args[0])
ConfigParser.InterpolationMissingOptionError: Bad value substitution:
section: [developer]
option : hexdump_addrfmt
key : addr
rawval : %(addr)04i x%(addr)04X
=====================================
More information about the chirp_devel
mailing list