1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

mount fix for spaces in mountpoint name

This commit is contained in:
Kelly Brazil
2023-11-14 15:17:31 -08:00
parent 8aceda18b9
commit c78a4bb655
7 changed files with 26 additions and 9 deletions

View File

@ -1,9 +1,10 @@
jc changelog jc changelog
20231104 v1.23.7 20231114 v1.23.7
- Add `deb-packages` parser for Debian/Ubuntu Package Index files - 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 `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 `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 20231023 v1.23.6
- Fix XML parser for xmltodict library versions < 0.13.0 - Fix XML parser for xmltodict library versions < 0.13.0

View File

@ -98,4 +98,4 @@ Returns:
### Parser Information ### Parser Information
Compatibility: linux, darwin, freebsd, aix Compatibility: linux, darwin, freebsd, aix
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com) Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@ -77,7 +77,7 @@ import jc.utils
class info(): class info():
"""Provides parser metadata (version, author, etc.)""" """Provides parser metadata (version, author, etc.)"""
version = '1.8' version = '1.9'
description = '`mount` command parser' description = '`mount` command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -149,11 +149,13 @@ def _linux_parse(data):
match = pattern.match(entry) match = pattern.match(entry)
groups = match.groupdict() groups = match.groupdict()
output_line['filesystem'] = groups["filesystem"] if groups:
output_line['mount_point'] = groups["mount_point"] output_line['filesystem'] = groups["filesystem"]
output_line['type'] = groups["type"] output_line['mount_point'] = groups["mount_point"]
output_line['options'] = groups["options"].split(',') output_line['type'] = groups["type"]
output.append(output_line) output_line['options'] = groups["options"].split(',')
output.append(output_line)
return output return output
def _aix_parse(data): def _aix_parse(data):

View File

@ -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 .SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
and strings and strings

View File

@ -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"]}]

View File

@ -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)

View File

@ -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: 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() 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 # output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mount.json'), 'r', encoding='utf-8') as f: 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()) centos_7_7_mount_json = json.loads(f.read())
@ -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: 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()) 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): def test_mount_nodata(self):
""" """
@ -77,6 +83,12 @@ class MyTests(unittest.TestCase):
""" """
self.assertEqual(jc.parsers.mount.parse(self.aix_7_1_mount, quiet=True), self.aix_7_1_mount_json) 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__': if __name__ == '__main__':
unittest.main() unittest.main()