Fixed merge criterias:

delete unnecassary local variable, space between be and paranthesis, make return type consistent, fix multiline strings
This commit is contained in:
Lucas Noki 2020-01-21 23:26:57 +01:00
parent 4177fe2a5f
commit dd03126057
2 changed files with 17 additions and 19 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
__pycache__
.vscode
devenv
env

View File

@ -36,20 +36,18 @@ class SwapModule(AbstractModule):
self.create_resize_swap()
self.make_swap_persistent()
def swap_location_check(self) -> None:
def swap_location_check(self):
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
li = list(output_swaps.split())
final_list = li
final_list = list(output_swaps.split())
try:
print("Swap is located here:", final_list[5])
self.swap_file = final_list[5]
except IndexError:
print("Swap file doesn´t exist!\n")
def get_swap_size(self) -> None:
def get_swap_size(self):
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
li = list(swap_size.split())
final_list = li
final_list = list(swap_size.split())
try:
print("Swap is {}b big!".format(final_list[7]))
except IndexError:
@ -59,10 +57,10 @@ class SwapModule(AbstractModule):
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
if not output_swapon:
size = input("How big should the swap be (numbers in Gigabyte)? ")
create_swapfile = """sudo fallocate -l {}G /swapfile &&
sudo chmod 600 /swapfile &&
sudo mkswap /swapfile &&
sudo swapon /swapfile""".format(size)
create_swapfile = "sudo fallocate -l {}G /swapfile && ".format(size) + \
"sudo chmod 600 /swapfile && " + \
"sudo mkswap /swapfile && " + \
"sudo swapon /swapfile"
subprocess.call(create_swapfile, shell=True)
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
@ -70,16 +68,15 @@ class SwapModule(AbstractModule):
else:
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
li = list(swap_size.split())
final_list = li
final_list = list(swap_size.split())
print("")
print("Swap already installed! You can resize it!")
print("Curr. swap size: {}b".format(final_list[7]))
resize = input("How big should your swap become(numbers in Gigabyte)? ")
resize_swapfile = """sudo swapoff /swapfile &&
sudo fallocate -l {}G /swapfile &&
sudo mkswap /swapfile &&
sudo swapon /swapfile""".format(resize)
resize_swapfile = "sudo swapoff /swapfile && " + \
"sudo fallocate -l {}G /swapfile && ".format(resize) + \
"sudo mkswap /swapfile && " + \
"sudo swapon /swapfile"
subprocess.call(resize_swapfile, shell=True)
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
print(output_free.strip())
@ -120,8 +117,8 @@ class SwapModule(AbstractModule):
def delete_swap(self):
self.swap_location_check()
disable_swapfile = """sudo swapoff {0} &&
sudo rm {0}""".format(self.swap_file)
disable_swapfile = "sudo swapoff {} && ".format(self.swap_file) + \
"sudo rm {}".format(self.swap_file)
subprocess.call(disable_swapfile, shell=True)
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")