mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
service: Fix warning to use collections.abc
Fix the following warning: "DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working" Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
41d9419ddd
commit
c79b9b276f
@ -30,7 +30,7 @@ from plinth.utils import format_lazy
|
|||||||
services = {}
|
services = {}
|
||||||
|
|
||||||
|
|
||||||
class Service(object):
|
class Service():
|
||||||
"""
|
"""
|
||||||
Representation of an application service provided by the machine
|
Representation of an application service provided by the machine
|
||||||
containing information such as current status and ports required
|
containing information such as current status and ports required
|
||||||
@ -62,7 +62,7 @@ class Service(object):
|
|||||||
self._is_running = is_running
|
self._is_running = is_running
|
||||||
|
|
||||||
# Maintain a complete list of services
|
# Maintain a complete list of services
|
||||||
assert(service_id not in services)
|
assert service_id not in services
|
||||||
services[service_id] = self
|
services[service_id] = self
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
@ -86,31 +86,35 @@ class Service(object):
|
|||||||
return self._call_or_return(self._is_enabled)
|
return self._call_or_return(self._is_enabled)
|
||||||
|
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
|
"""Return whether the service is running."""
|
||||||
if self._is_running is None:
|
if self._is_running is None:
|
||||||
return action_utils.service_is_running(self.service_id)
|
return action_utils.service_is_running(self.service_id)
|
||||||
else:
|
|
||||||
return self._call_or_return(self._is_running)
|
return self._call_or_return(self._is_running)
|
||||||
|
|
||||||
def notify_enabled(self, sender, enabled):
|
def notify_enabled(self, sender, enabled):
|
||||||
"""Notify observers about change in state of service."""
|
"""Notify observers about change in state of service."""
|
||||||
service_enabled.send_robust(sender=sender, service_id=self.service_id,
|
service_enabled.send_robust(sender=sender, service_id=self.service_id,
|
||||||
enabled=enabled)
|
enabled=enabled)
|
||||||
|
|
||||||
def _call_or_return(self, obj):
|
@staticmethod
|
||||||
|
def _call_or_return(obj):
|
||||||
"""Calls obj if it's callable, returns it if it's Boolean."""
|
"""Calls obj if it's callable, returns it if it's Boolean."""
|
||||||
if isinstance(obj, collections.Callable):
|
if isinstance(obj, collections.abc.Callable):
|
||||||
return obj()
|
return obj()
|
||||||
elif type(obj) is bool:
|
|
||||||
|
if isinstance(obj, bool):
|
||||||
return obj
|
return obj
|
||||||
else:
|
|
||||||
message = 'obj is expected to be callable or a boolean.'
|
message = 'obj is expected to be callable or a boolean.'
|
||||||
raise ValueError(message)
|
raise ValueError(message)
|
||||||
|
|
||||||
def _default_is_enabled(self):
|
def _default_is_enabled(self):
|
||||||
"""Returns is_enabled relying on a correct service_id"""
|
"""Returns is_enabled relying on a correct service_id"""
|
||||||
return action_utils.service_is_enabled(self.service_id)
|
return action_utils.service_is_enabled(self.service_id)
|
||||||
|
|
||||||
def get_internal_interfaces(self):
|
@staticmethod
|
||||||
|
def get_internal_interfaces():
|
||||||
"""Returns a list of interfaces in a firewall zone."""
|
"""Returns a list of interfaces in a firewall zone."""
|
||||||
from plinth.modules import firewall
|
from plinth.modules import firewall
|
||||||
return firewall.get_interfaces('internal')
|
return firewall.get_interfaces('internal')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user