mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
Don't convert 'size' to int, except for legacy -d support. Change partition table detection logic to fix -F output
This commit is contained in:
@@ -50,7 +50,7 @@ Schema:
|
||||
"boot": boolean,
|
||||
"start": integer,
|
||||
"end": integer,
|
||||
"size": integer,
|
||||
"size": string, # Note: will be integer when using deprecated -d sfdisk option
|
||||
"cyls": integer,
|
||||
"mib": integer,
|
||||
"blocks": integer,
|
||||
@@ -224,7 +224,7 @@ def _process(proc_data):
|
||||
|
||||
List of Dictionaries. Structured to conform to the schema.
|
||||
"""
|
||||
int_list = ['cylinders', 'heads', 'sectors_per_track', 'start', 'end', 'size', 'cyls', 'mib',
|
||||
int_list = ['cylinders', 'heads', 'sectors_per_track', 'start', 'end', 'cyls', 'mib',
|
||||
'blocks', 'sectors', 'bytes', 'logical_sector_size', 'physical_sector_size',
|
||||
'min_io_size', 'optimal_io_size', 'free_bytes', 'free_sectors']
|
||||
bool_list = ['boot']
|
||||
@@ -237,6 +237,12 @@ def _process(proc_data):
|
||||
if 'partitions' in entry:
|
||||
for p in entry['partitions']:
|
||||
for key in p:
|
||||
# legacy conversion for -d option
|
||||
if key == 'size':
|
||||
if p[key].isnumeric():
|
||||
p[key] = jc.utils.convert_to_int(p[key])
|
||||
|
||||
# normal conversions
|
||||
if key in int_list:
|
||||
p[key] = jc.utils.convert_to_int(p[key].replace('-', ''))
|
||||
if key in bool_list:
|
||||
@@ -373,7 +379,7 @@ def parse(data, raw=False, quiet=False):
|
||||
continue
|
||||
|
||||
# partition lines
|
||||
if 'Device' in line and 'Boot' in line and 'Start' in line and 'End' in line:
|
||||
if 'Start' in line and 'End' in line and ('Sectors' in line or 'Device' in line):
|
||||
section = 'partitions'
|
||||
partitions.append(line.lower().replace('#', ' '))
|
||||
continue
|
||||
|
2
tests/fixtures/centos-8/sfdisk-l.json
vendored
2
tests/fixtures/centos-8/sfdisk-l.json
vendored
@@ -1 +1 @@
|
||||
[{"disk":"/dev/sda","disk_size":"20 GiB","bytes":21474836480,"sectors":41943040,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512,"disk_label_type":"dos","disk_identifier":"0x94988ac4","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":2099199,"sectors":2097152,"size":1,"id":"83","type":"Linux"},{"device":"/dev/sda2","boot":false,"start":2099200,"end":41943039,"sectors":39843840,"size":19,"id":"8e","type":"Linux LVM"}]},{"disk":"/dev/mapper/cl-root","disk_size":"17 GiB","bytes":18249416704,"sectors":35643392,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512},{"disk":"/dev/mapper/cl-swap","disk_size":"2 GiB","bytes":2147483648,"sectors":4194304,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512}]
|
||||
[{"disk":"/dev/sda","disk_size":"20 GiB","bytes":21474836480,"sectors":41943040,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512,"disk_label_type":"dos","disk_identifier":"0x94988ac4","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":2099199,"sectors":2097152,"size":"1G","id":"83","type":"Linux"},{"device":"/dev/sda2","boot":false,"start":2099200,"end":41943039,"sectors":39843840,"size":"19G","id":"8e","type":"Linux LVM"}]},{"disk":"/dev/mapper/cl-root","disk_size":"17 GiB","bytes":18249416704,"sectors":35643392,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512},{"disk":"/dev/mapper/cl-swap","disk_size":"2 GiB","bytes":2147483648,"sectors":4194304,"units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512}]
|
||||
|
2
tests/fixtures/debian10/sfdisk-l.json
vendored
2
tests/fixtures/debian10/sfdisk-l.json
vendored
@@ -1 +1 @@
|
||||
[{"disk":"/dev/sda","disk_size":"20 GiB","bytes":21474836480,"sectors":41943040,"disk_model":"VMware Virtual S","units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512,"disk_label_type":"dos","disk_identifier":"0x3719ef0f","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":39942143,"sectors":39940096,"size":19,"id":"83","type":"Linux"},{"device":"/dev/sda2","boot":false,"start":39944190,"end":41940991,"sectors":1996802,"size":975,"id":"5","type":"Extended"},{"device":"/dev/sda5","boot":false,"start":39944192,"end":41940991,"sectors":1996800,"size":975,"id":"82","type":"Linux swap / Solaris"}]}]
|
||||
[{"disk":"/dev/sda","disk_size":"20 GiB","bytes":21474836480,"sectors":41943040,"disk_model":"VMware Virtual S","units":"sectors of 1 * 512 = 512 bytes","logical_sector_size":512,"physical_sector_size":512,"min_io_size":512,"optimal_io_size":512,"disk_label_type":"dos","disk_identifier":"0x3719ef0f","partitions":[{"device":"/dev/sda1","boot":true,"start":2048,"end":39942143,"sectors":39940096,"size":"19G","id":"83","type":"Linux"},{"device":"/dev/sda2","boot":false,"start":39944190,"end":41940991,"sectors":1996802,"size":"975M","id":"5","type":"Extended"},{"device":"/dev/sda5","boot":false,"start":39944192,"end":41940991,"sectors":1996800,"size":"975M","id":"82","type":"Linux swap / Solaris"}]}]
|
||||
|
Reference in New Issue
Block a user