]> jfr.im git - erebus.git/commitdiff
added softdeps to modinfo - bumped APIVERSION
authorzonidjan <redacted>
Sun, 3 Sep 2017 00:55:36 +0000 (19:55 -0500)
committerzonidjan <redacted>
Sun, 3 Sep 2017 00:55:36 +0000 (19:55 -0500)
APIVERSION is now 2. modules written for 2 are compatible with 1;
however modules written for 1 need to be updated (by adding softdeps
to modinfo).

softdeps are loaded before the current module is started, when possible.
however, if they are disabled (by setting them to 0 in config
"[autoloads]"), or non-existent, they will be ignored. Additionally, if
they are unloaded at runtime any modules with softdeps on them will
continue to be loaded and are expected to not raise any errors.

13 files changed:
ctlmod.py
erebus.py
modlib.py
modules/coins.py
modules/control.py
modules/eval.py
modules/foo.py
modules/help.py
modules/resources.py
modules/sms.py
modules/trivia.py
modules/urls.py
modules/userinfo.py

index be1095fd7e983dc824c2c92255f530740ead0d0c..dbd2a36bdf5185a9935ea8115b85ea035ddc0d29 100644 (file)
--- a/ctlmod.py
+++ b/ctlmod.py
@@ -19,17 +19,24 @@ def load(parent, modname, dependent=False):
                print "%09.3f [MOD] [?] Loading %s..." % (time.time() % 100000, modname),
        modstatus = _load(parent, modname, dependent)
        if not modstatus:
-               print str(modstatus)
+               if dependent:
+                       print "failed: %s)" % (modstatus),
+               else:
+                       print "failed: %s." % (modstatus)
        elif modstatus == True:
                if dependent:
                        print "OK)",
                else:
                        print "OK."
        else:
-               print modstatus
+               if dependent:
+                       print "OK: %s)" % (modstatus),
+               else:
+                       print "OK: %s." % (modstatus)
        return modstatus
 
 def _load(parent, modname, dependent=False):
+       successstatus = []
        if not isloaded(modname):
                try:
                        mod = __import__('modules.'+modname, globals(), locals(), ['*'], -1)
@@ -49,20 +56,44 @@ def _load(parent, modname, dependent=False):
                dependents[modname] = []
 
                for dep in mod.modinfo['depends']:
-                       if dep not in modules:
-                               depret = load(parent, dep, dependent=True)
-                               if depret is not None and not depret:
-                                       return depret #TODO FIXME
+                       if bool(int(parent.cfg.get('autoloads', dep, default=1))):
+                               if dep not in modules:
+                                       depret = load(parent, dep, dependent=True)
+                                       if depret is not None and not depret:
+                                               return depret
+                       else:
+                               return modlib.error("dependent %s disabled" % (dep))
                        dependents[dep].append(modname)
 
+               for dep in mod.modinfo['softdeps']:
+                       if bool(int(parent.cfg.get('autoloads', dep, default=1))):
+                               if dep not in modules:
+                                       depret = load(parent, dep, dependent=True)
+                                       if depret is not None:
+                                               if not depret:
+                                                       successstatus.append("softdep %s failed" % (dep))
+                       else:
+                               successstatus.append("softdep %s disabled" % (dep))
+                       #swallow errors loading - softdeps are preferred, not required
+
 
                ret = mod.modstart(parent)
-               if ret is not None and not ret:
+               if ret is None:
+                       ret = True
+               if not ret:
                        del modules[modname]
                        del dependents[modname]
                        for dep in mod.modinfo['depends']:
                                dependents[dep].remove(modname)
-               return ret
+
+               successstatus = ';'.join(successstatus)
+               if len(successstatus) > 0 and ret:
+                       if ret == True:
+                               return successstatus
+                       else:
+                               return "%s (%s)" % (ret, successstatus)
+               else:
+                       return ret
        else: #if not isloaded...else:
                return modlib.error('already loaded')
 
