egemenimre/ccsds-ndm

Cannot write KVN file (`'Ndm' object has no attribute 'id'`)

astrojuanlu opened this issue · 4 comments

I tried the following:

ndm = NdmIo().from_path("omm_combined.xml")  # omm_combined.xml from the repository
NdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn"))

but it failed with this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-60823d5a4046> in <module>
----> 1 NdmIo().to_file(ndm, NDMFileFormats.KVN, Path("new.kvn"))

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_io.py in to_file(self, ndm_obj, data_format, xml_write_file_path, **kwargs)
    158 
    159         if data_format is NDMFileFormats.KVN:
--> 160             return NdmKvnIo().to_file(ndm_obj, xml_write_file_path)
    161 
    162         if data_format is NDMFileFormats.JSON:

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_file(self, ndm_obj, kvn_write_file_path)
    226             Path of the XML file to be written
    227         """
--> 228         kvn_write_file_path.write_text(self.to_string(ndm_obj))
    229 
    230     def to_string(self, ndm_obj):

~/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/ccsds_ndm/ndm_kvn_io.py in to_string(self, ndm_obj)
    242             given object tree as KVN string
    243         """
--> 244         out_str = [_fill_str_out_kvn(ndm_obj.id, ndm_obj.version)]
    245         self._collate_str_out("", ndm_obj, out_str)
    246 

AttributeError: 'Ndm' object has no attribute 'id'

Am I doing anything wrong?

Thanks @egemenimre ! I have been able to write an OMM combined file in XML though, and reading it works fine too. I guess you mean that KVN is not supported for combined files?

Eventually chaos on my end has let up a bit and I was able to look at this.

I checked the standard and couldn't find a Combined NDM in KVN format at first glance.

I have now added a proper NotImplementedError and a meaningful error message if you try to output a Combined NDM to KVN. I will issue a new version in a couple of days. Closing this for now.