From 8973840bd12b86de5ff1b6588b46273b414ef984 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Thu, 15 Jun 2017 11:59:39 +0200 Subject: Remove plugin system; fix config loading --- pycrctrl/__pycache__/plugin.cpython-36.pyc | Bin 1583 -> 0 bytes pycrctrl/__pycache__/pycrctrl.cpython-36.pyc | Bin 20510 -> 0 bytes pycrctrl/plugin.py | 48 --------------------------- pycrctrl/pycrctrl.py | 12 ++----- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 pycrctrl/__pycache__/plugin.cpython-36.pyc delete mode 100644 pycrctrl/__pycache__/pycrctrl.cpython-36.pyc delete mode 100644 pycrctrl/plugin.py diff --git a/pycrctrl/__pycache__/plugin.cpython-36.pyc b/pycrctrl/__pycache__/plugin.cpython-36.pyc deleted file mode 100644 index 16ed639..0000000 Binary files a/pycrctrl/__pycache__/plugin.cpython-36.pyc and /dev/null differ diff --git a/pycrctrl/__pycache__/pycrctrl.cpython-36.pyc b/pycrctrl/__pycache__/pycrctrl.cpython-36.pyc deleted file mode 100644 index 1d536d6..0000000 Binary files a/pycrctrl/__pycache__/pycrctrl.cpython-36.pyc and /dev/null differ diff --git a/pycrctrl/plugin.py b/pycrctrl/plugin.py deleted file mode 100644 index d6a43c2..0000000 --- a/pycrctrl/plugin.py +++ /dev/null @@ -1,48 +0,0 @@ -import sys -import os -import os.path -import re - -import importlib.util - -if sys.version_info < (3,6): - class ModuleNotFoundError(ImportError): - pass - -class PluginError(Exception): - """There is an error when loading a PyCRCtrl plugin.""" - pass - -def loadPlugin(name : str, directories : list): - """Loads a plugin.""" - - if not isinstance(directories, list): - directories = [directories] - - found = None - for dir in directories: - if found == None: - if os.path.isdir(os.path.join(dir, name)) or os.path.isfile(os.path.join(dir, ("{}.py".format(name) if name[-3:] != ".py" else name))): - found = dir - else: - raise ImportError("Multiple modules named {} found!".format(name)) - - if found == None: - raise ModuleNotFoundError("Cannot find module {}".format(name)) from None - - spec = importlib.util.spec_from_file_location(name, os.path.join(dir, name)) - - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - - sys.modules[module.__name__] = module - return module - -def loadPluginClass(module): - try: - c = module.Class() - - except AttributeError: - raise PluginError("The plugin \"{}\" does not have a Class attribute".format(module.__name__)) from None - - return c \ No newline at end of file diff --git a/pycrctrl/pycrctrl.py b/pycrctrl/pycrctrl.py index 749989b..09692b9 100644 --- a/pycrctrl/pycrctrl.py +++ b/pycrctrl/pycrctrl.py @@ -31,8 +31,6 @@ import json import base64 import supybot.log import supybot.ircmsgs as ircmsgs -from . import plugin - from pickle import Pickler, Unpickler from PyQt5.QtCore import * from time import sleep @@ -247,7 +245,6 @@ class PyCRCtrl(object): _capa_old = {} updater = None - plugins = QList() def __init__(self, irc=None, path=None, config="pycrctrl.conf"): if sys.platform == "win32": @@ -263,12 +260,6 @@ class PyCRCtrl(object): self.queue = queue.Queue(5) if self.config["Clonk"]["Updater"]["enabled"]: self.updater = Updater(self) - - for p in os.listdir(os.path.join(self.path, "plugins")): - try: - self.plugins.append(plugins.loadPluginClass(plugins.loadPlugin(p, dir))) - except Exception: - pass def __ostream__(self, ostream): return "PyCRCtrl: commandline: {}, channel: {}, scenario: {}".format(self.commandline, self.config["Clonk"]["IRC"]["Channels"]["ingame"], (self.scenario if self.scenario != "" else "None")) @@ -327,7 +318,8 @@ class PyCRCtrl(object): return False elif os.path.isfile(conf): - self.config = json.load(open(conf, "r")) + self.config = self.setupConfig(json.load(open(conf, "r"))) + return True elif not os.path.exists(conf): c = { -- cgit v1.2.3-54-g00ecf