mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
refactored actions to use exceptions instead of return-values
This commit is contained in:
1 parent
a40d42eb60
commit
0d5636a900
12 files changed
+62
-72
No files matched your search
@@ -6,23 +6,18 @@ from gettext import gettext as _
|
||||
|
||||
import actions
|
||||
import cfg
|
||||
from errors import ActionError
|
||||
|
||||
|
||||
def get_modules_available():
|
||||
"""Return list of all modules"""
|
||||
output, error = actions.run('module-manager', ['list-available'])
|
||||
if error:
|
||||
raise Exception('Error getting modules: %s' % error)
|
||||
|
||||
output = actions.run('module-manager', ['list-available'])
|
||||
return output.split()
|
||||
|
||||
|
||||
def get_modules_enabled():
|
||||
"""Return list of all modules"""
|
||||
output, error = actions.run('module-manager', ['list-enabled'])
|
||||
if error:
|
||||
raise Exception('Error getting enabled modules - %s' % error)
|
||||
|
||||
output = actions.run('module-manager', ['list-enabled'])
|
||||
return output.split()
|
||||
|
||||
|
||||
@@ -88,13 +83,12 @@ def _apply_changes(request, old_status, new_status):
|
||||
|
||||
module = field.split('_enabled')[0]
|
||||
if enabled:
|
||||
output, error = actions.superuser_run(
|
||||
'module-manager', ['enable', cfg.python_root, module])
|
||||
del output # Unused
|
||||
|
||||
# TODO: need to get plinth to load the module we just
|
||||
# enabled
|
||||
if error:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'module-manager', ['enable', cfg.python_root, module])
|
||||
except ActionError:
|
||||
# TODO: need to get plinth to load the module we just
|
||||
# enabled
|
||||
messages.error(
|
||||
request, _('Error enabling module - {module}').format(
|
||||
module=module))
|
||||
@@ -103,13 +97,12 @@ def _apply_changes(request, old_status, new_status):
|
||||
request, _('Module enabled - {module}').format(
|
||||
module=module))
|
||||
else:
|
||||
output, error = actions.superuser_run(
|
||||
'module-manager', ['disable', cfg.python_root, module])
|
||||
del output # Unused
|
||||
|
||||
# TODO: need a smoother way for plinth to unload the
|
||||
# module
|
||||
if error:
|
||||
try:
|
||||
actions.superuser_run(
|
||||
'module-manager', ['disable', cfg.python_root, module])
|
||||
except ActionError:
|
||||
# TODO: need a smoother way for plinth to unload the
|
||||
# module
|
||||
messages.error(
|
||||
request, _('Error disabling module - {module}').format(
|
||||
module=module))
|
||||
|
||||
Reference in new issue
Block a user