Source code for

""" Handle details of tool tagging - perhaps a deprecated feature.
import logging
from abc import (

import six

log = logging.getLogger(__name__)

[docs]def tool_tag_manager(app): """ Build a tool tag manager according to app's configuration and return it. """ if hasattr(app.config, "get_bool") and app.config.get_bool('enable_tool_tags', False): return PersistentToolTagManager(app) else: return NullToolTagManager()
[docs]@six.add_metaclass(ABCMeta) class AbstractToolTagManager(object):
[docs] @abstractmethod def reset_tags(self): """ Starting to load tool panels, reset all tags. """
[docs] @abstractmethod def handle_tags(self, tool_id, tool_definition_source): """ Parse out tags and persist them. """
[docs]class NullToolTagManager(AbstractToolTagManager):
[docs] def reset_tags(self): return None
[docs] def handle_tags(self, tool_id, tool_definition_source): return None
[docs]class PersistentToolTagManager(AbstractToolTagManager): def __init__(self, app): = app self.sa_session = app.model.context
[docs] def reset_tags(self):"removing all tool tag associations (" + str(self.sa_session.query( + ")") self.sa_session.query( self.sa_session.flush()
[docs] def handle_tags(self, tool_id, tool_definition_source): elem = tool_definition_source if'enable_tool_tags', False): tag_names = elem.get("tags", "").split(",") for tag_name in tag_names: if tag_name == '': continue tag = self.sa_session.query( if not tag: tag = self.sa_session.add(tag) self.sa_session.flush() tta =, self.sa_session.add(tta) self.sa_session.flush() else: for tagged_tool in tag.tagged_tools: if tagged_tool.tool_id == tool_id: break else: tta =, self.sa_session.add(tta) self.sa_session.flush()