I did a bit of work on adding JSON support but it turned out I needed
to change a few things to get it to work. I also made some arbitary
decisions (see (1) below) which I'd like you guys to comment on.
First of all, JSON support is via simplejson. We could bundle this in
with cclib, or just expect users to install it if they wanted to use
this feature.
Here's the log message with some additional comments.
(1) Moved cclibData from logfileparser.py to ../data.py, and renamed to ccData
Rationale: this data is the core of the library. It doesn't really
below in any of cclib's submodules, so I moved it to the top level.
(2) Added methods to ccData: listify() and arrayify() to convert array
attributes to and from lists
Rationale: I think these will be useful in general, but they are
required for the JSON library, which doesn't handle arrays.
(3) Commented out __setattr__ magic, in favour of a call to arrayify()
in logfileparser.py
Rationale: this prevented listify() from working. As soon as I tried
to turn an array into a list, it automagically reverted it back to an
array.
(4) Added the writejson() method to ccData, which either returns a
JSON string, or writes it to a file
Rationale: well, this was the whole point
Notes:
(1) pickle now works, both for the arrayified ccData, and the listified one.
The pickled file is slightly smaller for the listified version, but
nothing major. We could add a writepickle() method. To be honest, I
think this would be overengineering.
(2) ccData._attrlist is duplicated by ccData._attrtypes.keys()
So...we should probably dump attrlist. Just something I noticed.
Regards,
Noel
|