From 97adb1a1916fd3e3c335913e599fffedf3029c44 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 22 Dec 2017 02:52:56 +0100 Subject: [PATCH] * Better documentation for the local backend * Remove the fifos at the beginning of the test --- platypush/backend/local/__init__.py | 18 ++++++++++++++++-- tests/test_local.py | 7 +++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/platypush/backend/local/__init__.py b/platypush/backend/local/__init__.py index b77105e9..9e386169 100644 --- a/platypush/backend/local/__init__.py +++ b/platypush/backend/local/__init__.py @@ -12,8 +12,22 @@ from platypush.message.request import Request from platypush.message.response import Response class LocalBackend(Backend): - """ Sends and receive messages on two distinct local FIFOs, one for - the requests and one for the responses """ + """ + Sends and receive messages on two distinct local FIFOs, one for + the requests and one for the responses. + + You can use this backend either to send local commands to push through + Pusher (or any other script), or debug. You can even send command on the + command line and read the responses in this way: + + # Send the request. Remember: the JSON must be all on one line. + $ cat < /tmp/platypush-requests.fifo + {"type": "request", "target": "node_name", "action": "shell.exec", "args": {"cmd":"echo ping"}, "origin": "node_name", "id": "put_an_id_here"} + EOF + $ cat /tmp/platypush-responses.fifo + ping + $ + """ def __init__(self, request_fifo, response_fifo, **kwargs): super().__init__(**kwargs) diff --git a/tests/test_local.py b/tests/test_local.py index 2fed7755..bf095690 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -1,5 +1,6 @@ from .context import platypush, config_file, TestTimeoutException +import os import sys import logging import unittest @@ -22,6 +23,12 @@ class TestLocal(unittest.TestCase): backends = Config.get_backends() self.assertTrue('local' in backends) + try: os.remove(Config.get_backends()['local']['request_fifo']) + except FileNotFoundError as e: pass + + try: os.remove(Config.get_backends()['local']['response_fifo']) + except FileNotFoundError as e: pass + def test_local_shell_exec_flow(self): self.start_sender()