Closed jimbraun closed 1 year ago
Hi Jim! Is this not implemented yet? in the pybindings directory I see there's a addField function but I cannot decode how the Write part should be done. cheers
Hi Edna,
No, I still have not implemented this. It should be straightforward to add the needed pybindings to XCDFFile and XCDFField, but there was never a pressing need to write XCDF files from Python. If you want to give a try, I can help; otherwise I'll keep this on my to-do list.
Hi Jim, sure! I want to give a try. It will be very helpfull If you guide me through it.
Hi Edna,
Sure. I'm not sure how much experience you have with XCDF and pybindings, so here's a high-level overview of the work. I'll answer any more specific questions you have. I'm happy to answer them, so don't worry about asking too many.
In order to write data from Python, the user will need to be able to create new XCDFField objects, add them to an XCDFFile object, add data to the XCDFField objects, and call XCDFFile::Write. The last part, exposing XCDFFile::Write, is trivial and would be a good starting point. For the rest, I imagine a new Python object that represents an XCDFField object (XCDFField PyObject) and exposes XCDFField::Add(). Since the fields must be added to the XCDFFile object, you also have to expose the XCDFFile::Allocate*Field functionality. I imagine you could bind three AllocateField methods to the XCDFFile PyObject, capture the returned XCDFField object and use that to build a new XCDFField PyObject that is returned to the user.
I recommend using templates judiciously to avoid duplicating code. Also, you may eventually want to consider the XCDFFile append functionality to complete the Python interface. Once you enable writing files from Python, it should be trivial to append to them from Python as well.
I think that the only thing missing now to close this issue are the allocation capabilities, am I correct?
See #100: append capabilities are actually already automatically exposed with the Open
method, though I forgot to add a unit test and an example in the documentation.
After this is there something else missing from what you describe in this issue? Otherwise, I think we can close it with #100 and continue from there depending on any new use case popping out.
Let's re-title this issue "Unable to create new XCDF files from Python". "AddField" is the missing piece of being able to use Python start-to-finish.
I am not sure that this it an informative title, as I can already create a file from Python see e.g.
https://xcdf-my-fork.readthedocs.io/en/latest/userguide.html#python-interface
This is why I was wondering if this issue could be closed and maybe we open a more specific one.
This AddField
you refer to is XCDFUtility::ADDField
? What does it do more than what we have now?
OK, I had forgotten that the previous PRs already added this feature. So I agree that this issue can be closed.
This means exposing the XCDFFile::Write() method. Most likely, we'll also need to create an XCDFField class (or 3 of them) and expose XCDFField::Add and XCDFField::Get().