Added REPL plugin

This commit is contained in:
Kevin F 2022-09-16 23:33:39 -05:00
parent a036c1839f
commit 2c9836c54f
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1 @@
PYTHONPATH=./venv/bin/python310:../../src/:./

View File

@ -0,0 +1,4 @@
{ "name": "repl",
"version": "0.0.0",
"author": "onionr"
}

View File

@ -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 <https://www.gnu.org/licenses/>.
"""
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