mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Another round of simplification for interface init...
This commit is contained in:
parent
c750226a3b
commit
559f40a4ea
3 changed files with 12 additions and 15 deletions
|
@ -84,13 +84,9 @@ def api(host="localhost", port=80, routes={}):
|
||||||
{(method, uri): callback}
|
{(method, uri): callback}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from moulinette.actionsmap import ActionsMap
|
from moulinette.interfaces.api import Interface as Api
|
||||||
from moulinette.interfaces.api import Interface, ActionsMapParser
|
|
||||||
try:
|
try:
|
||||||
actionsmap = ActionsMap(ActionsMapParser())
|
Api(routes=routes).run(host, port)
|
||||||
interface = Interface(actionsmap=actionsmap,
|
|
||||||
routes=routes)
|
|
||||||
interface.run(host, port)
|
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger().error(e.strerror)
|
logging.getLogger().error(e.strerror)
|
||||||
|
@ -114,12 +110,9 @@ def cli(args, top_parser, output_as=None, timeout=None):
|
||||||
- top_parser -- The top parser used to build the ActionsMapParser
|
- top_parser -- The top parser used to build the ActionsMapParser
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from moulinette.actionsmap import ActionsMap
|
from moulinette.interfaces.cli import Interface as Cli
|
||||||
from moulinette.interfaces.cli import Interface, ActionsMapParser
|
|
||||||
try:
|
try:
|
||||||
actionsmap = ActionsMap(ActionsMapParser(top_parser=top_parser))
|
Cli(top_parser=top_parser).run(args, output_as=output_as, timeout=timeout)
|
||||||
interface = Interface(actionsmap=actionsmap)
|
|
||||||
interface.run(args, output_as=output_as, timeout=timeout)
|
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger().error(e.strerror)
|
logging.getLogger().error(e.strerror)
|
||||||
|
|
|
@ -14,6 +14,7 @@ from bottle import request, response, Bottle, HTTPResponse
|
||||||
from bottle import abort
|
from bottle import abort
|
||||||
|
|
||||||
from moulinette import msignals, m18n, env
|
from moulinette import msignals, m18n, env
|
||||||
|
from moulinette.actionsmap import ActionsMap
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.interfaces import (
|
from moulinette.interfaces import (
|
||||||
BaseActionsMapParser,
|
BaseActionsMapParser,
|
||||||
|
@ -729,7 +730,6 @@ class Interface(BaseInterface):
|
||||||
actions map.
|
actions map.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
- actionsmap -- The ActionsMap instance to connect to
|
|
||||||
- routes -- A dict of additional routes to add in the form of
|
- routes -- A dict of additional routes to add in the form of
|
||||||
{(method, path): callback}
|
{(method, path): callback}
|
||||||
- log_queues -- A LogQueues object or None to retrieve it from
|
- log_queues -- A LogQueues object or None to retrieve it from
|
||||||
|
@ -737,7 +737,9 @@ class Interface(BaseInterface):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, actionsmap, routes={}, log_queues=None):
|
def __init__(self, routes={}, log_queues=None):
|
||||||
|
|
||||||
|
actionsmap = ActionsMap(ActionsMapParser())
|
||||||
|
|
||||||
# Attempt to retrieve log queues from an APIQueueHandler
|
# Attempt to retrieve log queues from an APIQueueHandler
|
||||||
if log_queues is None:
|
if log_queues is None:
|
||||||
|
|
|
@ -12,6 +12,7 @@ from datetime import date, datetime
|
||||||
import argcomplete
|
import argcomplete
|
||||||
|
|
||||||
from moulinette import msignals, m18n
|
from moulinette import msignals, m18n
|
||||||
|
from moulinette.actionsmap import ActionsMap
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
from moulinette.interfaces import (
|
from moulinette.interfaces import (
|
||||||
BaseActionsMapParser,
|
BaseActionsMapParser,
|
||||||
|
@ -419,7 +420,8 @@ class Interface(BaseInterface):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, actionsmap):
|
def __init__(self, top_parser=None):
|
||||||
|
|
||||||
# Set user locale
|
# Set user locale
|
||||||
m18n.set_locale(get_locale())
|
m18n.set_locale(get_locale())
|
||||||
|
|
||||||
|
@ -429,7 +431,7 @@ class Interface(BaseInterface):
|
||||||
msignals.set_handler("authenticate", self._do_authenticate)
|
msignals.set_handler("authenticate", self._do_authenticate)
|
||||||
msignals.set_handler("prompt", self._do_prompt)
|
msignals.set_handler("prompt", self._do_prompt)
|
||||||
|
|
||||||
self.actionsmap = actionsmap
|
self.actionsmap = ActionsMap(ActionsMapParser(top_parser=top_parser))
|
||||||
|
|
||||||
def run(self, args, output_as=None, timeout=None):
|
def run(self, args, output_as=None, timeout=None):
|
||||||
"""Run the moulinette
|
"""Run the moulinette
|
||||||
|
|
Loading…
Add table
Reference in a new issue