Pull out indice and rename variable

This commit is contained in:
Lucas Noki 2020-01-25 01:01:37 +01:00
parent 5d519f2380
commit d2c729f0ab

View File

@ -38,19 +38,18 @@ class SwapModule(AbstractModule):
def _swap_location_check(self):
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
final_list = list(output_swaps.split())
swap_location = output_swaps.split()[5]
try:
print("Swap is located here:", final_list[5])
self.swap_file = final_list[5]
print("Swap is located here:", swap_location)
self.swap_file = swap_location
except IndexError:
print("Swap file doesn´t exist!")
return "NoSwap"
def _get_swap_size(self):
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
final_list = list(swap_size.split())
swap_size = swap_size.split()[7]
try:
print("Swap is {}b big!".format(final_list[7]))
print("Swap is {}b big!".format(swap_size))
except IndexError:
print("Swap file doesn´t exist!")
@ -69,10 +68,10 @@ class SwapModule(AbstractModule):
else:
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
final_list = list(swap_size.split())
swap_size = swap_size.split()[7]
print("")
print("Swap already installed! You can resize it!")
print("Curr. swap size: {}b".format(final_list[7]))
print("Curr. swap size: {}b".format(swap_size))
resize = input("How big should your swap become(numbers in Gigabyte)? ")
resize_swapfile = "sudo swapoff /swapfile && " + \
"sudo fallocate -l {}G /swapfile && ".format(resize) + \