Fixed merge criterias:
delete unnecassary local variable, space between be and paranthesis, make return type consistent, fix multiline strings
This commit is contained in:
parent
4177fe2a5f
commit
dd03126057
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.vscode
|
.vscode
|
||||||
devenv
|
devenv
|
||||||
|
env
|
@ -36,20 +36,18 @@ class SwapModule(AbstractModule):
|
|||||||
self.create_resize_swap()
|
self.create_resize_swap()
|
||||||
self.make_swap_persistent()
|
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")
|
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
|
||||||
li = list(output_swaps.split())
|
final_list = list(output_swaps.split())
|
||||||
final_list = li
|
|
||||||
try:
|
try:
|
||||||
print("Swap is located here:", final_list[5])
|
print("Swap is located here:", final_list[5])
|
||||||
self.swap_file = final_list[5]
|
self.swap_file = final_list[5]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("Swap file doesn´t exist!\n")
|
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")
|
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
li = list(swap_size.split())
|
final_list = list(swap_size.split())
|
||||||
final_list = li
|
|
||||||
try:
|
try:
|
||||||
print("Swap is {}b big!".format(final_list[7]))
|
print("Swap is {}b big!".format(final_list[7]))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -59,10 +57,10 @@ class SwapModule(AbstractModule):
|
|||||||
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
if not output_swapon:
|
if not output_swapon:
|
||||||
size = input("How big should the swap be (numbers in Gigabyte)? ")
|
size = input("How big should the swap be (numbers in Gigabyte)? ")
|
||||||
create_swapfile = """sudo fallocate -l {}G /swapfile &&
|
create_swapfile = "sudo fallocate -l {}G /swapfile && ".format(size) + \
|
||||||
sudo chmod 600 /swapfile &&
|
"sudo chmod 600 /swapfile && " + \
|
||||||
sudo mkswap /swapfile &&
|
"sudo mkswap /swapfile && " + \
|
||||||
sudo swapon /swapfile""".format(size)
|
"sudo swapon /swapfile"
|
||||||
subprocess.call(create_swapfile, shell=True)
|
subprocess.call(create_swapfile, shell=True)
|
||||||
|
|
||||||
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
@ -70,16 +68,15 @@ class SwapModule(AbstractModule):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
swap_size = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
li = list(swap_size.split())
|
final_list = list(swap_size.split())
|
||||||
final_list = li
|
|
||||||
print("")
|
print("")
|
||||||
print("Swap already installed! You can resize it!")
|
print("Swap already installed! You can resize it!")
|
||||||
print("Curr. swap size: {}b".format(final_list[7]))
|
print("Curr. swap size: {}b".format(final_list[7]))
|
||||||
resize = input("How big should your swap become(numbers in Gigabyte)? ")
|
resize = input("How big should your swap become(numbers in Gigabyte)? ")
|
||||||
resize_swapfile = """sudo swapoff /swapfile &&
|
resize_swapfile = "sudo swapoff /swapfile && " + \
|
||||||
sudo fallocate -l {}G /swapfile &&
|
"sudo fallocate -l {}G /swapfile && ".format(resize) + \
|
||||||
sudo mkswap /swapfile &&
|
"sudo mkswap /swapfile && " + \
|
||||||
sudo swapon /swapfile""".format(resize)
|
"sudo swapon /swapfile"
|
||||||
subprocess.call(resize_swapfile, shell=True)
|
subprocess.call(resize_swapfile, shell=True)
|
||||||
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
print(output_free.strip())
|
print(output_free.strip())
|
||||||
@ -120,8 +117,8 @@ class SwapModule(AbstractModule):
|
|||||||
|
|
||||||
def delete_swap(self):
|
def delete_swap(self):
|
||||||
self.swap_location_check()
|
self.swap_location_check()
|
||||||
disable_swapfile = """sudo swapoff {0} &&
|
disable_swapfile = "sudo swapoff {} && ".format(self.swap_file) + \
|
||||||
sudo rm {0}""".format(self.swap_file)
|
"sudo rm {}".format(self.swap_file)
|
||||||
|
|
||||||
subprocess.call(disable_swapfile, shell=True)
|
subprocess.call(disable_swapfile, shell=True)
|
||||||
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
|
Loading…
Reference in New Issue
Block a user