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 os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import glob
|
||||||
|
|
||||||
import moulinette
|
import moulinette
|
||||||
from moulinette.actionsmap import ActionsMap
|
|
||||||
from moulinette.interfaces.cli import colorize, get_locale
|
from moulinette.interfaces.cli import colorize, get_locale
|
||||||
|
|
||||||
# Directory and file to be used by logging
|
# 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_')]
|
extensions = [n for n in ActionsMap.get_namespaces() if n.startswith('ynh_')]
|
||||||
return ['yunohost'] + extensions
|
return ['yunohost'] + extensions
|
||||||
|
|
||||||
|
|
||||||
# Stupid PATH management because sometimes (e.g. some cron job) PATH is only /usr/bin:/bin ...
|
# 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"
|
default_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
if os.environ["PATH"] != default_path:
|
if os.environ["PATH"] != default_path:
|
||||||
|
@ -154,9 +155,11 @@ if __name__ == '__main__':
|
||||||
print(colorize(m18n.g('error'), 'red') + " " + m18n.n('yunohost_not_installed'))
|
print(colorize(m18n.g('error'), 'red') + " " + m18n.n('yunohost_not_installed'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
extensions = [f.split('/')[-1][:-4] for f in glob.glob("/usr/share/moulinette/actionsmap/ynh_*.yml")]
|
||||||
|
|
||||||
# Execute the action
|
# Execute the action
|
||||||
ret = moulinette.cli(
|
ret = moulinette.cli(
|
||||||
_retrieve_namespaces(),
|
['yunohost'] + extensions,
|
||||||
args,
|
args,
|
||||||
output_as=opts.output_as,
|
output_as=opts.output_as,
|
||||||
timeout=opts.timeout,
|
timeout=opts.timeout,
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
import glob
|
||||||
|
|
||||||
import moulinette
|
import moulinette
|
||||||
from moulinette.actionsmap import ActionsMap
|
|
||||||
from moulinette.interfaces.cli import colorize
|
|
||||||
|
|
||||||
# Default server configuration
|
# Default server configuration
|
||||||
DEFAULT_HOST = 'localhost'
|
DEFAULT_HOST = 'localhost'
|
||||||
|
@ -23,6 +22,7 @@ if not os.path.isdir(LOG_DIR):
|
||||||
|
|
||||||
# Initialization & helpers functions -----------------------------------
|
# Initialization & helpers functions -----------------------------------
|
||||||
|
|
||||||
|
|
||||||
def _parse_api_args():
|
def _parse_api_args():
|
||||||
"""Parse main arguments for the api"""
|
"""Parse main arguments for the api"""
|
||||||
parser = argparse.ArgumentParser(add_help=False,
|
parser = argparse.ArgumentParser(add_help=False,
|
||||||
|
@ -48,6 +48,7 @@ def _parse_api_args():
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def _init_moulinette(debug=False):
|
def _init_moulinette(debug=False):
|
||||||
"""Configure logging and initialize the moulinette"""
|
"""Configure logging and initialize the moulinette"""
|
||||||
|
|
||||||
|
@ -107,31 +108,28 @@ def _init_moulinette(debug=False):
|
||||||
# Initialize moulinette
|
# Initialize moulinette
|
||||||
moulinette.init(logging_config=logging)
|
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 --------------------------------------
|
# Callbacks for additional routes --------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def is_installed():
|
def is_installed():
|
||||||
""" Check whether YunoHost is installed or not """
|
""" Check whether YunoHost is installed or not """
|
||||||
return { 'installed': os.path.isfile('/etc/yunohost/installed') }
|
return {'installed': os.path.isfile('/etc/yunohost/installed')}
|
||||||
|
|
||||||
|
|
||||||
# Main action ----------------------------------------------------------
|
# Main action ----------------------------------------------------------
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
opts = _parse_api_args()
|
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
|
# Run the server
|
||||||
ret = moulinette.api(
|
ret = moulinette.api(
|
||||||
_retrieve_namespaces(),
|
['yunohost'] + extensions,
|
||||||
host=opts.host,
|
host=opts.host,
|
||||||
port=opts.port,
|
port=opts.port,
|
||||||
routes={ ('GET', '/installed'): is_installed, },
|
routes={('GET', '/installed'): is_installed},
|
||||||
use_websocket=True
|
use_websocket=True
|
||||||
)
|
)
|
||||||
sys.exit(ret)
|
sys.exit(ret)
|
||||||
|
|
Loading…
Add table
Reference in a new issue