From bd0a175dfcae1585529cb869be3b60528c473019 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Fri, 20 Apr 2018 22:04:03 -0700 Subject: [PATCH] Improve first-run and add default plugins --- onionr/default-plugins/pluginmanager/main.py | 35 ++++++++++++++++++++ onionr/gui.py | 4 ++- onionr/onionr.py | 24 ++++++++++++-- onionr/onionrpluginapi.py | 5 ++- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 onionr/default-plugins/pluginmanager/main.py diff --git a/onionr/default-plugins/pluginmanager/main.py b/onionr/default-plugins/pluginmanager/main.py new file mode 100644 index 00000000..115ae56f --- /dev/null +++ b/onionr/default-plugins/pluginmanager/main.py @@ -0,0 +1,35 @@ +''' + This is the future Onionr plugin manager. TODO: Add better description. +''' + +# useful libraries +import logger, config + +# useful functions + +def installPlugin(): + logger.info('This feature has not been created yet. Please check back later.') + return + +def uninstallPlugin(): + logger.info('This feature has not been created yet. Please check back later.') + return + +def searchPlugin(): + logger.info('This feature has not been created yet. Please check back later.') + return + +# event listeners + +def on_init(api, data = None): + global pluginapi + pluginapi = api + + # register some commands + api.commands.register(['install-plugin', 'installplugin', 'plugin-install', 'install', 'plugininstall'], installPlugin) + api.commands.register(['remove-plugin', 'removeplugin', 'plugin-remove', 'uninstall-plugin', 'uninstallplugin', 'plugin-uninstall', 'uninstall', 'remove', 'pluginremove'], uninstallPlugin) + api.commands.register(['search', 'filter-plugins', 'search-plugins', 'searchplugins', 'search-plugin', 'searchplugin', 'findplugin', 'find-plugin', 'filterplugin', 'plugin-search', 'pluginsearch'], searchPlugin) + + # add help menus once the features are actually implemented + + return diff --git a/onionr/gui.py b/onionr/gui.py index 89ba604c..644ae5c2 100755 --- a/onionr/gui.py +++ b/onionr/gui.py @@ -14,8 +14,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' + from tkinter import * import os, sqlite3, core + class OnionrGUI: def __init__(self, myCore): self.root = Tk() @@ -71,7 +73,7 @@ class OnionrGUI: scrollbar.config(command=self.listbox.yview) self.root.after(2000, self.update) - self.root.mainloop() + self.root.mainloop() def sendMessage(self): messageToAdd = '-txt-' + self.sendEntry.get() diff --git a/onionr/onionr.py b/onionr/onionr.py index bcd71849..321904c8 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' + import sys, os, base64, random, getpass, shutil, subprocess, requests, time, platform, datetime, re import api, core, config, logger, onionrplugins as plugins, onionrevents as events from onionrutils import OnionrUtils @@ -54,8 +55,15 @@ class Onionr: # Load global configuration data + data_exists = os.path.exists('data/') + + if not data_exists: + os.mkdir('data/') + exists = os.path.exists(config.get_config_file()) config.set_config({'devmode': True, 'log': {'file': {'output': True, 'path': 'data/output.log'}, 'console': {'output': True, 'color': True}}}) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it + if not exists: + config.save() config.reload() # this will read the configuration file into memory settings = 0b000 @@ -92,9 +100,19 @@ class Onionr: else: logger.error('Failed to decrypt: ' + result[1], timestamp = False) else: - if not os.path.exists('data/'): - os.mkdir('data/') - os.mkdir('data/blocks/') + # If data folder does not exist + if not data_exists: + if not os.path.exists('data/blocks/'): + os.mkdir('data/blocks/') + + # Copy default plugins into plugins folder + if os.path.exists('default-plugins/'): + names = [f for f in os.listdir("default-plugins/") if not os.path.isfile(f)] + shutil.copytree('default-plugins/', 'data/plugins/') + + # Enable plugins + for name in names: + plugins.enable(name, self) if not os.path.exists(self.onionrCore.peerDB): self.onionrCore.createPeerDB() diff --git a/onionr/onionrpluginapi.py b/onionr/onionrpluginapi.py index c6d68f31..3989a2bb 100644 --- a/onionr/onionrpluginapi.py +++ b/onionr/onionrpluginapi.py @@ -66,11 +66,14 @@ class PluginAPI: def disable(self, name): plugins.disable(name) + def event(self, name, data = {}): + events.event(name, data = data, onionr = self.pluginapi.get_onionr()) + def is_enabled(self, name): return plugins.is_enabled(name) def get_enabled_plugins(self): - return plugins.get_enabled_plugins() + return plugins.get_enabled() class CommandAPI: def __init__(self, pluginapi):