diff --git a/moulinette/__init__.py b/moulinette/__init__.py index d27acac6..cf1992b8 100755 --- a/moulinette/__init__.py +++ b/moulinette/__init__.py @@ -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 diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 2fe17d71..7a365469 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -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] diff --git a/moulinette/globals.py b/moulinette/globals.py index 025aab52..8a169cea 100644 --- a/moulinette/globals.py +++ b/moulinette/globals.py @@ -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 } diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index f251c215..4714dd09 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -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) diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 186c0c89..d8e2dd2b 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -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 diff --git a/test/conftest.py b/test/conftest.py index 3f400b17..8e0ec8ac 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -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()