kellyjonbrazil / jc

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
MIT License
7.78k stars 196 forks source link

Parsing mounts with spaces in filenames fails - AttributeError: 'NoneType' object has no attribute 'groupdict' #574

Open wolkenarchitekt opened 2 months ago

wolkenarchitekt commented 2 months ago

Parsing mount output with spaces in filenames (such as mounts to samba shares) fails with AttributeError: 'NoneType' object has no attribute 'groupdict'.

Example code that fails:

import jc

data = """
//10.100.1.237/Bilder und Videos on /mnt/smb/thw/media type cifs (rw,nosuid,nodev,relatime,vers=2.1,cache=strict,username=iweinmann,uid=1000,noforceuid,gid=1000,noforcegid,addr=10.100.1.237,file_mode=0755,dir_mode=0755,iocharset=utf8,soft,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,bsize=1048576,retrans=1,echo_interval=60,actimeo=1,closetimeo=1,user=ingo)
"""
jc.parse(parser_mod_name="mount", data=data)

Will lead to error:

File ~/src/raspberrypi/xxxxx/.venv/lib/python3.9/site-packages/jc/parsers/mount.py:150, in _linux_parse(data)
    139 pattern = re.compile(
    140     r'''
    141     (?P<filesystem>\S+)\s+
   (...)
    146     \((?P<options>.*?)\)\s*''',
    147     re.VERBOSE)
    149 match = pattern.match(entry)
--> 150 groups = match.groupdict()
    152 if groups:
    153     output_line['filesystem'] = groups["filesystem"]

AttributeError: 'NoneType' object has no attribute 'groupdict
kellyjonbrazil commented 2 months ago

Thank you for reporting this - I should be able to get a fix in the next release.

kellyjonbrazil commented 2 months ago

I have a fix in the dev branch that you can test by copying the parser file below to your plugin directory:

https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/mount.py

Let me know if you run into any more issues. Thanks!