Beispiel #1
0
def load(parent, modname):
    if not isloaded(modname):
        mod = __import__(modname)
        reload(mod)

        if not hasattr(mod, 'modinfo'):
            return modlib.error('no modinfo')

        if parent.APIVERSION not in mod.modinfo['compatible']:
            return modlib.error('API-incompatible')

        modules[modname] = mod
        dependents[modname] = []

        for dep in mod.modinfo['depends']:
            if dep not in modules:
                depret = load(parent, dep)
                if not depret:
                    return
            dependents[dep].append(modname)

        ret = mod.modstart(parent)
        if ret is not None and not ret:
            del modules[modname]
            del dependents[modname]
            for dep in mod.modinfo['depends']:
                dependents[dep].remove(modname)
        return ret
    else:  #if not isloaded...else:
        return modlib.error('already loaded')
Beispiel #2
0
def load(parent, modname):
	if not isloaded(modname):
		mod = __import__(modname)
		reload(mod)

		if not hasattr(mod, 'modinfo'):
			return modlib.error('no modinfo')

		if parent.APIVERSION not in mod.modinfo['compatible']:
			return modlib.error('API-incompatible')

		modules[modname] = mod
		dependents[modname] = []

		for dep in mod.modinfo['depends']:
			if dep not in modules:
				depret = load(parent, dep)
				if not depret:
					return
			dependents[dep].append(modname)


		ret = mod.modstart(parent)
		if ret is not None and not ret:
			del modules[modname]
			del dependents[modname]
			for dep in mod.modinfo['depends']:
				dependents[dep].remove(modname)
		return ret
	else: #if not isloaded...else:
		return modlib.error('already loaded')
Beispiel #3
0
def unload(parent, modname):
	if isloaded(modname):
		for dependent in dependents[modname]:
			unload(parent, dependent)
		for dep in modules[modname].modinfo['depends']:
			dependents[dep].remove(modname)
		ret = modules[modname].modstop(parent)
		del modules[modname]
		return ret
	else:
		return modlib.error('already unloaded')
Beispiel #4
0
def unload(parent, modname):
    if isloaded(modname):
        for dependent in dependents[modname]:
            unload(parent, dependent)
        for dep in dependents[modname]:
            dependents[dep].remove(modname)
        ret = modules[modname].modstop(parent)
        del modules[modname]
        return ret
    else:
        return modlib.error('already unloaded')
Beispiel #5
0
def reloadmod(parent, modname):
	if isloaded(modname):
		if modhas(modname, 'modrestart'): modules[modname].modrestart(parent)
		else: modules[modname].modstop(parent)

		try:
			reload(modules[modname])
		except BaseException as e:
			return modlib.error(e)

		if modhas(modname, 'modrestarted'): ret = modules[modname].modrestarted(parent)
		else: ret = modules[modname].modstart(parent)

		return ret
	else:
		return load(parent, modname)
Beispiel #6
0
def _load(parent, modname, dependent=False):
	"""Load and return the new status of the module."""
	successstatus = []
	if not isloaded(modname):
		importlib.invalidate_caches()
		try:
			mod = importlib.import_module('modules.'+modname)
			reload(mod) #in case it's been previously loaded.
		except Exception as e:
			return modlib.error(e)


		if not hasattr(mod, 'modinfo'):
			return modlib.error('no modinfo')

		if parent.APIVERSION not in mod.modinfo['compatible']:
			return modlib.error('API-incompatible')

		modules[modname] = mod
		dependents[modname] = []

		for dep in mod.modinfo['depends']:
			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 None:
			ret = True
		if not ret:
			del modules[modname]
			del dependents[modname]
			for dep in mod.modinfo['depends']:
				dependents[dep].remove(modname)

		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')