test
This commit is contained in:
parent
fd73177035
commit
8d5ac44fee
@ -6,19 +6,17 @@ from .logger import Logger
|
||||
|
||||
class SpiceBotCore_OBJ():
|
||||
|
||||
def __init__(self):
|
||||
self.script_dir = None
|
||||
self.increment = 1
|
||||
self.bot = None
|
||||
def __init__(self, script_dir):
|
||||
|
||||
self.config = None
|
||||
self.versions = None
|
||||
self.logger = None
|
||||
|
||||
def setup(self, script_dir, bot):
|
||||
# Set directory for the plugin
|
||||
self.script_dir = script_dir
|
||||
self.bot = bot
|
||||
|
||||
self.config = Config(script_dir, bot)
|
||||
self.logger = Logger(self.config)
|
||||
self.versions = Versions(self.config, self.logger)
|
||||
# Allow SpiceBot to interact with Sopel Logger
|
||||
self.logger = Logger()
|
||||
|
||||
# Parse Version Information for the ENV
|
||||
self.versions = Versions(self.logger)
|
||||
|
||||
# def setup(self, script_dir, bot):
|
||||
# self.bot = bot
|
||||
# self.config = Config(script_dir, bot)
|
||||
|
||||
@ -1,3 +1,10 @@
|
||||
# coding=utf8
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
from sopel.cli.run import build_parser, get_configuration
|
||||
|
||||
|
||||
class Config():
|
||||
@ -10,16 +17,44 @@ class Config():
|
||||
|
||||
self.core_setup()
|
||||
|
||||
def core_setup(self):
|
||||
self.dict = {}
|
||||
|
||||
self.internal["paths"] = {
|
||||
"script_dir": self.script_dir
|
||||
}
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""
|
||||
Quick and dirty shortcuts. Will only get called for undefined attributes.
|
||||
"""
|
||||
# opts input
|
||||
self.opts = self.get_opts()
|
||||
|
||||
if hasattr(self.bot.config, name):
|
||||
return eval("self.bot.config.%s" % name)
|
||||
# Load config
|
||||
self.config = get_configuration(self.opts)
|
||||
|
||||
self.setup_config()
|
||||
|
||||
def setup_config(self):
|
||||
self.config.core.basename = os.path.basename(self.config.filename).rsplit('.', 1)[0]
|
||||
self.config.core.prefix_list = str(self.config.core.prefix).replace("\\", '').split("|")
|
||||
|
||||
def define_section(self, name, cls_, validate=True):
|
||||
return self.config.define_section(name, cls_, validate)
|
||||
|
||||
def get_opts(self):
|
||||
parser = build_parser()
|
||||
if not len(sys.argv[1:]):
|
||||
argv = ['legacy']
|
||||
else:
|
||||
argv = sys.argv[1:]
|
||||
return parser.parse_args(argv)
|
||||
|
||||
def __getattr__(self, name):
|
||||
''' will only get called for undefined attributes '''
|
||||
"""We will try to find a core value, or return None"""
|
||||
|
||||
if hasattr(self.config.core, name):
|
||||
return eval("self.config.core." + name)
|
||||
|
||||
elif hasattr(self.config, name):
|
||||
return eval("self.config." + name)
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -3,8 +3,7 @@ from sopel import tools
|
||||
|
||||
class Logger():
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
def __init__(self):
|
||||
self.logger = tools.get_logger('SpiceBot')
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
||||
@ -8,8 +8,7 @@ import re
|
||||
|
||||
class Versions():
|
||||
|
||||
def __init__(self, config, logger):
|
||||
self.config = config
|
||||
def __init__(self, logger):
|
||||
self.logger = logger
|
||||
|
||||
self.dict = {}
|
||||
@ -42,8 +41,7 @@ class Versions():
|
||||
Register core version items.
|
||||
"""
|
||||
|
||||
script_dir = self.config.internal["paths"]["script_dir"]
|
||||
version_file = pathlib.Path(script_dir).joinpath("version.json")
|
||||
version_file = pathlib.Path(self.script_dir).joinpath("version.json")
|
||||
with open(version_file, 'r') as jsonversion:
|
||||
versions = json.load(jsonversion)
|
||||
|
||||
|
||||
@ -10,13 +10,14 @@ import pathlib
|
||||
from sopel import plugin
|
||||
|
||||
from .SpiceBotCore import SpiceBotCore_OBJ
|
||||
sbcore = SpiceBotCore_OBJ()
|
||||
|
||||
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
sbcore = SpiceBotCore_OBJ(SCRIPT_DIR)
|
||||
|
||||
def setup(bot):
|
||||
sbcore.setup(SCRIPT_DIR, bot)
|
||||
|
||||
# def setup(bot):
|
||||
# sbcore.setup(bot)
|
||||
|
||||
|
||||
@plugin.nickname_command('test')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user