mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Service object to handle services on a system-level
The Service object now offers handling services on a system level, and gathering information whether it's enabled or running. New methods: enable, disable, is_enabled, is_running; For this it needs the correct (system-level) service name. All of the methods can be overridden/customized. This changes all modules to the new Service object and deletes action scripts that are not required anymore.
This commit is contained in:
1 parent
9fe49f881f
commit
a9528c56d9
30 files changed
+243
-629
No files matched your search
@@ -22,7 +22,6 @@ Plinth module to configure system date and time
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import subprocess
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth import cfg
|
||||
from plinth import service as service_module
|
||||
|
||||
@@ -33,6 +32,8 @@ is_essential = True
|
||||
|
||||
depends = ['system']
|
||||
|
||||
managed_services = ['ntp']
|
||||
|
||||
title = _('Date & Time')
|
||||
|
||||
description = [
|
||||
@@ -50,7 +51,7 @@ def init():
|
||||
|
||||
global service
|
||||
service = service_module.Service(
|
||||
'ntp', title, is_external=False, enabled=is_enabled())
|
||||
managed_services[0], title, is_external=False)
|
||||
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
@@ -61,27 +62,25 @@ def setup(helper, old_version=None):
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings from server."""
|
||||
return {'enabled': is_enabled(),
|
||||
'is_running': is_running(),
|
||||
return {'enabled': service.is_enabled(),
|
||||
'is_running': service.is_running(),
|
||||
'time_zone': get_current_time_zone()}
|
||||
|
||||
|
||||
def enable(should_enable):
|
||||
"""Enable/disable the module."""
|
||||
if should_enable:
|
||||
service.enable()
|
||||
else:
|
||||
service.disable()
|
||||
|
||||
|
||||
def get_current_time_zone():
|
||||
"""Get current time zone."""
|
||||
time_zone = open('/etc/timezone').read().rstrip()
|
||||
return time_zone or 'none'
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return action_utils.service_is_enabled('ntp')
|
||||
|
||||
|
||||
def is_running():
|
||||
"""Return whether the service is running."""
|
||||
return action_utils.service_is_running('ntp')
|
||||
|
||||
|
||||
def diagnose():
|
||||
"""Run diagnostics and return the results."""
|
||||
results = []
|
||||
|
||||
@@ -40,10 +40,11 @@ class ConfigurationView(views.ConfigurationView):
|
||||
modified = False
|
||||
|
||||
if old_status['enabled'] != new_status['enabled']:
|
||||
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
||||
if new_status['enabled']:
|
||||
datetime.service.enable()
|
||||
else:
|
||||
datetime.service.disable()
|
||||
modified = True
|
||||
actions.superuser_run('datetime', [sub_command])
|
||||
datetime.service.notify_enabled(None, new_status['enabled'])
|
||||
messages.success(self.request, _('Configuration updated'))
|
||||
|
||||
if old_status['time_zone'] != new_status['time_zone'] and \
|
||||
|
||||
Reference in new issue
Block a user