mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
black/flake8
This commit is contained in:
parent
e8309384e5
commit
708b0330d2
6 changed files with 31 additions and 16 deletions
|
@ -85,14 +85,17 @@ def api(host="localhost", port=80, routes={}):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from moulinette.interfaces.api import Interface as Api
|
from moulinette.interfaces.api import Interface as Api
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Api(routes=routes).run(host, port)
|
Api(routes=routes).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)
|
||||||
return 1
|
return 1
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logging.getLogger().info(m18n.g("operation_interrupted"))
|
logging.getLogger().info(m18n.g("operation_interrupted"))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -111,11 +114,15 @@ def cli(args, top_parser, output_as=None, timeout=None):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from moulinette.interfaces.cli import Interface as Cli
|
from moulinette.interfaces.cli import Interface as Cli
|
||||||
|
|
||||||
try:
|
try:
|
||||||
load_only_category = args[0] if args and not args[0].startswith("-") else None
|
load_only_category = args[0] if args and not args[0].startswith("-") else None
|
||||||
Cli(top_parser=top_parser, load_only_category=load_only_category).run(args, output_as=output_as, timeout=timeout)
|
Cli(top_parser=top_parser, load_only_category=load_only_category).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)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -411,7 +411,9 @@ class ActionsMap(object):
|
||||||
|
|
||||||
def __init__(self, top_parser, load_only_category=None):
|
def __init__(self, top_parser, load_only_category=None):
|
||||||
|
|
||||||
assert isinstance(top_parser, BaseActionsMapParser), "Invalid parser class '%s'" % top_parser.__class__.__name__
|
assert isinstance(top_parser, BaseActionsMapParser), (
|
||||||
|
"Invalid parser class '%s'" % top_parser.__class__.__name__
|
||||||
|
)
|
||||||
|
|
||||||
moulinette_env = init_moulinette_env()
|
moulinette_env = init_moulinette_env()
|
||||||
DATA_DIR = moulinette_env["DATA_DIR"]
|
DATA_DIR = moulinette_env["DATA_DIR"]
|
||||||
|
@ -451,7 +453,11 @@ class ActionsMap(object):
|
||||||
# If we filter it even if it doesn't exist, we'll end up with a
|
# If we filter it even if it doesn't exist, we'll end up with a
|
||||||
# weird help message when we do a typo in the category name..
|
# weird help message when we do a typo in the category name..
|
||||||
if load_only_category and load_only_category in actionsmaps[n]:
|
if load_only_category and load_only_category in actionsmaps[n]:
|
||||||
actionsmaps[n] = {k: v for k, v in actionsmaps[n].items() if k in [load_only_category, "_global"]}
|
actionsmaps[n] = {
|
||||||
|
k: v
|
||||||
|
for k, v in actionsmaps[n].items()
|
||||||
|
if k in [load_only_category, "_global"]
|
||||||
|
}
|
||||||
|
|
||||||
# Load translations
|
# Load translations
|
||||||
m18n.load_namespace(n)
|
m18n.load_namespace(n)
|
||||||
|
@ -600,7 +606,9 @@ class ActionsMap(object):
|
||||||
|
|
||||||
# Look for all files that match the given patterns in the actionsmap dir
|
# Look for all files that match the given patterns in the actionsmap dir
|
||||||
for namespace_pattern in NAMESPACE_PATTERNS:
|
for namespace_pattern in NAMESPACE_PATTERNS:
|
||||||
namespaces.extend(glob.glob("%s/actionsmap/%s.yml" % (DATA_DIR, namespace_pattern)))
|
namespaces.extend(
|
||||||
|
glob.glob("%s/actionsmap/%s.yml" % (DATA_DIR, namespace_pattern))
|
||||||
|
)
|
||||||
|
|
||||||
# Keep only the filenames with extension
|
# Keep only the filenames with extension
|
||||||
namespaces = [os.path.basename(n)[:-4] for n in namespaces]
|
namespaces = [os.path.basename(n)[:-4] for n in namespaces]
|
||||||
|
|
|
@ -11,5 +11,7 @@ def init_moulinette_env():
|
||||||
"MOULINETTE_LOCALES_DIR", "/usr/share/moulinette/locale"
|
"MOULINETTE_LOCALES_DIR", "/usr/share/moulinette/locale"
|
||||||
),
|
),
|
||||||
"CACHE_DIR": environ.get("MOULINETTE_CACHE_DIR", "/var/cache/moulinette"),
|
"CACHE_DIR": environ.get("MOULINETTE_CACHE_DIR", "/var/cache/moulinette"),
|
||||||
"NAMESPACES": environ.get("MOULINETTE_NAMESPACES", "*").split(), # By default we'll load every namespace we find
|
"NAMESPACES": environ.get(
|
||||||
|
"MOULINETTE_NAMESPACES", "*"
|
||||||
|
).split(), # By default we'll load every namespace we find
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,10 +288,7 @@ class _ActionsMapPlugin(object):
|
||||||
|
|
||||||
# Append messages route
|
# Append messages route
|
||||||
app.route(
|
app.route(
|
||||||
"/messages",
|
"/messages", name="messages", callback=self.messages, skip=["actionsmap"],
|
||||||
name="messages",
|
|
||||||
callback=self.messages,
|
|
||||||
skip=["actionsmap"],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Append routes from the actions map
|
# Append routes from the actions map
|
||||||
|
@ -796,18 +793,14 @@ class Interface(BaseInterface):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"starting the server instance in %s:%d",
|
"starting the server instance in %s:%d", host, port,
|
||||||
host,
|
|
||||||
port,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
from geventwebsocket.handler import WebSocketHandler
|
from geventwebsocket.handler import WebSocketHandler
|
||||||
|
|
||||||
server = WSGIServer(
|
server = WSGIServer((host, port), self._app, handler_class=WebSocketHandler)
|
||||||
(host, port), self._app, handler_class=WebSocketHandler
|
|
||||||
)
|
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.exception("unable to start the server instance on %s:%d", host, port)
|
logger.exception("unable to start the server instance on %s:%d", host, port)
|
||||||
|
|
|
@ -431,7 +431,10 @@ 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(ActionsMapParser(top_parser=top_parser), load_only_category=load_only_category)
|
self.actionsmap = ActionsMap(
|
||||||
|
ActionsMapParser(top_parser=top_parser),
|
||||||
|
load_only_category=load_only_category,
|
||||||
|
)
|
||||||
|
|
||||||
def run(self, args, output_as=None, timeout=None):
|
def run(self, args, output_as=None, timeout=None):
|
||||||
"""Run the moulinette
|
"""Run the moulinette
|
||||||
|
|
|
@ -126,6 +126,7 @@ def moulinette_webapi(moulinette):
|
||||||
CookiePolicy.return_ok_secure = return_true
|
CookiePolicy.return_ok_secure = return_true
|
||||||
|
|
||||||
from moulinette.interfaces.api import Interface as Api
|
from moulinette.interfaces.api import Interface as Api
|
||||||
|
|
||||||
return TestApp(Api(routes={})._app)
|
return TestApp(Api(routes={})._app)
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,6 +145,7 @@ def moulinette_cli(moulinette, mocker):
|
||||||
)
|
)
|
||||||
mocker.patch("os.isatty", return_value=True)
|
mocker.patch("os.isatty", return_value=True)
|
||||||
from moulinette.interfaces.cli import Interface as Cli
|
from moulinette.interfaces.cli import Interface as Cli
|
||||||
|
|
||||||
cli = Cli(top_parser=parser)
|
cli = Cli(top_parser=parser)
|
||||||
mocker.stopall()
|
mocker.stopall()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue