Browse Source

v7.3.2.0: Refactor action_service method in roxy module

Refactoring of the function 'action_service' has been completed in the roxywi module. The function for different actions ('start', 'stop', and 'restart') has been replaced by a dictionary for more clean and efficient code. This change also enhances code readability and maintainability.
pull/390/head v7.3.2.0
Aidaho 4 months ago
parent
commit
45b964d341
  1. 13
      app/modules/roxywi/roxy.py

13
app/modules/roxywi/roxy.py

@ -93,11 +93,14 @@ def update_user_status() -> None:
def action_service(action: str, service: str) -> str:
is_in_docker = is_docker()
cmd = f"sudo systemctl disable {service} --now"
if action in ("start", "restart"):
cmd = f"sudo systemctl {action} {service} --now"
if not roxy_sql.select_user_status():
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
actions = {
'start': 'enable --now',
'stop': 'disable --now',
'restart': 'restart',
}
cmd = f"sudo systemctl {actions[action]} {service}"
if not roxy_sql.select_user_status():
return 'warning: The service is disabled because you are not subscribed. Read <a href="https://roxy-wi.org/pricing" ' \
'title="Roxy-WI pricing" target="_blank">here</a> about subscriptions'
if is_in_docker:
cmd = f"sudo supervisorctl {action} {service}"

Loading…
Cancel
Save