mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add mount parser
This commit is contained in:
45
README.md
45
README.md
@ -66,6 +66,7 @@ jc [parser] [options]
|
||||
- `--ifconfig` enables the `ifconfig` parser
|
||||
- `--ls` enables the `ls` parser
|
||||
- `--lsblk` enables the `lsblk` parser
|
||||
- `--mount` enables the `mount` parser
|
||||
- `--netstat` enables the `netstat` parser
|
||||
- `--ps` enables the `ps` parser
|
||||
- `--route` enables the `route` parser
|
||||
@ -310,6 +311,50 @@ $ lsblk | jc --lsblk -p
|
||||
}
|
||||
]
|
||||
```
|
||||
### mount
|
||||
```
|
||||
$ mount | jc --mount -p
|
||||
[
|
||||
{
|
||||
"filesystem": "sysfs",
|
||||
"mount_point": "/sys",
|
||||
"type": "sysfs",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"noexec",
|
||||
"relatime"
|
||||
]
|
||||
},
|
||||
{
|
||||
"filesystem": "proc",
|
||||
"mount_point": "/proc",
|
||||
"type": "proc",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"noexec",
|
||||
"relatime"
|
||||
]
|
||||
},
|
||||
{
|
||||
"filesystem": "udev",
|
||||
"mount_point": "/dev",
|
||||
"type": "devtmpfs",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"relatime",
|
||||
"size=977500k",
|
||||
"nr_inodes=244375",
|
||||
"mode=755"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
```
|
||||
### netstat
|
||||
```
|
||||
$ netstat -p | jc --netstat -p
|
||||
|
@ -5,6 +5,7 @@ jc changelog
|
||||
- Add df parser
|
||||
- Add free parser
|
||||
- Add lsblk parser
|
||||
- Add mount parser
|
||||
|
||||
20191021 v0.6.4
|
||||
- Flatten netstat parser output
|
||||
|
7
jc/jc.py
7
jc/jc.py
@ -12,6 +12,7 @@ import jc.parsers.free
|
||||
import jc.parsers.ifconfig
|
||||
import jc.parsers.ls
|
||||
import jc.parsers.lsblk
|
||||
import jc.parsers.mount
|
||||
import jc.parsers.netstat
|
||||
import jc.parsers.ps
|
||||
import jc.parsers.route
|
||||
@ -42,6 +43,9 @@ def main():
|
||||
elif '--lsblk' in sys.argv:
|
||||
result = jc.parsers.lsblk.parse(data)
|
||||
|
||||
elif '--mount' in sys.argv:
|
||||
result = jc.parsers.mount.parse(data)
|
||||
|
||||
elif '--netstat' in sys.argv:
|
||||
result = jc.parsers.netstat.parse(data)
|
||||
|
||||
@ -52,7 +56,7 @@ def main():
|
||||
result = jc.parsers.route.parse(data)
|
||||
|
||||
else:
|
||||
print('jc: missing arguments', file=sys.stderr)
|
||||
print('jc: missing arguments\n', file=sys.stderr)
|
||||
print('Usage: jc [parser] [options]\n', file=sys.stderr)
|
||||
print('Parsers:', file=sys.stderr)
|
||||
print(' --df df parser', file=sys.stderr)
|
||||
@ -61,6 +65,7 @@ def main():
|
||||
print(' --ifconfig iconfig parser', file=sys.stderr)
|
||||
print(' --ls ls parser', file=sys.stderr)
|
||||
print(' --lsblk lsblk parser', file=sys.stderr)
|
||||
print(' --mount mount parser', file=sys.stderr)
|
||||
print(' --netstat netstat parser', file=sys.stderr)
|
||||
print(' --ps ps parser', file=sys.stderr)
|
||||
print(' --route route parser\n', file=sys.stderr)
|
||||
|
75
jc/parsers/mount.py
Normal file
75
jc/parsers/mount.py
Normal file
@ -0,0 +1,75 @@
|
||||
"""jc - JSON CLI output utility mount Parser
|
||||
|
||||
Usage:
|
||||
specify --mount as the first argument if the piped input is coming from mount
|
||||
|
||||
Example:
|
||||
|
||||
$ mount | jc --mount -p
|
||||
[
|
||||
{
|
||||
"filesystem": "sysfs",
|
||||
"mount_point": "/sys",
|
||||
"type": "sysfs",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"noexec",
|
||||
"relatime"
|
||||
]
|
||||
},
|
||||
{
|
||||
"filesystem": "proc",
|
||||
"mount_point": "/proc",
|
||||
"type": "proc",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"nodev",
|
||||
"noexec",
|
||||
"relatime"
|
||||
]
|
||||
},
|
||||
{
|
||||
"filesystem": "udev",
|
||||
"mount_point": "/dev",
|
||||
"type": "devtmpfs",
|
||||
"access": [
|
||||
"rw",
|
||||
"nosuid",
|
||||
"relatime",
|
||||
"size=977500k",
|
||||
"nr_inodes=244375",
|
||||
"mode=755"
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
|
||||
|
||||
def parse(data):
|
||||
output = []
|
||||
|
||||
linedata = data.splitlines()
|
||||
|
||||
# Clear any blank lines
|
||||
cleandata = list(filter(None, linedata))
|
||||
|
||||
if cleandata:
|
||||
for entry in cleandata:
|
||||
output_line = {}
|
||||
parsed_line = entry.split()
|
||||
|
||||
output_line['filesystem'] = parsed_line[0]
|
||||
output_line['mount_point'] = parsed_line[2]
|
||||
output_line['type'] = parsed_line[4]
|
||||
|
||||
access = parsed_line[5].lstrip('(').rstrip(')').split(',')
|
||||
|
||||
output_line['access'] = access
|
||||
|
||||
output.append(output_line)
|
||||
|
||||
return output
|
Reference in New Issue
Block a user