Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle None value in nmcli tables #648

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

diegobfernandez
Copy link

Fix for #428

There is no need to have another function as nmcli device wifi list returns a table that sparse_table_parse is already able to parse. The problem is _normalize_value is not handling None and failing when trying to call value.strip().

Short-circuit _normalize_value if value is None.

I did not added any tests because I couldn't setup the project, I've simply copied nmcli.py into $HOME/.local/share/jc/jcparsers and tested this change with that.

@kellyjonbrazil
Copy link
Owner

Hi and thanks for the contribution! I'm not seeing this fix in _normalize_value address #428:

% echo '* :AA\:AA\:AA\:AA\:AA\:AA:go_away:Infra:40:270 Mbit/s:25:▂___:WPA2' | jc --nmcli -pqd
Traceback (most recent call last):
  File "/Users/kbrazil/.local/bin/jc", line 33, in <module>
    sys.exit(load_entry_point('jc', 'console_scripts', 'jc')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kbrazil/git/jc/jc/cli.py", line 970, in main
    JcCli().run()
  File "/Users/kbrazil/git/jc/jc/cli.py", line 952, in run
    self._run()
  File "/Users/kbrazil/git/jc/jc/cli.py", line 916, in _run
    self.standard_parse_and_print()
  File "/Users/kbrazil/git/jc/jc/cli.py", line 808, in standard_parse_and_print
    self.create_normal_output()
  File "/Users/kbrazil/git/jc/jc/cli.py", line 760, in create_normal_output
    self.data_out = self.parser_module.parse(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kbrazil/git/jc/jc/parsers/nmcli.py", line 396, in parse
    if data.splitlines()[1].startswith('\t'):
       ~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Is that the same input you were testing with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants