From 76024898462ad27f62b29b0add9e8ad5d68022f2 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Wed, 26 May 2021 06:03:04 +0200 Subject: [PATCH] Initial commit --- .gitignore | 4 ++++ LICENSE | 19 +++++++++++++++++++ README.md | 14 ++++++++++++++ conf.json | 19 +++++++++++++++++++ controlpi_plugins/graph.py | 34 ++++++++++++++++++++++++++++++++++ doc/index.md | 28 ++++++++++++++++++++++++++++ setup.py | 24 ++++++++++++++++++++++++ 7 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 conf.json create mode 100644 controlpi_plugins/graph.py create mode 100644 doc/index.md create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..494a764 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +__pycache__/ +dist/ +controlpi_graph.egg-info/ +venv/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ebb8ac1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2021 Graph-IT GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cdc7855 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# ControlPi Plugin for Graph Connections +This distribution package contains a plugin for the +[ControlPi system](https://docs.graph-it.com/graphit/controlpi), that +<…> + +Documentation (in German) can be found at [doc/index.md](doc/index.md) in +the source repository and at +[https://docs.graph-it.com/graphit/controlpi-graph/](https://docs.graph-it.com/graphit/controlpi-graph/). +Code documentation (in English) including doctests is contained in the +source files. +An API documentation generated by pdoc3 can be found at +[doc/controlpi_plugins/index.html](doc/controlpi_plugins/index.html) in the source +repository and at +[https://docs.graph-it.com/graphit/controlpi-graph/controlpi_plugins/](https://docs.graph-it.com/graphit/controlpi-graph/controlpi_plugins/). diff --git a/conf.json b/conf.json new file mode 100644 index 0000000..e03ac66 --- /dev/null +++ b/conf.json @@ -0,0 +1,19 @@ +{ + "Example Server": { + "plugin": "WSServer", + "port": 8080, + "web": { + "/": { "module": "controlpi_plugins.wsserver", + "location": "Debug" } + } + }, + "Test Graph": { + "plugin": "GraphConnection", + "url": "tls://graph.example.com", + "crt": "graph.crt" + }, + "Example State": { + "plugin": "State" + }, + ... +} diff --git a/controlpi_plugins/graph.py b/controlpi_plugins/graph.py new file mode 100644 index 0000000..b90fdc9 --- /dev/null +++ b/controlpi_plugins/graph.py @@ -0,0 +1,34 @@ +"""Provide Graph Connections as ControlPi Plugin + +… + +TODO: documentation, doctests +""" +from controlpi import BasePlugin, Message, MessageTemplate + + +class GraphConnection(BasePlugin): + """Graph connection plugin. + + Connect to remote graph and allow execution of API calls over this + connection. + """ + + CONF_SCHEMA = {'properties': + {'url': {'type': 'string'}, + 'crt': {'type': 'string'}}, + 'required': ['url', 'crt']} + + async def _receive(self, message: Message) -> None: + await self.bus.send(Message(self.name, {'spam': self.conf['spam']})) + + def process_conf(self) -> None: + """Register plugin as bus client.""" + message = Message(self.name, {'spam': self.conf['spam']}) + sends = [MessageTemplate.from_message(message)] + receives = [MessageTemplate({'target': {'const': self.name}})] + self.bus.register(self.name, 'Plugin', sends, receives, self._receive) + + async def run(self) -> None: + """Send initial message.""" + await self.bus.send(Message(self.name, {'spam': self.conf['spam']})) diff --git a/doc/index.md b/doc/index.md new file mode 100644 index 0000000..d891071 --- /dev/null +++ b/doc/index.md @@ -0,0 +1,28 @@ +# ControlPi-Plugin für Graph-Connections +Dieses Paket enthält ein Plugin für das ControlPi-System, mit dem <…> + +## Benutzung +… + +## Installation +Eine ausführliche Dokumentation ist in der Dokumentation der +[ControlPi-Infrastruktur](https://docs.graph-it.com/graphit/controlpi) zu +finden. + +Der Code dieses Plugins kann mit git geclonet werden: +```sh +$ git clone git://git.graph-it.com/graphit/controlpi-graph.git +``` +(Falls Zugang zu diesem Server per SSH besteht und Änderungen gepusht +werden sollen, sollte stattdessen die SSH-URL benutzt werden.) + +Dann kann es editierbar in ein virtuelles Environment installiert werden: +```sh +(venv)$ pip install --editable +``` + +Auf dem Raspberry Pi (oder wenn keine Code-Änderungen gewünscht sind) kann +es auch direkt, ohne einen git-Clone installiert werden: +```sh +(venv)$ pip install git+git://git.graph-it.com/graphit/controlpi-graph.git +``` diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d4422d5 --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +import setuptools + +with open("README.md", "r") as readme_file: + long_description = readme_file.read() + +setuptools.setup( + name="controlpi-graph", + version="0.1.0", + author="Graph-IT GmbH", + author_email="info@graph-it.com", + description="ControlPi Plugin for Graph Connections", + long_description=long_description, + long_description_content_type="text/markdown", + url="http://docs.graph-it.com/graphit/controlpi-graph", + packages=["controlpi_plugins"], + install_requires=[ + "controlpi @ git+git://git.graph-it.com/graphit/controlpi.git", + ], + classifiers=[ + "Programming Language :: Python", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], +) -- 2.34.1