Alon Bar-Lev has uploaded a new change for review. Change subject: core: context: support 'before', 'after' in sequence ......................................................................
core: context: support 'before', 'after' in sequence Change-Id: Id560d4aac9052379442c43672d87153b2cb4aefa Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M README.API M src/otopi/context.py M src/otopi/plugin.py 3 files changed, 50 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/78/11778/1 diff --git a/README.API b/README.API index 9b2d6ea..cb74ee5 100644 --- a/README.API +++ b/README.API @@ -20,8 +20,8 @@ variable. Plugins entries are loaded and sorted by Stages, and within each -stage by priority. Then entries are called one by one by their -order. +stage by priority, order by before and after hints. Then entries +are called one by one by their order. Plugin class inherit from PluginBase and uses @plugin.event decoration in order to declare entry points (see example bellow). diff --git a/src/otopi/context.py b/src/otopi/context.py index 2f7418a..1079544 100644 --- a/src/otopi/context.py +++ b/src/otopi/context.py @@ -273,6 +273,43 @@ # tmplist.sort(key=operator.itemgetter('priority')) + # + # Handle before and after + # KISS mode + # + def _doit(l, what, op, offset): + def _indexOfName(names): + try: + return min( + i for i, data in enumerate(l) + if data['name'] in names + ) + except ValueError: + return None + + for limit in range(400): # boundary + modified = False + for index, metadata in enumerate(l): + candidateindex = _indexOfName(metadata[what]) + if ( + candidateindex is not None and + op(candidateindex, index) + ): + l.insert(candidateindex+offset, metadata) + if candidateindex < index: + del l[index+1] + else: + del l[index] + modified = True + break + if not modified: + break + if modified: + raise RuntimeError(_('Sequence build loop detected')) + + _doit(tmplist, 'before', operator.lt, 0) + _doit(tmplist, 'after', operator.gt, 1) + sequence = {} for m in tmplist: sequence.setdefault(m['stage'], []).append(m) @@ -343,8 +380,9 @@ self.logger.debug('STAGE %s', plugin.Stages.stage_id(stage)) for methodinfo in methodinfos: self.logger.debug( - ' METHOD %s', + ' METHOD %s (%s)', self._methodName(methodinfo), + methodinfo['name'], ) self.logger.debug('SEQUENCE DUMP - END') diff --git a/src/otopi/plugin.py b/src/otopi/plugin.py index fc6c509..d1a5c17 100644 --- a/src/otopi/plugin.py +++ b/src/otopi/plugin.py @@ -214,14 +214,20 @@ @util.export def event( + name=None, stage=None, + before=[], + after=[], priority=Stages.PRIORITY_DEFAULT, condition=None, ): """Decoration to specify sequence event method. Keyword arguments: + name -- name of stage. stage -- stage out of Stages.STAGE_*. + before -- place before plugin. + after -- place after plugin. priority -- priority out of Stages.PRIORITY_*. condition -- optional condition function. @@ -229,7 +235,10 @@ def decorator(f): f.decoration_event = { 'method': f, + 'name': name, 'stage': stage, + 'before': before, + 'after': after, 'priority': priority, 'condition': ( condition if condition is not None -- To view, visit http://gerrit.ovirt.org/11778 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id560d4aac9052379442c43672d87153b2cb4aefa Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches