clan-cli: add a check for the flatpak sandbox
Allows for differentiation between sandbox and non sandbox usage.
This commit is contained in:
parent
44d897e89f
commit
9bb4c8d094
|
@ -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])
|
||||
|
||||
|
|
16
pkgs/clan-cli/clan_cli/flatpak.py
Normal file
16
pkgs/clan-cli/clan_cli/flatpak.py
Normal 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
|
Loading…
Reference in New Issue
Block a user