Initial swap file
This commit is contained in:
parent
ff076eb527
commit
23771e22be
61
modules/swap/module.py
Normal file
61
modules/swap/module.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import subprocess
|
||||||
|
from PyInquirer import prompt
|
||||||
|
from AbstractModule import AbstractModule
|
||||||
|
|
||||||
|
|
||||||
|
class VimModule(AbstractModule):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
|
# Check default swap location
|
||||||
|
def convert_string(string):
|
||||||
|
li = list(string.split())
|
||||||
|
return li
|
||||||
|
|
||||||
|
|
||||||
|
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
|
||||||
|
final_list = convert_string(output_swaps)
|
||||||
|
print(final_list[5])
|
||||||
|
# End of location check
|
||||||
|
|
||||||
|
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
|
|
||||||
|
option = input("Enter option. 1.Create/Resize 2.Delete: ")
|
||||||
|
|
||||||
|
if option == "1":
|
||||||
|
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)
|
||||||
|
subprocess.call(create_swapfile, shell=True)
|
||||||
|
|
||||||
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
|
print(output_free.strip())
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("")
|
||||||
|
print("Swap already installed! You can resize it!")
|
||||||
|
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)
|
||||||
|
subprocess.call(resize_swapfile, shell=True)
|
||||||
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
|
print(output_free.strip())
|
||||||
|
elif option == "2":
|
||||||
|
disable_swapfile = """sudo swapoff /swapfile &&
|
||||||
|
sudo rm /swapfile"""
|
||||||
|
|
||||||
|
subprocess.call(disable_swapfile, shell=True)
|
||||||
|
output_swapon = subprocess.check_output(['swapon', '--show']).decode("UTF-8")
|
||||||
|
output_free = subprocess.check_output(['free', '-h']).decode("UTF-8")
|
||||||
|
if not output_swapon:
|
||||||
|
print("Swap deleted!")
|
||||||
|
print(output_free.strip())
|
||||||
|
else:
|
||||||
|
print("Wrong input!")
|
Loading…
Reference in New Issue
Block a user