Coverage for modules/org/openteacher/logic/modules/modules : 98%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2011-2013, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
"""This module has two purposes: 1) selecting modules via its default() and sort() methods. 2) updating OT to self.profile (which should be set by a module other than this one, normally the execute module, before this module should be used by any module.)
Lowest (positive) priority: 1000
"""
self._mm.mods(type="event"), )
#return a negative priority to the sort algorithm so the #module gets on top of the list. The negative integer #needs to be a number, that makes sure the last #installed module is on the top of the list. This just #uses seconds since installation. #store so mtime is not requested repeatedly for the same #file.
"""Sorts the modules returned by self._mm.mods(*args, **kwargs) based on their priority in the current profile.
"""
"""Selects one of the modules returned by self._mm.mods(*args, **kwargs) based on their priority and the current profile OT's running in.
Raises IndexError if no modules remain after filtering with the arguments.
"""
#Enabling/disabling modules
"""Enable()s and disable()s modules until only modules that have a positive priority in the current profile remain. This takes into account dependencies: if a module depends on one that can't be enabled due to its priority in the current profile, that module isn't enabled either.
""" #build dependency tree by topological sorting #http://en.wikipedia.org/wiki/Topological_sort ; second algorithm
(potentialRequirement, dep_mod) for dep_mod in self._allMods for potentialRequirement in itertools.chain( self._depFor(dep_mod, "requires"), self._depFor(dep_mod, "uses") ) )
mod for mod in self._allMods if not ( getattr(mod, "requires", None) and getattr(mod, "uses", None) ) )
depMod for requirement, depMod in self._potentialRequirements if mod in requirement )
frozenset(dep) for dep in attribute )
#enable modules else:
any( getattr(depMod, "active", False) for depMod in selector ) for selector in getattr(mod, "requires", []) )
#disable modules logger.debug("Disabling %s" % mod) mod.disable()
|