Added utils.is_root method.

This commit is contained in:
Fabio Manganiello 2023-08-31 23:19:13 +02:00
parent 1be40f30d6
commit 9aaf2559fa
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 10 additions and 3 deletions

View file

@ -655,4 +655,11 @@ def get_src_root() -> str:
return os.path.dirname(inspect.getfile(platypush)) return os.path.dirname(inspect.getfile(platypush))
def is_root() -> bool:
"""
:return: True if the current user is root/administrator.
"""
return os.getuid() == 0
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et:

View file

@ -30,7 +30,7 @@ from typing_extensions import override
import yaml import yaml
from platypush.message.event import Event from platypush.message.event import Event
from platypush.utils import get_src_root from platypush.utils import get_src_root, is_root
_available_package_manager = None _available_package_manager = None
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -250,7 +250,7 @@ class Dependencies:
""" """
:return: True if the system dependencies should be installed with sudo. :return: True if the system dependencies should be installed with sudo.
""" """
return not (self._is_docker or os.getuid() == 0) return not (self._is_docker or is_root())
@staticmethod @staticmethod
def _get_requirements_dir() -> str: def _get_requirements_dir() -> str:
@ -359,7 +359,7 @@ class Dependencies:
dependencies on the system. dependencies on the system.
""" """
wants_sudo = not (self._is_docker or os.getuid() == 0) wants_sudo = not (self._is_docker or is_root())
pkg_manager = self.pkg_manager or PackageManagers.scan() pkg_manager = self.pkg_manager or PackageManagers.scan()
if self.packages and pkg_manager: if self.packages and pkg_manager: