mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
More stuff to reduce complexity
This commit is contained in:
parent
68c9244492
commit
f5c16737eb
2 changed files with 15 additions and 14 deletions
|
@ -4,9 +4,9 @@
|
|||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import glob
|
||||
|
||||
import moulinette
|
||||
from moulinette.actionsmap import ActionsMap
|
||||
from moulinette.interfaces.cli import colorize, get_locale
|
||||
|
||||
# Directory and file to be used by logging
|
||||
|
@ -123,6 +123,7 @@ def _retrieve_namespaces():
|
|||
extensions = [n for n in ActionsMap.get_namespaces() if n.startswith('ynh_')]
|
||||
return ['yunohost'] + extensions
|
||||
|
||||
|
||||
# Stupid PATH management because sometimes (e.g. some cron job) PATH is only /usr/bin:/bin ...
|
||||
default_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
if os.environ["PATH"] != default_path:
|
||||
|
@ -154,9 +155,11 @@ if __name__ == '__main__':
|
|||
print(colorize(m18n.g('error'), 'red') + " " + m18n.n('yunohost_not_installed'))
|
||||
sys.exit(1)
|
||||
|
||||
extensions = [f.split('/')[-1][:-4] for f in glob.glob("/usr/share/moulinette/actionsmap/ynh_*.yml")]
|
||||
|
||||
# Execute the action
|
||||
ret = moulinette.cli(
|
||||
_retrieve_namespaces(),
|
||||
['yunohost'] + extensions,
|
||||
args,
|
||||
output_as=opts.output_as,
|
||||
timeout=opts.timeout,
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import glob
|
||||
|
||||
import moulinette
|
||||
from moulinette.actionsmap import ActionsMap
|
||||
from moulinette.interfaces.cli import colorize
|
||||
|
||||
# Default server configuration
|
||||
DEFAULT_HOST = 'localhost'
|
||||
|
@ -23,6 +22,7 @@ if not os.path.isdir(LOG_DIR):
|
|||
|
||||
# Initialization & helpers functions -----------------------------------
|
||||
|
||||
|
||||
def _parse_api_args():
|
||||
"""Parse main arguments for the api"""
|
||||
parser = argparse.ArgumentParser(add_help=False,
|
||||
|
@ -48,6 +48,7 @@ def _parse_api_args():
|
|||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _init_moulinette(debug=False):
|
||||
"""Configure logging and initialize the moulinette"""
|
||||
|
||||
|
@ -107,14 +108,9 @@ def _init_moulinette(debug=False):
|
|||
# Initialize moulinette
|
||||
moulinette.init(logging_config=logging)
|
||||
|
||||
def _retrieve_namespaces():
|
||||
"""Return the list of namespaces to load"""
|
||||
extensions = [n for n in ActionsMap.get_namespaces() if n.startswith('ynh_')]
|
||||
return ['yunohost'] + extensions
|
||||
|
||||
|
||||
# Callbacks for additional routes --------------------------------------
|
||||
|
||||
|
||||
def is_installed():
|
||||
""" Check whether YunoHost is installed or not """
|
||||
return {'installed': os.path.isfile('/etc/yunohost/installed')}
|
||||
|
@ -124,14 +120,16 @@ def is_installed():
|
|||
|
||||
if __name__ == '__main__':
|
||||
opts = _parse_api_args()
|
||||
_init_moulinette(opts.use_websocket, opts.debug, opts.verbose)
|
||||
_init_moulinette(opts.debug)
|
||||
|
||||
extensions = [f.split('/')[-1][:-4] for f in glob.glob("/usr/share/moulinette/actionsmap/ynh_*.yml")]
|
||||
|
||||
# Run the server
|
||||
ret = moulinette.api(
|
||||
_retrieve_namespaces(),
|
||||
['yunohost'] + extensions,
|
||||
host=opts.host,
|
||||
port=opts.port,
|
||||
routes={ ('GET', '/installed'): is_installed, },
|
||||
routes={('GET', '/installed'): is_installed},
|
||||
use_websocket=True
|
||||
)
|
||||
sys.exit(ret)
|
||||
|
|
Loading…
Add table
Reference in a new issue