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
|
||||
|
||||
try:
|
||||
Api(routes=routes).run(host, port)
|
||||
except MoulinetteError as e:
|
||||
import logging
|
||||
|
||||
logging.getLogger().error(e.strerror)
|
||||
return 1
|
||||
except KeyboardInterrupt:
|
||||
import logging
|
||||
|
||||
logging.getLogger().info(m18n.g("operation_interrupted"))
|
||||
return 0
|
||||
|
||||
|
@ -111,11 +114,15 @@ def cli(args, top_parser, output_as=None, timeout=None):
|
|||
|
||||
"""
|
||||
from moulinette.interfaces.cli import Interface as Cli
|
||||
|
||||
try:
|
||||
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:
|
||||
import logging
|
||||
|
||||
logging.getLogger().error(e.strerror)
|
||||
return 1
|
||||
return 0
|
||||
|
|
|
@ -411,7 +411,9 @@ class ActionsMap(object):
|
|||
|
||||
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()
|
||||
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
|
||||
# weird help message when we do a typo in the category name..
|
||||
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
|
||||
m18n.load_namespace(n)
|
||||
|
@ -600,7 +606,9 @@ class ActionsMap(object):
|
|||
|
||||
# Look for all files that match the given patterns in the actionsmap dir
|
||||
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
|
||||
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"
|
||||
),
|
||||
"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
|
||||
app.route(
|
||||
"/messages",
|
||||
name="messages",
|
||||
callback=self.messages,
|
||||
skip=["actionsmap"],
|
||||
"/messages", name="messages", callback=self.messages, skip=["actionsmap"],
|
||||
)
|
||||
|
||||
# Append routes from the actions map
|
||||
|
@ -796,18 +793,14 @@ class Interface(BaseInterface):
|
|||
|
||||
"""
|
||||
logger.debug(
|
||||
"starting the server instance in %s:%d",
|
||||
host,
|
||||
port,
|
||||
"starting the server instance in %s:%d", host, port,
|
||||
)
|
||||
|
||||
try:
|
||||
from gevent.pywsgi import WSGIServer
|
||||
from geventwebsocket.handler import WebSocketHandler
|
||||
|
||||
server = WSGIServer(
|
||||
(host, port), self._app, handler_class=WebSocketHandler
|
||||
)
|
||||
server = WSGIServer((host, port), self._app, handler_class=WebSocketHandler)
|
||||
server.serve_forever()
|
||||
except IOError as e:
|
||||
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("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):
|
||||
"""Run the moulinette
|
||||
|
|
|
@ -126,6 +126,7 @@ def moulinette_webapi(moulinette):
|
|||
CookiePolicy.return_ok_secure = return_true
|
||||
|
||||
from moulinette.interfaces.api import Interface as Api
|
||||
|
||||
return TestApp(Api(routes={})._app)
|
||||
|
||||
|
||||
|
@ -144,6 +145,7 @@ def moulinette_cli(moulinette, mocker):
|
|||
)
|
||||
mocker.patch("os.isatty", return_value=True)
|
||||
from moulinette.interfaces.cli import Interface as Cli
|
||||
|
||||
cli = Cli(top_parser=parser)
|
||||
mocker.stopall()
|
||||
|
||||
|
|
Loading…
Reference in a new issue