clan-cli: add a check for the flatpak sandbox
All checks were successful
checks / check-links (pull_request) Successful in 14s
checks / checks-impure (pull_request) Successful in 1m50s
checks / checks (pull_request) Successful in 4m17s

Allows for differentiation between sandbox and non sandbox usage.
This commit is contained in:
a-kenji 2024-04-02 12:16:30 +02:00
parent 44d897e89f
commit 9bb4c8d094
2 changed files with 30 additions and 1 deletions

View File

@ -6,7 +6,18 @@ from pathlib import Path
from types import ModuleType
from typing import Any
from . import backups, config, facts, flakes, flash, history, machines, secrets, vms
from . import (
backups,
config,
facts,
flakes,
flash,
flatpak,
history,
machines,
secrets,
vms,
)
from .custom_logger import setup_logging
from .dirs import get_clan_flake_toplevel
from .errors import ClanCmdError, ClanError
@ -129,6 +140,8 @@ def main() -> None:
if args.debug:
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
log.debug("Debug log activated")
if flatpak.is_flatpak():
log.debug("Running inside a flatpak sandbox")
else:
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])

View File

@ -0,0 +1,16 @@
import os
def is_flatpak() -> bool:
"""Check if the current process is running inside a flatpak sandbox."""
# FLATPAK_ID environment variable check
flatpak_env = "FLATPAK_ID" in os.environ
flatpak_file = False
try:
with open("/.flatpak-info"):
flatpak_file = True
except FileNotFoundError:
pass
return flatpak_env and flatpak_file