mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Remove _die, simplify creation of log dir, make linter a bit happier
This commit is contained in:
parent
31e5f7e8b5
commit
68c9244492
2 changed files with 14 additions and 26 deletions
24
bin/yunohost
24
bin/yunohost
|
@ -13,12 +13,12 @@ from moulinette.interfaces.cli import colorize, get_locale
|
||||||
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 _die(message, title='Error:'):
|
|
||||||
"""Print error message and exit"""
|
|
||||||
print('%s %s' % (colorize(title, 'red'), message))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def _parse_cli_args():
|
def _parse_cli_args():
|
||||||
"""Parse additional arguments for the cli"""
|
"""Parse additional arguments for the cli"""
|
||||||
|
@ -57,16 +57,10 @@ def _parse_cli_args():
|
||||||
|
|
||||||
return (parser, opts, args)
|
return (parser, opts, args)
|
||||||
|
|
||||||
|
|
||||||
def _init_moulinette(debug=False, quiet=False):
|
def _init_moulinette(debug=False, quiet=False):
|
||||||
"""Configure logging and initialize the moulinette"""
|
"""Configure logging and initialize the moulinette"""
|
||||||
|
|
||||||
# Create log directory
|
|
||||||
if not os.path.isdir(LOG_DIR):
|
|
||||||
try:
|
|
||||||
os.makedirs(LOG_DIR, 0750)
|
|
||||||
except os.error as e:
|
|
||||||
_die(str(e))
|
|
||||||
|
|
||||||
# Custom logging configuration
|
# Custom logging configuration
|
||||||
logging = {
|
logging = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
|
@ -123,6 +117,7 @@ def _init_moulinette(debug=False, quiet=False):
|
||||||
# Initialize moulinette
|
# Initialize moulinette
|
||||||
moulinette.init(logging_config=logging)
|
moulinette.init(logging_config=logging)
|
||||||
|
|
||||||
|
|
||||||
def _retrieve_namespaces():
|
def _retrieve_namespaces():
|
||||||
"""Return the list of namespaces to load"""
|
"""Return the list of namespaces to load"""
|
||||||
extensions = [n for n in ActionsMap.get_namespaces() if n.startswith('ynh_')]
|
extensions = [n for n in ActionsMap.get_namespaces() if n.startswith('ynh_')]
|
||||||
|
@ -138,7 +133,7 @@ if os.environ["PATH"] != default_path:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if os.geteuid() != 0:
|
if os.geteuid() != 0:
|
||||||
# since moulinette isn't initialized, we can't use m18n here
|
# since moulinette isn't initialized, we can't use m18n here
|
||||||
sys.stderr.write("\033[1;31mError:\033[0m yunohost command must be " \
|
sys.stderr.write("\033[1;31mError:\033[0m yunohost command must be "
|
||||||
"run as root or with sudo.\n")
|
"run as root or with sudo.\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -148,7 +143,7 @@ if __name__ == '__main__':
|
||||||
# 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']
|
||||||
if not os.path.isfile('/etc/yunohost/installed') and \
|
if not os.path.isfile('/etc/yunohost/installed') and \
|
||||||
(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
|
||||||
# Init i18n
|
# Init i18n
|
||||||
|
@ -156,7 +151,8 @@ if __name__ == '__main__':
|
||||||
m18n.set_locale(get_locale())
|
m18n.set_locale(get_locale())
|
||||||
|
|
||||||
# Print error and exit
|
# Print error and exit
|
||||||
_die(m18n.n('yunohost_not_installed'), m18n.g('error'))
|
print(colorize(m18n.g('error'), 'red') + " " + m18n.n('yunohost_not_installed'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Execute the action
|
# Execute the action
|
||||||
ret = moulinette.cli(
|
ret = moulinette.cli(
|
||||||
|
|
|
@ -17,12 +17,11 @@ DEFAULT_PORT = 6787
|
||||||
LOG_DIR = '/var/log/yunohost'
|
LOG_DIR = '/var/log/yunohost'
|
||||||
LOG_FILE = 'yunohost-api.log'
|
LOG_FILE = 'yunohost-api.log'
|
||||||
|
|
||||||
# Initialization & helpers functions -----------------------------------
|
# Create log directory
|
||||||
|
if not os.path.isdir(LOG_DIR):
|
||||||
|
os.makedirs(LOG_DIR, 0750)
|
||||||
|
|
||||||
def _die(message, title='Error:'):
|
# Initialization & helpers functions -----------------------------------
|
||||||
"""Print error message and exit"""
|
|
||||||
print('%s %s' % (colorize(title, 'red'), message))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def _parse_api_args():
|
def _parse_api_args():
|
||||||
"""Parse main arguments for the api"""
|
"""Parse main arguments for the api"""
|
||||||
|
@ -52,13 +51,6 @@ def _parse_api_args():
|
||||||
def _init_moulinette(debug=False):
|
def _init_moulinette(debug=False):
|
||||||
"""Configure logging and initialize the moulinette"""
|
"""Configure logging and initialize the moulinette"""
|
||||||
|
|
||||||
# Create log directory
|
|
||||||
if not os.path.isdir(LOG_DIR):
|
|
||||||
try:
|
|
||||||
os.makedirs(LOG_DIR, 0750)
|
|
||||||
except os.error as e:
|
|
||||||
_die(str(e))
|
|
||||||
|
|
||||||
# Custom logging configuration
|
# Custom logging configuration
|
||||||
logging = {
|
logging = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
|
|
Loading…
Add table
Reference in a new issue