* Changed default value of info in largest_free_space() * Fixing bad assumption that a disk always contain a minimum of two partitions.
This commit is contained in:
parent
66e23af422
commit
c264fd466a
|
|
@ -192,7 +192,7 @@ class BlockDevice:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def largest_free_space(self):
|
def largest_free_space(self):
|
||||||
info = None
|
info = []
|
||||||
for space_info in self.free_space:
|
for space_info in self.free_space:
|
||||||
if not info:
|
if not info:
|
||||||
info = space_info
|
info = space_info
|
||||||
|
|
@ -202,6 +202,22 @@ class BlockDevice:
|
||||||
info = space_info
|
info = space_info
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first_free_sector(self):
|
||||||
|
if info := self.largest_free_space:
|
||||||
|
start = info[0]
|
||||||
|
else:
|
||||||
|
start = '512MB'
|
||||||
|
return start
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first_end_sector(self):
|
||||||
|
if info := self.largest_free_space:
|
||||||
|
end = info[1]
|
||||||
|
else:
|
||||||
|
end = f"{self.size}GB"
|
||||||
|
return end
|
||||||
|
|
||||||
def partprobe(self):
|
def partprobe(self):
|
||||||
SysCommand(['partprobe', self.path])
|
SysCommand(['partprobe', self.path])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -643,10 +643,10 @@ def manage_new_and_existing_partitions(block_device :BlockDevice) -> dict:
|
||||||
|
|
||||||
fstype = input("Enter a desired filesystem type for the partition: ").strip()
|
fstype = input("Enter a desired filesystem type for the partition: ").strip()
|
||||||
|
|
||||||
start = input(f"Enter the start sector (percentage or block number, default: {block_device.largest_free_space[0]}): ").strip()
|
start = input(f"Enter the start sector (percentage or block number, default: {block_device.first_free_sector}): ").strip()
|
||||||
if not start.strip():
|
if not start.strip():
|
||||||
start = block_device.largest_free_space[0]
|
start = block_device.first_free_sector
|
||||||
end_suggested = block_device.largest_free_space[1]
|
end_suggested = block_device.first_end_sector
|
||||||
else:
|
else:
|
||||||
end_suggested = '100%'
|
end_suggested = '100%'
|
||||||
end = input(f"Enter the end sector of the partition (percentage or block number, ex: {end_suggested}): ").strip()
|
end = input(f"Enter the end sector of the partition (percentage or block number, ex: {end_suggested}): ").strip()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue