From 9aaf2559faace8789c4eacf5178ea3b6680fb11d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 31 Aug 2023 23:19:13 +0200 Subject: [PATCH] Added `utils.is_root` method. --- platypush/utils/__init__.py | 7 +++++++ platypush/utils/manifest.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/platypush/utils/__init__.py b/platypush/utils/__init__.py index 3ec6934e0..45ffbedb9 100644 --- a/platypush/utils/__init__.py +++ b/platypush/utils/__init__.py @@ -655,4 +655,11 @@ def get_src_root() -> str: 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: diff --git a/platypush/utils/manifest.py b/platypush/utils/manifest.py index 48a8a0ab2..b5f6c39b2 100644 --- a/platypush/utils/manifest.py +++ b/platypush/utils/manifest.py @@ -30,7 +30,7 @@ from typing_extensions import override import yaml 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 logger = logging.getLogger(__name__) @@ -250,7 +250,7 @@ class Dependencies: """ :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 def _get_requirements_dir() -> str: @@ -359,7 +359,7 @@ class Dependencies: 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() if self.packages and pkg_manager: