mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add mountpoints array field and convert sizes to bytes
This commit is contained in:
@ -21,9 +21,13 @@ Schema:
|
|||||||
"maj_min": string,
|
"maj_min": string,
|
||||||
"rm": boolean,
|
"rm": boolean,
|
||||||
"size": string,
|
"size": string,
|
||||||
|
"size_bytes": integer
|
||||||
"ro": boolean,
|
"ro": boolean,
|
||||||
"type": string,
|
"type": string,
|
||||||
"mountpoint": string,
|
"mountpoint": string,
|
||||||
|
"mountpoints": [
|
||||||
|
string # null if no mountpoints
|
||||||
|
],
|
||||||
"kname": string,
|
"kname": string,
|
||||||
"fstype": string,
|
"fstype": string,
|
||||||
"label": string,
|
"label": string,
|
||||||
@ -47,9 +51,12 @@ Schema:
|
|||||||
"rq_size": integer,
|
"rq_size": integer,
|
||||||
"disc_aln": integer,
|
"disc_aln": integer,
|
||||||
"disc_gran": string,
|
"disc_gran": string,
|
||||||
|
"disc_gran_bytes": integer,
|
||||||
"disc_max": string,
|
"disc_max": string,
|
||||||
|
"disc_max_bytes": integer,
|
||||||
"disc_zero": boolean,
|
"disc_zero": boolean,
|
||||||
"wsame": string,
|
"wsame": string,
|
||||||
|
"wsame_bytes": integer,
|
||||||
"wwn": string,
|
"wwn": string,
|
||||||
"rand": boolean,
|
"rand": boolean,
|
||||||
"pkname": string,
|
"pkname": string,
|
||||||
@ -69,6 +76,7 @@ Examples:
|
|||||||
"maj_min": "8:0",
|
"maj_min": "8:0",
|
||||||
"rm": false,
|
"rm": false,
|
||||||
"size": "20G",
|
"size": "20G",
|
||||||
|
"size_bytes": 20000000000,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
"type": "disk",
|
"type": "disk",
|
||||||
"mountpoint": null
|
"mountpoint": null
|
||||||
@ -78,6 +86,7 @@ Examples:
|
|||||||
"maj_min": "8:1",
|
"maj_min": "8:1",
|
||||||
"rm": false,
|
"rm": false,
|
||||||
"size": "1G",
|
"size": "1G",
|
||||||
|
"size_bytes": 1000000000
|
||||||
"ro": false,
|
"ro": false,
|
||||||
"type": "part",
|
"type": "part",
|
||||||
"mountpoint": "/boot"
|
"mountpoint": "/boot"
|
||||||
@ -95,6 +104,7 @@ Examples:
|
|||||||
"maj_min": "8:0",
|
"maj_min": "8:0",
|
||||||
"rm": false,
|
"rm": false,
|
||||||
"size": "20G",
|
"size": "20G",
|
||||||
|
"size_bytes": 20000000000,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
"type": "disk",
|
"type": "disk",
|
||||||
"mountpoint": null,
|
"mountpoint": null,
|
||||||
@ -121,9 +131,12 @@ Examples:
|
|||||||
"rq_size": 128,
|
"rq_size": 128,
|
||||||
"disc_aln": 0,
|
"disc_aln": 0,
|
||||||
"disc_gran": "0B",
|
"disc_gran": "0B",
|
||||||
|
"disc_gran_bytes": 0,
|
||||||
"disc_max": "0B",
|
"disc_max": "0B",
|
||||||
|
"disc_max_bytes": 0,
|
||||||
"disc_zero": false,
|
"disc_zero": false,
|
||||||
"wsame": "32M",
|
"wsame": "32M",
|
||||||
|
"wsame_bytes": 32000000,
|
||||||
"wwn": null,
|
"wwn": null,
|
||||||
"rand": true,
|
"rand": true,
|
||||||
"pkname": null,
|
"pkname": null,
|
||||||
@ -137,6 +150,7 @@ Examples:
|
|||||||
"maj_min": "8:1",
|
"maj_min": "8:1",
|
||||||
"rm": false,
|
"rm": false,
|
||||||
"size": "1G",
|
"size": "1G",
|
||||||
|
"size_bytes": 1000000000
|
||||||
"ro": false,
|
"ro": false,
|
||||||
"type": "part",
|
"type": "part",
|
||||||
"mountpoint": "/boot",
|
"mountpoint": "/boot",
|
||||||
@ -163,9 +177,12 @@ Examples:
|
|||||||
"rq_size": 128,
|
"rq_size": 128,
|
||||||
"disc_aln": 0,
|
"disc_aln": 0,
|
||||||
"disc_gran": "0B",
|
"disc_gran": "0B",
|
||||||
|
"disc_gran_bytes": 0,
|
||||||
"disc_max": "0B",
|
"disc_max": "0B",
|
||||||
|
"disc_max_bytes": 0,
|
||||||
"disc_zero": false,
|
"disc_zero": false,
|
||||||
"wsame": "32M",
|
"wsame": "32M",
|
||||||
|
"wsame_bytes": 32000000,
|
||||||
"wwn": null,
|
"wwn": null,
|
||||||
"rand": true,
|
"rand": true,
|
||||||
"pkname": "sda",
|
"pkname": "sda",
|
||||||
@ -187,6 +204,7 @@ Examples:
|
|||||||
"maj_min": "8:0",
|
"maj_min": "8:0",
|
||||||
"rm": "0",
|
"rm": "0",
|
||||||
"size": "20G",
|
"size": "20G",
|
||||||
|
"size_bytes": 20000000000,
|
||||||
"ro": "0",
|
"ro": "0",
|
||||||
"type": "disk",
|
"type": "disk",
|
||||||
"mountpoint": null,
|
"mountpoint": null,
|
||||||
@ -213,9 +231,12 @@ Examples:
|
|||||||
"rq_size": "128",
|
"rq_size": "128",
|
||||||
"disc_aln": "0",
|
"disc_aln": "0",
|
||||||
"disc_gran": "0B",
|
"disc_gran": "0B",
|
||||||
|
"disc_gran_bytes": 0,
|
||||||
"disc_max": "0B",
|
"disc_max": "0B",
|
||||||
|
"disc_max_bytes": 0,
|
||||||
"disc_zero": "0",
|
"disc_zero": "0",
|
||||||
"wsame": "32M",
|
"wsame": "32M",
|
||||||
|
"wsame_bytes": 32000000,
|
||||||
"wwn": null,
|
"wwn": null,
|
||||||
"rand": "1",
|
"rand": "1",
|
||||||
"pkname": null,
|
"pkname": null,
|
||||||
@ -229,6 +250,7 @@ Examples:
|
|||||||
"maj_min": "8:1",
|
"maj_min": "8:1",
|
||||||
"rm": "0",
|
"rm": "0",
|
||||||
"size": "1G",
|
"size": "1G",
|
||||||
|
"size_bytes": 1000000000
|
||||||
"ro": "0",
|
"ro": "0",
|
||||||
"type": "part",
|
"type": "part",
|
||||||
"mountpoint": "/boot",
|
"mountpoint": "/boot",
|
||||||
@ -255,9 +277,12 @@ Examples:
|
|||||||
"rq_size": "128",
|
"rq_size": "128",
|
||||||
"disc_aln": "0",
|
"disc_aln": "0",
|
||||||
"disc_gran": "0B",
|
"disc_gran": "0B",
|
||||||
|
"disc_gran_bytes": 0,
|
||||||
"disc_max": "0B",
|
"disc_max": "0B",
|
||||||
|
"disc_max_bytes": 0,
|
||||||
"disc_zero": "0",
|
"disc_zero": "0",
|
||||||
"wsame": "32M",
|
"wsame": "32M",
|
||||||
|
"wsame_bytes": 32000000,
|
||||||
"wwn": null,
|
"wwn": null,
|
||||||
"rand": "1",
|
"rand": "1",
|
||||||
"pkname": "sda",
|
"pkname": "sda",
|
||||||
@ -275,7 +300,7 @@ import jc.parsers.universal
|
|||||||
|
|
||||||
class info():
|
class info():
|
||||||
"""Provides parser metadata (version, author, etc.)"""
|
"""Provides parser metadata (version, author, etc.)"""
|
||||||
version = '1.9'
|
version = '1.10'
|
||||||
description = '`lsblk` command parser'
|
description = '`lsblk` command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -304,14 +329,19 @@ def _process(proc_data):
|
|||||||
int_list = {'ra', 'alignment', 'min_io', 'opt_io', 'phy_sec', 'log_sec',
|
int_list = {'ra', 'alignment', 'min_io', 'opt_io', 'phy_sec', 'log_sec',
|
||||||
'rq_size', 'disc_aln'}
|
'rq_size', 'disc_aln'}
|
||||||
|
|
||||||
|
size_list = {'size', 'disc_gran', 'disc_max', 'wsame'}
|
||||||
|
|
||||||
for entry in proc_data:
|
for entry in proc_data:
|
||||||
for key in entry:
|
for key in entry.copy():
|
||||||
if key in bool_list:
|
if key in bool_list:
|
||||||
entry[key] = jc.utils.convert_to_bool(entry[key])
|
entry[key] = jc.utils.convert_to_bool(entry[key])
|
||||||
|
|
||||||
if key in int_list:
|
if key in int_list:
|
||||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||||
|
|
||||||
|
if key in size_list:
|
||||||
|
entry[key + '_bytes'] = jc.utils.convert_size_to_int(entry[key])
|
||||||
|
|
||||||
return proc_data
|
return proc_data
|
||||||
|
|
||||||
|
|
||||||
@ -335,6 +365,7 @@ def parse(data, raw=False, quiet=False):
|
|||||||
# Clear any blank lines
|
# Clear any blank lines
|
||||||
cleandata = list(filter(None, data.splitlines()))
|
cleandata = list(filter(None, data.splitlines()))
|
||||||
raw_output = []
|
raw_output = []
|
||||||
|
new_list = []
|
||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
|
|
||||||
@ -346,11 +377,20 @@ def parse(data, raw=False, quiet=False):
|
|||||||
|
|
||||||
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
|
raw_output = jc.parsers.universal.sparse_table_parse(cleandata)
|
||||||
|
|
||||||
# clean up non-ascii characters, if any
|
# find multiple mount points and add to a single entry
|
||||||
for entry in raw_output:
|
for entry in raw_output:
|
||||||
entry['name'] = entry['name'].encode('ascii', errors='ignore').decode()
|
if entry['name']:
|
||||||
|
if 'mountpoints' in entry and entry['mountpoints']:
|
||||||
|
entry['mountpoints'] = [entry['mountpoints']]
|
||||||
|
new_list.append(entry)
|
||||||
|
elif 'mountpoints' in entry and entry['mountpoints']:
|
||||||
|
new_list[-1]['mountpoints'].append(entry['mountpoints'])
|
||||||
|
|
||||||
if raw:
|
# clean up tree characters, if any
|
||||||
return raw_output
|
for entry in new_list:
|
||||||
else:
|
tree_chars = ['`-', '|-', '├─', '└─']
|
||||||
return _process(raw_output)
|
for chars in tree_chars:
|
||||||
|
if entry['name'][0:2] == chars:
|
||||||
|
entry['name'] = entry['name'][2:]
|
||||||
|
|
||||||
|
return new_list if raw else _process(new_list)
|
||||||
|
Reference in New Issue
Block a user