progress in removing core

This commit is contained in:
Kevin Froman 2019-07-20 19:29:08 -05:00
parent f843ccc3b2
commit 50a8e8958a
9 changed files with 26 additions and 31 deletions

View File

@ -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))

View File

@ -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/<name>')
def getHumanReadable(name):

View File

@ -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):
'''

View File

@ -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

View File

@ -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]

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -18,15 +18,13 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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):