Skip to content

Commit

Permalink
mount fix for spaces in mountpoint name
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Nov 14, 2023
1 parent 8aceda1 commit c78a4bb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
jc changelog

20231104 v1.23.7
20231114 v1.23.7
- Add `deb-packages` parser for Debian/Ubuntu Package Index files
- Fix `iptables` parser for cases where the `target` field is blank in a rule
- Fix `vmstat` parsers for some cases where wide output is used
- Fix `mount` parser for cases with spaces in the mount point name

20231023 v1.23.6
- Fix XML parser for xmltodict library versions < 0.13.0
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, freebsd, aix

Version 1.8 by Kelly Brazil ([email protected])
Version 1.9 by Kelly Brazil ([email protected])
14 changes: 8 additions & 6 deletions jc/parsers/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.8'
version = '1.9'
description = '`mount` command parser'
author = 'Kelly Brazil'
author_email = '[email protected]'
Expand Down Expand Up @@ -149,11 +149,13 @@ def _linux_parse(data):
match = pattern.match(entry)
groups = match.groupdict()

output_line['filesystem'] = groups["filesystem"]
output_line['mount_point'] = groups["mount_point"]
output_line['type'] = groups["type"]
output_line['options'] = groups["options"].split(',')
output.append(output_line)
if groups:
output_line['filesystem'] = groups["filesystem"]
output_line['mount_point'] = groups["mount_point"]
output_line['type'] = groups["type"]
output_line['options'] = groups["options"].split(',')
output.append(output_line)

return output

def _aix_parse(data):
Expand Down
2 changes: 1 addition & 1 deletion man/jc.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH jc 1 2023-11-04 1.23.7 "JSON Convert"
.TH jc 1 2023-11-14 1.23.7 "JSON Convert"
.SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/generic/mount-spaces-in-mountpoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"filesystem":"/dev/sda1","mount_point":"/media/ingo/Ubuntu 22.04.3 LTS amd64","type":"iso9660","options":["ro","nosuid","nodev","relatime","nojoliet","check=s","map=n","blocksize=2048","uid=1000","gid=1000","dmode=500","fmode=400","iocharset=utf8","uhelper=udisks2"]}]
1 change: 1 addition & 0 deletions tests/fixtures/generic/mount-spaces-in-mountpoint.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dev/sda1 on /media/ingo/Ubuntu 22.04.3 LTS amd64 type iso9660 (ro,nosuid,nodev,relatime,nojoliet,check=s,map=n,blocksize=2048,uid=1000,gid=1000,dmode=500,fmode=400,iocharset=utf8,uhelper=udisks2)
12 changes: 12 additions & 0 deletions tests/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/aix-7.1/mount.out'), 'r', encoding='utf-8') as f:
aix_7_1_mount = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/mount-spaces-in-mountpoint.out'), 'r', encoding='utf-8') as f:
generic_mount_spaces_in_mountpoint = f.read()

# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mount.json'), 'r', encoding='utf-8') as f:
centos_7_7_mount_json = json.loads(f.read())
Expand All @@ -40,6 +43,9 @@ class MyTests(unittest.TestCase):
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/aix-7.1/mount.json'), 'r', encoding='utf-8') as f:
aix_7_1_mount_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/mount-spaces-in-mountpoint.json'), 'r', encoding='utf-8') as f:
generic_mount_spaces_in_mountpoint_json = json.loads(f.read())


def test_mount_nodata(self):
"""
Expand Down Expand Up @@ -77,6 +83,12 @@ def test_mount_aix_7_1(self):
"""
self.assertEqual(jc.parsers.mount.parse(self.aix_7_1_mount, quiet=True), self.aix_7_1_mount_json)

def test_mount_spaces_in_mountpoint(self):
"""
Test 'mount' with spaces in the mountpoint
"""
self.assertEqual(jc.parsers.mount.parse(self.generic_mount_spaces_in_mountpoint, quiet=True), self.generic_mount_spaces_in_mountpoint_json)


if __name__ == '__main__':
unittest.main()

0 comments on commit c78a4bb

Please sign in to comment.