Remove if-"hell" from run function
This commit is contained in:
parent
e573118b38
commit
4177fe2a5f
@ -11,35 +11,30 @@ class SwapModule(AbstractModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
actions = ["Create/Resize temp. swap", "Create/Resize persistent swap", "Delete swap",
|
actions = {
|
||||||
"Make temp. swap persistent", "Get swap location", "Get swap size",
|
"Create/Resize temp. swap": self.create_resize_swap,
|
||||||
"Show swapiness", "Adjust temp. swapiness"]
|
"Create/Resize persistent swap": self.create_resize_peristent_swap,
|
||||||
|
"Delete swap": self.delete_swap,
|
||||||
|
"Make temp. swap persistent": self.make_swap_persistent,
|
||||||
|
"Get swap location": self.swap_location_check,
|
||||||
|
"Get swap size": self.get_swap_size,
|
||||||
|
"Show swapiness": self.show_swapiness,
|
||||||
|
"Adjust temp. swapiness": self.adjust_swapiness_temp
|
||||||
|
}
|
||||||
menu = [
|
menu = [
|
||||||
{
|
{
|
||||||
'type': 'list',
|
'type': 'list',
|
||||||
'message': 'Select action',
|
'message': 'Select action',
|
||||||
'name': 'action',
|
'name': 'action',
|
||||||
'choices': list(map(lambda x: {"name": x}, actions))
|
'choices': list(map(lambda x: {"name": x}, actions.keys()))
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
selected_action = prompt(menu)['action']
|
selected_action = prompt(menu)['action']
|
||||||
if selected_action == "Create/Resize temp. swap":
|
actions[selected_action]()
|
||||||
self.create_resize_swap()
|
|
||||||
elif selected_action == "Create/Resize persistent swap":
|
def create_resize_peristent_swap(self):
|
||||||
self.create_resize_swap()
|
self.create_resize_swap()
|
||||||
self.make_swap_persistent()
|
self.make_swap_persistent()
|
||||||
elif selected_action == "Make temp. swap persistent":
|
|
||||||
self.make_swap_persistent()
|
|
||||||
elif selected_action == "Show swapiness":
|
|
||||||
self.show_swapiness()
|
|
||||||
elif selected_action == "Delete":
|
|
||||||
self.delete_swap()
|
|
||||||
elif selected_action == "Get swap location":
|
|
||||||
self.swap_location_check()
|
|
||||||
elif selected_action == "Get swap size":
|
|
||||||
self.get_swap_size()
|
|
||||||
elif selected_action == "Adjust temp. swapiness":
|
|
||||||
self.adjust_swapiness_temp()
|
|
||||||
|
|
||||||
def swap_location_check(self) -> None:
|
def swap_location_check(self) -> None:
|
||||||
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
|
output_swaps = subprocess.check_output(['cat', '/proc/swaps']).decode("UTF-8")
|
||||||
|
Loading…
Reference in New Issue
Block a user