Add an 'init' helper for scripts/tests to initialize everything needed...

This commit is contained in:
Alexandre Aubin 2020-04-29 04:43:04 +02:00
parent 7df8e8421d
commit 84e39a416a

View file

@ -72,6 +72,19 @@ def check_command_is_valid_before_postinstall(args):
sys.exit(1) sys.exit(1)
def init(interface="cli", debug=False, quiet=False, logdir="/var/log/yunohost"):
"""
This is a small util function ONLY meant to be used to initialize a Yunohost
context when ran from tests or from scripts.
"""
init_logging(interface=interface, debug=debug, quiet=quiet, logdir=logdir)
init_i18n()
from moulinette.core import MoulinetteLock
lock = MoulinetteLock("yunohost", timeout=30)
lock.acquire()
return lock
def init_i18n(): def init_i18n():
# This should only be called when not willing to go through moulinette.cli # This should only be called when not willing to go through moulinette.cli
# or moulinette.api but still willing to call m18n.n/g... # or moulinette.api but still willing to call m18n.n/g...