Merge pull request 'clan-cli: add a check for the flatpak sandbox' (#1088) from a-kenji-clan-cli/check/flatpak-sandbox into main
All checks were successful
checks / check-links (push) Successful in 14s
checks / checks (push) Successful in 37s
checks / checks-impure (push) Successful in 1m49s

This commit is contained in:
clan-bot 2024-04-02 10:24:49 +00:00
commit 439293a079
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