Skip to content

Instantly share code, notes, and snippets.

def main():
#main loop
#....
if irc_line is a message:
sawMessage(channel, user, message)
#....
def pluginExists(self, pluginName):
if os.path.exists(pluginName.replace(".", os.sep)+".py"):
f = __import__("plugins."+pluginName.split(".")[0], fromlist=[pluginName.split(".")[1]])
try:
getattr(f, pluginName.split(".")[1])
del f
del sys.modules["plugins."+pluginName.split(".")[0]]
return True
except AttributeError:
del f
Test Summary Report
-------------------
t/00bootstrap.t (Wstat: 512 Tests: 2 Failed: 2)
Failed tests: 1-2
Non-zero exit status: 2
t/connect.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
Files=2, Tests=2, 1 wallclock secs ( 0.08 usr 0.03 sys + 0.30 cusr 0.03 csys = 0.44 CPU)
Result: FAIL
@FurryHead
FurryHead / gist:1010639
Created June 6, 2011 16:56
Load list of classes from each module in a package, using exocet
import exocet
import inspect
PluginList = { }
modules = [m for m in exocet.getModule("plugins").iterModules()]
for module in modules:
m = module.load()
for name, obj in inspect.getmembers(m):
if inspect.isclass(obj):
@FurryHead
FurryHead / gist:1010770
Created June 6, 2011 18:24
Module to load all classes from modules located in package "plugins"
import exocet
import inspect
_ClassList = { }
def refresh(moduleName=None):
if moduleName is None:
_ClassList.clear()
modules = [m for m in exocet.getModule("plugins").iterModules()]
for module in modules:
m = module.load()
code_environment = load_some_code(string_or_file_or_code_object);
classObject = code_environment.SomeClass(args);
.... do stuff with classObject
code_environment = load_some_code(string);
classObject = code_environment.SomeClass(args);
@FurryHead
FurryHead / __init__.py
Created June 7, 2011 20:52
Creates a list of all plugins
import os, inspect
pList = { }
mList = { }
def plugin(cls):
try:
mList[inspect.stack()[1][1].split(os.sep)[1]].append(cls.__name__)
except KeyError:
mList[inspect.stack()[1][1].split(os.sep)[1]] = []
@FurryHead
FurryHead / __init__.py
Created June 7, 2011 21:25
New plugin loader
import os, inspect
pList = { }
mList = defaultdict(list)
def plugin(cls):
#Using inspect, figure out what file is calling this function (using @plugin)
clsFile = inspect.stack()[1][1]
#Split the path, because it will be in the form "plugins" + os.sep + "*.py"
@FurryHead
FurryHead / __init__.py
Created June 7, 2011 22:36
New plugin loader
import os, inspect, collections
pList = { }
mList = collections.defaultdict(list)
class NoSuchPluginError(Exception): pass
def plugin(cls):
#Using inspect, figure out what file is calling this function (using @plugin)
clsFile = inspect.stack()[1][1]
@FurryHead
FurryHead / moduleloader.py
Created June 8, 2011 18:58
Module loader, to replace (somewhat) python's import. Does not work on .pyc - it's mainly for user files.
import os, sys, new
modules = { }
def loadModule(moduleName, locals_dict={}):
"""
Imports a module without using the built-in import functions.
Parameters:
moduleName - The name of the module, same as if you were using __import__ or import