Simplify if statements

This commit is contained in:
Lucas Noki 2020-02-01 03:06:37 +01:00
parent faac5d22be
commit e25c3f16d6

View File

@ -83,13 +83,12 @@ class SwapModule(AbstractModule):
def _make_swap_persistent(self):
swap_location = self._get_swap_location()
persistence_entry = self._check_fstab_entry()
if swap_location is None:
print("Swap file doesn't exist!")
return
backup_fstab = "sudo cp /etc/fstab /etc/fstab.bak"
enable_persistence = "echo '{} none swap sw 0 0' | sudo tee -a /etc/fstab".format(swap_location)
if persistence_entry is True:
if self._check_fstab_entry():
print("Swap is already persistent!")
else:
subprocess.call(backup_fstab, shell=True)
@ -126,7 +125,7 @@ class SwapModule(AbstractModule):
return
disable_swapfile = "sudo swapoff {} && ".format(swap_location) + \
"sudo rm {}".format(swap_location)
if self._check_fstab_entry() is True:
if self._check_fstab_entry():
with open("/etc/fstab", "r") as fstab_out:
content = fstab_out.readlines()
with open("/etc/fstab", "w") as fstab_in: