comparison libervia/backend/core/constants.py @ 4202:b26339343076

core: use a user specific directory for PID file: default location of pid file is now specific to logged user, this allow to run several instances of Libervia by different users on the same machine without PID conflicts.
author Goffi <goffi@goffi.org>
date Sun, 14 Jan 2024 17:48:02 +0100
parents 50c919dfe61b
children 5a0bddfa34ac
comparison
equal deleted inserted replaced
4201:6a8cc6d668a4 4202:b26339343076
19 try: 19 try:
20 from xdg import BaseDirectory 20 from xdg import BaseDirectory
21 from os.path import expanduser, realpath 21 from os.path import expanduser, realpath
22 except ImportError: 22 except ImportError:
23 BaseDirectory = None 23 BaseDirectory = None
24 from os.path import dirname 24 from os.path import dirname, join
25 import tempfile 25 import tempfile
26 from typing import Final 26 from typing import Final
27 27
28 from libervia import backend 28 from libervia import backend
29
30 try:
31 from getpass import getuser
32 except ImportError:
33 logged_user = "unkonwn"
34 else:
35 logged_user = getuser()
29 36
30 37
31 class Const(object): 38 class Const(object):
32 39
33 ## Application ## 40 ## Application ##
456 """@return (str): constant associated to bool value""" 463 """@return (str): constant associated to bool value"""
457 assert isinstance(value, bool) 464 assert isinstance(value, bool)
458 return cls.BOOL_TRUE if value else cls.BOOL_FALSE 465 return cls.BOOL_TRUE if value else cls.BOOL_FALSE
459 466
460 467
461
462 ## Configuration ## 468 ## Configuration ##
463 if ( 469 if (
464 BaseDirectory 470 BaseDirectory
465 ): # skipped when xdg module is not available (should not happen in backend) 471 ): # skipped when xdg module is not available (should not happen in backend)
466 if "org.libervia.cagou" in BaseDirectory.__file__: 472 if "org.libervia.cagou" in BaseDirectory.__file__:
487 Environment.getExternalStoragePublicDirectory( 493 Environment.getExternalStoragePublicDirectory(
488 Environment.DIRECTORY_DOWNLOADS 494 Environment.DIRECTORY_DOWNLOADS
489 ).getAbsolutePath(), 495 ).getAbsolutePath(),
490 Const.APP_NAME_FILE, 496 Const.APP_NAME_FILE,
491 ), 497 ),
492 "pid_dir": tempfile.gettempdir(), 498 "pid_dir": join(tempfile.gettempdir(), Const.APP_NAME_FILE, logged_user),
493 "log_dir": "%(local_dir)s", 499 "log_dir": "%(local_dir)s",
494 } 500 }
495 Const.CONFIG_FILES = [ 501 Const.CONFIG_FILES = [
496 "/data/data/org.libervia.cagou/files/app/android/" 502 "/data/data/org.libervia.cagou/files/app/android/"
497 + Const.APP_NAME_FILE 503 + Const.APP_NAME_FILE
530 ## Configuration ## 536 ## Configuration ##
531 Const.DEFAULT_CONFIG = { 537 Const.DEFAULT_CONFIG = {
532 "media_dir": "/usr/share/" + Const.APP_NAME_FILE + "/media", 538 "media_dir": "/usr/share/" + Const.APP_NAME_FILE + "/media",
533 "local_dir": BaseDirectory.save_data_path(Const.APP_NAME_FILE), 539 "local_dir": BaseDirectory.save_data_path(Const.APP_NAME_FILE),
534 "downloads_dir": "~/Downloads/" + Const.APP_NAME_FILE, 540 "downloads_dir": "~/Downloads/" + Const.APP_NAME_FILE,
535 "pid_dir": tempfile.gettempdir(), 541 "pid_dir": join(tempfile.gettempdir(), Const.APP_NAME_FILE, logged_user),
536 "log_dir": "%(local_dir)s", 542 "log_dir": "%(local_dir)s",
537 } 543 }
538 544
539 # List of the configuration filenames sorted by ascending priority 545 # List of the configuration filenames sorted by ascending priority
540 Const.CONFIG_FILES = [ 546 Const.CONFIG_FILES = [