put index access in try block
This commit is contained in:
parent
c3e9bcc147
commit
de6b0917e8
@ -38,8 +38,8 @@ class SwapModule(AbstractModule):
|
|||||||
|
|
||||||
def _swap_location_check(self):
|
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")
|
||||||
swap_location = output_swaps.split()[5]
|
|
||||||
try:
|
try:
|
||||||
|
swap_location = output_swaps.split()[5]
|
||||||
print("Swap is located here:", swap_location)
|
print("Swap is located here:", swap_location)
|
||||||
self.swap_file = swap_location
|
self.swap_file = swap_location
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -47,8 +47,8 @@ class SwapModule(AbstractModule):
|
|||||||
|
|
||||||
def _get_swap_size(self):
|
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")
|
||||||
swap_size = swap_size.split()[7]
|
|
||||||
try:
|
try:
|
||||||
|
swap_size = swap_size.split()[7]
|
||||||
print("Swap is {}b big!".format(swap_size))
|
print("Swap is {}b big!".format(swap_size))
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("Swap file doesn´t exist!")
|
print("Swap file doesn´t exist!")
|
||||||
|
Loading…
Reference in New Issue
Block a user