Improve first-run and add default plugins

This commit is contained in:
Arinerron 2018-04-20 22:04:03 -07:00
parent 098abb8e55
commit bd0a175dfc
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
4 changed files with 63 additions and 5 deletions

View File

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

View File

@ -14,8 +14,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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()

View File

@ -20,6 +20,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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()

View File

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