From 50a8e8958ac46ed913f95d6e506d43ae19da8d07 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 20 Jul 2019 19:29:08 -0500 Subject: [PATCH] progress in removing core --- onionr/apiservers/private/__init__.py | 2 ++ onionr/httpapi/miscclientapi/endpoints.py | 4 +++- onionr/onionr.py | 5 ++--- onionr/onionrevents.py | 4 +--- onionr/onionrpluginapi.py | 2 -- onionr/static-data/default-plugins/pms/loadinbox.py | 8 +++++--- onionr/static-data/default-plugins/pms/mailapi.py | 12 ++++++------ onionr/static-data/default-plugins/pms/main.py | 12 ++++-------- onionr/static-data/default-plugins/pms/sentboxdb.py | 8 +++----- 9 files changed, 26 insertions(+), 31 deletions(-) diff --git a/onionr/apiservers/private/__init__.py b/onionr/apiservers/private/__init__.py index e15a133e..7c696373 100644 --- a/onionr/apiservers/private/__init__.py +++ b/onionr/apiservers/private/__init__.py @@ -23,6 +23,7 @@ from gevent.pywsgi import WSGIServer from onionrutils import epoch import httpapi, filepaths, logger from . import register_private_blueprints +import serializeddata class PrivateAPI: ''' Client HTTP api @@ -40,6 +41,7 @@ class PrivateAPI: config = onionrInst.config self.config = config self.debug = debug + self.serializer = serializeddata.SerializedData(onionrInst) self.startTime = epoch.get_epoch() app = flask.Flask(__name__) bindPort = int(config.get('client.client.port', 59496)) diff --git a/onionr/httpapi/miscclientapi/endpoints.py b/onionr/httpapi/miscclientapi/endpoints.py index 0aaaa994..f0c86204 100644 --- a/onionr/httpapi/miscclientapi/endpoints.py +++ b/onionr/httpapi/miscclientapi/endpoints.py @@ -19,6 +19,8 @@ ''' from flask import Response, Blueprint, request, send_from_directory, abort from httpapi import apiutils +import onionrcrypto +pub_key = onionrcrypto.pub_key class PrivateEndpoints: def __init__(self, client_api): private_endpoints_bp = Blueprint('privateendpoints', __name__) @@ -105,7 +107,7 @@ class PrivateEndpoints: @private_endpoints_bp.route('/getActivePubkey') def getActivePubkey(): - return Response(onionrcrypto.OnionrCrypto().pubKey) + return Response(pub_key) @private_endpoints_bp.route('/getHumanReadable/') def getHumanReadable(name): diff --git a/onionr/onionr.py b/onionr/onionr.py index 62dc2fda..d2d04514 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -236,7 +236,7 @@ class Onionr: commands.onionrstatistics.show_peers(self) def listPeers(self): - logger.info('Peer transport address list:') + logger.info('Peer transport address list:', terminal=True) for i in keydb.listkeys.list_adders(): logger.info(i, terminal=True) @@ -354,8 +354,7 @@ class Onionr: ''' Displays a message suggesting help ''' - if __name__ == '__main__': - logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.', terminal=True) + logger.info('Do ' + logger.colors.bold + sys.argv[0] + ' --help' + logger.colors.reset + logger.colors.fg.green + ' for Onionr help.', terminal=True) def start(self, input = False, override = False): ''' diff --git a/onionr/onionrevents.py b/onionr/onionrevents.py index f8d16653..66e596be 100755 --- a/onionr/onionrevents.py +++ b/onionr/onionrevents.py @@ -39,7 +39,6 @@ def __event_caller(event_name, data = {}, onionr = None): logger.warn('Event "%s" failed for plugin "%s".' % (event_name, plugin), terminal=True) logger.debug(str(e), terminal=True) - def event(event_name, data = {}, onionr = None, threaded = True): ''' Calls an event on all plugins (if defined) @@ -62,12 +61,11 @@ def call(plugin, event_name, data = None, pluginapi = None): attribute = 'on_' + str(event_name).lower() if hasattr(plugin, attribute): - #logger.debug('Calling event ' + str(event_name)) getattr(plugin, attribute)(pluginapi, data) return True except Exception as e: - logger.error(str(e)) + logger.error(str(e), terminal=True) return False else: return True diff --git a/onionr/onionrpluginapi.py b/onionr/onionrpluginapi.py index f5731e69..0ebabda1 100755 --- a/onionr/onionrpluginapi.py +++ b/onionr/onionrpluginapi.py @@ -92,8 +92,6 @@ class CommandAPI: for name in names: self.pluginapi.get_onionr().addCommand(name, call) - return - def unregister(self, names): if isinstance(names, str): names = [names] diff --git a/onionr/static-data/default-plugins/pms/loadinbox.py b/onionr/static-data/default-plugins/pms/loadinbox.py index 28ac36cf..ca49ea25 100755 --- a/onionr/static-data/default-plugins/pms/loadinbox.py +++ b/onionr/static-data/default-plugins/pms/loadinbox.py @@ -19,14 +19,16 @@ ''' import onionrblockapi from coredb import blockmetadb -def load_inbox(myCore): +import filepaths +import deadsimplekv as simplekv +def load_inbox(): inbox_list = [] - deleted = myCore.keyStore.get('deleted_mail') + deleted = simplekv.DeadSimpleKV(filepaths.cached_storage).get('deleted_mail') if deleted is None: deleted = [] for blockHash in blockmetadb.get_blocks_by_type('pm'): - block = onionrblockapi.Block(blockHash, core=myCore) + block = onionrblockapi.Block(blockHash) block.decrypt() if block.decrypted and blockHash not in deleted: inbox_list.append(blockHash) diff --git a/onionr/static-data/default-plugins/pms/mailapi.py b/onionr/static-data/default-plugins/pms/mailapi.py index 922432a0..fd3c8ee7 100755 --- a/onionr/static-data/default-plugins/pms/mailapi.py +++ b/onionr/static-data/default-plugins/pms/mailapi.py @@ -19,15 +19,15 @@ ''' import sys, os, json from flask import Response, request, redirect, Blueprint, abort -import core from onionrusers import contactmanager from onionrutils import stringvalidators +import filepaths +import deadsimplekv as simplekv sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import loadinbox, sentboxdb flask_blueprint = Blueprint('mail', __name__) -c = core.Core() -kv = c.keyStore +kv = simplekv.DeadSimpleKV(filepaths.cached_storage) @flask_blueprint.route('/mail/ping') def mail_ping(): @@ -48,12 +48,12 @@ def mail_delete(block): @flask_blueprint.route('/mail/getinbox') def list_inbox(): - return ','.join(loadinbox.load_inbox(c)) + return ','.join(loadinbox.load_inbox()) @flask_blueprint.route('/mail/getsentbox') def list_sentbox(): kv.refresh() - sentbox_list = sentboxdb.SentBox(c).listSent() + sentbox_list = sentboxdb.SentBox().listSent() list_copy = list(sentbox_list) deleted = kv.get('deleted_mail') if deleted is None: @@ -62,5 +62,5 @@ def list_sentbox(): if x['hash'] in deleted: sentbox_list.remove(x) continue - x['name'] = contactmanager.ContactManager(c, x['peer'], saveUser=False).get_info('name') + x['name'] = contactmanager.ContactManager(x['peer'], saveUser=False).get_info('name') return json.dumps(sentbox_list) diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index 0e01fa34..523c7d39 100755 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -25,7 +25,6 @@ import onionrexceptions from onionrusers import onionrusers from onionrutils import stringvalidators, escapeansi, bytesconverter import locale, sys, os, json -from coredb import blockmetadb locale.setlocale(locale.LC_ALL, '') @@ -35,7 +34,7 @@ PLUGIN_VERSION = '0.0.1' sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import sentboxdb, mailapi, loadinbox # import after path insert flask_blueprint = mailapi.flask_blueprint - +""" def draw_border(text): # This function taken from https://stackoverflow.com/a/20757491 by https://stackoverflow.com/users/816449/bunyk, under https://creativecommons.org/licenses/by-sa/3.0/ lines = text.splitlines() @@ -62,10 +61,9 @@ class MailStrings: class OnionrMail: def __init__(self, pluginapi): - self.myCore = pluginapi.get_core() self.strings = MailStrings(self) - self.sentboxTools = sentboxdb.SentBox(self.myCore) + self.sentboxTools = sentboxdb.SentBox() self.sentboxList = [] self.sentMessages = {} self.doSigs = True @@ -293,7 +291,7 @@ class OnionrMail: pass else: logger.warn('Invalid choice.', terminal=True) - return + return """ def add_deleted(keyStore, bHash): existing = keyStore.get('deleted_mail') @@ -318,7 +316,5 @@ def on_init(api, data = None): ''' pluginapi = api - mail = OnionrMail(pluginapi) - api.commands.register(['mail'], mail.menu) - api.commands.register_help('mail', 'Interact with OnionrMail') + return diff --git a/onionr/static-data/default-plugins/pms/sentboxdb.py b/onionr/static-data/default-plugins/pms/sentboxdb.py index f5a56272..28d2ab5d 100755 --- a/onionr/static-data/default-plugins/pms/sentboxdb.py +++ b/onionr/static-data/default-plugins/pms/sentboxdb.py @@ -18,15 +18,13 @@ along with this program. If not, see . ''' import sqlite3, os -import core from onionrutils import epoch +from utils import identifyhome class SentBox: - def __init__(self, mycore): - assert isinstance(mycore, core.Core) - self.dbLocation = mycore.dataDir + 'sentbox.db' + def __init__(self): + self.dbLocation = identifyhome.identify_home() + '/sentbox.db' if not os.path.exists(self.dbLocation): self.createDB() - self.core = mycore return def connect(self):