From 2c9836c54f5ad9a146ad6c245fce0d468e74daac Mon Sep 17 00:00:00 2001 From: Kevin F Date: Fri, 16 Sep 2022 23:33:39 -0500 Subject: [PATCH] Added REPL plugin --- static-data/default-plugins/repl/.env | 1 + static-data/default-plugins/repl/info.json | 4 ++ static-data/default-plugins/repl/main.py | 57 ++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 static-data/default-plugins/repl/.env create mode 100644 static-data/default-plugins/repl/info.json create mode 100644 static-data/default-plugins/repl/main.py diff --git a/static-data/default-plugins/repl/.env b/static-data/default-plugins/repl/.env new file mode 100644 index 00000000..27a4c0d2 --- /dev/null +++ b/static-data/default-plugins/repl/.env @@ -0,0 +1 @@ +PYTHONPATH=./venv/bin/python310:../../src/:./ \ No newline at end of file diff --git a/static-data/default-plugins/repl/info.json b/static-data/default-plugins/repl/info.json new file mode 100644 index 00000000..7e63c5b4 --- /dev/null +++ b/static-data/default-plugins/repl/info.json @@ -0,0 +1,4 @@ +{ "name": "repl", + "version": "0.0.0", + "author": "onionr" + } \ No newline at end of file diff --git a/static-data/default-plugins/repl/main.py b/static-data/default-plugins/repl/main.py new file mode 100644 index 00000000..017a612d --- /dev/null +++ b/static-data/default-plugins/repl/main.py @@ -0,0 +1,57 @@ +"""Onionr - Private P2P Communication. + +read-eval-print-loop plugin for Onionr +""" + +import locale + + +locale.setlocale(locale.LC_ALL, '') + +import sys +import os +import readline +import rlcompleter +readline.parse_and_bind("tab: complete") + +# locals for the repl +from gossip.peerset import gossip_peer_set + +from code import InteractiveConsole +sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) +# import after path insert + +""" +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + + +plugin_name = 'repl' +PLUGIN_VERSION = '0.0.0' + +def on_primary_loop(event_name, data): + """Run a REPL on the primary loop""" + header = """You are now in the Onionr REPL. Type 'exit()' to exit. + +Enter repl_locals to see the (default) special locals available to you. +""" + footer = "Exiting Onionr REPL." + repl_locals = { + 'gossip_peer_set': gossip_peer_set, + } + + InteractiveConsole( + repl_locals | {"repl_locals": repl_locals}).interact(header, footer) + raise KeyboardInterrupt +