mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Hmpf idk another iteration to cleaning attempt
This commit is contained in:
parent
f5c16737eb
commit
233c962710
2 changed files with 20 additions and 29 deletions
26
bin/yunohost
26
bin/yunohost
|
@ -7,19 +7,13 @@ import argparse
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
import moulinette
|
import moulinette
|
||||||
from moulinette.interfaces.cli import colorize, get_locale
|
|
||||||
|
|
||||||
# Directory and file to be used by logging
|
# Directory and file to be used by logging
|
||||||
LOG_DIR = '/var/log/yunohost'
|
LOG_DIR = '/var/log/yunohost'
|
||||||
LOG_FILE = 'yunohost-cli.log'
|
LOG_FILE = 'yunohost-cli.log'
|
||||||
|
|
||||||
# Create log directory
|
|
||||||
if not os.path.isdir(LOG_DIR):
|
|
||||||
os.makedirs(LOG_DIR, 0750)
|
|
||||||
|
|
||||||
# Initialization & helpers functions -----------------------------------
|
# Initialization & helpers functions -----------------------------------
|
||||||
|
|
||||||
|
|
||||||
def _parse_cli_args():
|
def _parse_cli_args():
|
||||||
"""Parse additional arguments for the cli"""
|
"""Parse additional arguments for the cli"""
|
||||||
parser = argparse.ArgumentParser(add_help=False)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
|
@ -58,11 +52,13 @@ def _parse_cli_args():
|
||||||
return (parser, opts, args)
|
return (parser, opts, args)
|
||||||
|
|
||||||
|
|
||||||
def _init_moulinette(debug=False, quiet=False):
|
def init(debug=False, quiet=False, logfile='%s/%s' % (LOG_DIR, LOG_FILE)):
|
||||||
"""Configure logging and initialize the moulinette"""
|
|
||||||
|
|
||||||
# Custom logging configuration
|
logdir = os.path.dirname(logfile)
|
||||||
logging = {
|
if not os.path.isdir(logdir):
|
||||||
|
os.makedirs(logdir, 0750)
|
||||||
|
|
||||||
|
moulinette.init(logging_config={
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': True,
|
'disable_existing_loggers': True,
|
||||||
'formatters': {
|
'formatters': {
|
||||||
|
@ -87,7 +83,7 @@ def _init_moulinette(debug=False, quiet=False):
|
||||||
'file': {
|
'file': {
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'formatter': 'precise',
|
'formatter': 'precise',
|
||||||
'filename': '%s/%s' % (LOG_DIR, LOG_FILE),
|
'filename': logfile,
|
||||||
'filters': ['action'],
|
'filters': ['action'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -112,10 +108,8 @@ def _init_moulinette(debug=False, quiet=False):
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': ['file', 'tty'] if debug else ['file'],
|
'handlers': ['file', 'tty'] if debug else ['file'],
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
# Initialize moulinette
|
|
||||||
moulinette.init(logging_config=logging)
|
|
||||||
|
|
||||||
|
|
||||||
def _retrieve_namespaces():
|
def _retrieve_namespaces():
|
||||||
|
@ -139,7 +133,7 @@ if __name__ == '__main__':
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
parser, opts, args = _parse_cli_args()
|
parser, opts, args = _parse_cli_args()
|
||||||
_init_moulinette(opts.debug, opts.quiet)
|
init(debug=opts.debug, quiet=opts.quiet)
|
||||||
|
|
||||||
# Check that YunoHost is installed
|
# Check that YunoHost is installed
|
||||||
allowed_if_not_installed = ['tools postinstall', 'backup restore', 'log display']
|
allowed_if_not_installed = ['tools postinstall', 'backup restore', 'log display']
|
||||||
|
@ -147,6 +141,8 @@ if __name__ == '__main__':
|
||||||
(len(args) < 2 or (args[0] + ' ' + args[1] not in allowed_if_not_installed)):
|
(len(args) < 2 or (args[0] + ' ' + args[1] not in allowed_if_not_installed)):
|
||||||
|
|
||||||
from moulinette import m18n
|
from moulinette import m18n
|
||||||
|
from moulinette.interfaces.cli import colorize, get_locale
|
||||||
|
|
||||||
# Init i18n
|
# Init i18n
|
||||||
m18n.load_namespace('yunohost')
|
m18n.load_namespace('yunohost')
|
||||||
m18n.set_locale(get_locale())
|
m18n.set_locale(get_locale())
|
||||||
|
|
|
@ -16,10 +16,6 @@ DEFAULT_PORT = 6787
|
||||||
LOG_DIR = '/var/log/yunohost'
|
LOG_DIR = '/var/log/yunohost'
|
||||||
LOG_FILE = 'yunohost-api.log'
|
LOG_FILE = 'yunohost-api.log'
|
||||||
|
|
||||||
# Create log directory
|
|
||||||
if not os.path.isdir(LOG_DIR):
|
|
||||||
os.makedirs(LOG_DIR, 0750)
|
|
||||||
|
|
||||||
# Initialization & helpers functions -----------------------------------
|
# Initialization & helpers functions -----------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,11 +45,13 @@ def _parse_api_args():
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def _init_moulinette(debug=False):
|
def init_api(debug=False, logfile='%s/%s' % (LOG_DIR, LOG_FILE)):
|
||||||
"""Configure logging and initialize the moulinette"""
|
|
||||||
|
|
||||||
# Custom logging configuration
|
logdir = os.path.dirname(logfile)
|
||||||
logging = {
|
if not os.path.isdir(logdir):
|
||||||
|
os.makedirs(logdir, 0750)
|
||||||
|
|
||||||
|
moulinette.init(logging_config={
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': True,
|
'disable_existing_loggers': True,
|
||||||
'formatters': {
|
'formatters': {
|
||||||
|
@ -77,7 +75,7 @@ def _init_moulinette(debug=False):
|
||||||
'file': {
|
'file': {
|
||||||
'class': 'logging.handlers.WatchedFileHandler',
|
'class': 'logging.handlers.WatchedFileHandler',
|
||||||
'formatter': 'precise',
|
'formatter': 'precise',
|
||||||
'filename': '%s/%s' % (LOG_DIR, LOG_FILE),
|
'filename': logfile,
|
||||||
'filters': ['action'],
|
'filters': ['action'],
|
||||||
},
|
},
|
||||||
'console': {
|
'console': {
|
||||||
|
@ -103,10 +101,7 @@ def _init_moulinette(debug=False):
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'handlers': ['file'] + ['console'] if debug else [],
|
'handlers': ['file'] + ['console'] if debug else [],
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
# Initialize moulinette
|
|
||||||
moulinette.init(logging_config=logging)
|
|
||||||
|
|
||||||
# Callbacks for additional routes --------------------------------------
|
# Callbacks for additional routes --------------------------------------
|
||||||
|
|
||||||
|
@ -120,7 +115,7 @@ def is_installed():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
opts = _parse_api_args()
|
opts = _parse_api_args()
|
||||||
_init_moulinette(opts.debug)
|
init_api(opts.debug)
|
||||||
|
|
||||||
extensions = [f.split('/')[-1][:-4] for f in glob.glob("/usr/share/moulinette/actionsmap/ynh_*.yml")]
|
extensions = [f.split('/')[-1][:-4] for f in glob.glob("/usr/share/moulinette/actionsmap/ynh_*.yml")]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue