mpenning/ciscoconfparse2

[Bug]: save_as not working

Closed this issue · 1 comments

Contact Details

No response

What happened?

When executing save_as i ran into an error instead of writing the config into the new file.

I was also able to fix this manually by changing ciscoconfparse2/ciscoconfparse2.py line 3548 to for line in self.objs.as_text though i am not sure that this is the intended way.

btw. this tool saved me a ton of python-programming and therefore time while rearranging configuration-files. Thanks a lot!

CiscoConfParse Version

0.7.43

What Operating System are you using?

MacOS

What Python version(s) have this problem?

Python 3.9

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

from ciscoconfparse2 import CiscoConfParse

parse = CiscoConfParse('example.conf', syntax='ios')
parse.save_as("example_parsed.conf")

Python tracebacks

Traceback (most recent call last):

> File "/Users/tabea.rieth/work/python_ztp/parser.py", line 51, in <module>
    origConfig.save_as("example_parsed.conf")
    │          └ <function CiscoConfParse.save_as at 0x1041325e0><CiscoConfParse: 484 lines / syntax: ios / comment delimiters: ['!'] / auto_indent_width: 1 / factory: False / ignore_blank_l...

  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3553, in save_as
    raise ee
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3548, in save_as
    for line in self.as_text:
                └ <CiscoConfParse: 484 lines / syntax: ios / comment delimiters: ['!'] / auto_indent_width: 1 / factory: False / ignore_blank_l...

AttributeError: 'CiscoConfParse' object has no attribute 'as_text'
  File "/Users/tabea.rieth/work/python_ztp/parser.py", line 51, in <module>
    origConfig.save_as("example_parsed.conf")
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/loguru/_logger.py", line 1277, in catch_wrapper
    return function(*args, **kwargs)
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3553, in save_as
    raise ee
  File "/Users/tabea.rieth/Library/Python/3.9/lib/python/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3548, in save_as
    for line in self.as_text:
AttributeError: 'CiscoConfParse' object has no attribute 'as_text'

Relevant log output

No response

Code of Conduct

Wow, that was a big test escape. Thank you for finding it. It's fixed (and tested) in 0.7.45.