index 190c4ba2301b0eeb39efe9cb83a7982717b8f150..713c384c433b6220c6d57247c6b8f8fde497041b 100644 (file)
--- a/erebus.py
+++ b/erebus.py
@@ -7,7 +7,7 @@ import os, sys, select, MySQLdb, MySQLdb.cursors, time, random
 import bot, config, ctlmod
 
 class Erebus(object): #singleton to pass around
-       APIVERSION = 1
+       APIVERSION = 2
        RELEASE = 0
 
        bots = {}
index 89a75d48d5193b7adf5d328e1384ca27c878242c..05ecf53ebe3d50fb0fbfaec8777ab0d92a551431 100644 (file)
--- a/modlib.py
+++ b/modlib.py
@@ -42,6 +42,13 @@ class modlib(object):
                self.name = (name.split("."))[-1]
 
        def modstart(self, parent):
+               #modstart can return a few things...
+               # None: unspecified success
+               # False: unspecified error
+               # modlib.error (or anything else False-y): specified error
+               # True: unspecified success
+               # non-empty string (or anything else True-y): specified success
+               #"specified" values will be printed. unspecified values will result in "OK" or "failed"
                self.parent = parent
                for cmd, func in self.hooks.iteritems():
                        self.parent.hook(cmd, func)
index 8548d60af728b0705fa76dc39ce075e0f9e543f8..5b3d663a34b090b2cbe60e97d409f695859cd0bf 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': [],
 }
 
 # preamble
index 74e0a66d4b1b54a6dc124d6f1941260dd0106909..572853d1264bee5bc7063f94b0a09a67a509122a 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1],
+       'compatible': [1,2],
        'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble
index 3e06472e5495ffe42e8d1e5a51751d2465bc9dc4..d2b82c83567e2005d5936e8d714b8139790b72d0 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1],
+       'compatible': [1,2],
        'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble
index 0278eb1ea6c00a72d17d2a55e2474e60d43d7309..bb56be0944e2b3f506bde9a299268b512c0c5a3b 100644 (file)
@@ -6,9 +6,15 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
+       'compatible': [1,2], # compatible module API versions
        'depends': [], # other modules required to work properly?
+       'softdeps': ['help'], # modules which are preferred but not required
 }
+# note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
+# however, if it is disabled it will be silently ignored, and if it is unloaded at runtime it won't cause this one to unload.
+#
+# basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
+# for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
 
 # preamble
 import modlib
index 299cf0a78298c930cc04b8749fbc47b8c95ac5d7..0010470b39549d5ef47b4a9d3d427ce7f7ce3809 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': [],
 }
 
 # preamble
index 35feebda569f3e5e64c9e1c1d6eed1947bf2cf08..016e4bdb85913ada2775615eff5f5b1becc4ffe0 100644 (file)
@@ -1,13 +1,14 @@
 # Erebus IRC bot - Author: Erebus Team
-# simple module example
+# resource-usage module
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble
index 3978ae21b5a978377daca5398acde2bec1ce29d5..16077a3244edd61c20b84f77b81d6df333571990 100644 (file)
@@ -1,13 +1,14 @@
 # Erebus IRC bot - Author: Erebus Team
-# simple module example
+# twilio sms module
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble
index 3eabbbc02097f60218daea0d1bdc8830dbde73f9..cb4b407bec7e718a66827de48344ade33b518522 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': ['userinfo'], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': ['userinfo'],
+       'softdeps': ['help'],
 }
 
 # preamble
index 3b418707dcd8d297e79284342a6f806cba9dec03..fc398e26913c87aa1d793ce05fed2467debb2467 100644 (file)
@@ -6,8 +6,9 @@
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': [],
 }
 
 # http://embed.ly/tools/generator
index fb0e111d4ecfddaff6476ad60a79d6e843f64c87..be6e33be11b2b0810f97d626084c82f86752bf2c 100644 (file)
@@ -1,13 +1,14 @@
 # Erebus IRC bot - Author: Erebus Team
-# trivia module
+# userinfo module
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
 modinfo = {
        'author': 'Erebus Team',
        'license': 'public domain',
-       'compatible': [1], # compatible module API versions
-       'depends': [], # other modules required to work properly?
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': ['help'],
 }
 
 # preamble