icsemantic.catalog.setuphandlers

Package platecom :: Package ontocatalog :: Module setuphandlers |
[hide private]
[frames] | no frames]

# Source Code for Module icsemantic.catalog.setuphandlers

     1  """This module handles the product install process.
     2  """
     3
     4  import logging
     5  logger = logging.getLogger('icsemantic.catalog: setuphandlers')
     6
     7  import transaction
     8
     9  from Products.CMFCore.utils import getToolByName
    10
    11  from platecom.ontocatalog.config import PROJECTNAME, DEPENDENCIES
    12  from platecom.ontocatalog.config import RELATED_IDX
    13  from platecom.ontocatalog.config import SYNONYM_IDX
    14  from platecom.ontocatalog.config import TRANSLATION_IDX
    15
    16
    17 -def is_icsemantic.catalog_profile(context):
    18      """Ordinarily, GenericSetup handlers check for the existence of
    19      XML files. Here, we are not parsing an XML file, but we use this
    20      text file as a flag to check that we actually meant for this import
    21      step to be run. The file is found in profiles/default.
    22      """
    23      return context.readDataFile("icsemantic.catalog_marker.txt") is not None
    24
    25
    26 -def add_indexes(context):
    27      """Add fake catalog indexes for synonyms, translations and
    28      relations.
    29      """
    30      catalog = getToolByName(context.getSite(), 'portal_catalog')
    31      if not SYNONYM_IDX in catalog.indexes():
    32          catalog.manage_addIndex(SYNONYM_IDX, 'SynonymIndex')
    33
    34      if not TRANSLATION_IDX in catalog.indexes():
    35          catalog.manage_addIndex(TRANSLATION_IDX, 'TranslationIndex')
    36
    37      if not RELATED_IDX in catalog.indexes():
    38          catalog.manage_addIndex(RELATED_IDX, 'RelatedIndex')
    39
    40
    41 -def update_portal_atct(context):
    42      """Update ATCT tool with criteria for synonyms, translations and
    43      relations.
    44      """
    45      atct_tool = getToolByName(context.getSite(), 'portal_atct')
    46      atct_tool.addIndex(SYNONYM_IDX, friendlyName='Synonyms', enabled=1)
    47      atct_tool.addIndex(TRANSLATION_IDX, friendlyName='Translations', enabled=1)
    48      atct_tool.addIndex(RELATED_IDX, friendlyName='Relations', enabled=1)
    49
    50
    51 -def install_dependencies(context):
    52      """Install dependencies"""
    53      quickinstaller = getToolByName(context.getSite(), 'portal_quickinstaller')
    54      for product in DEPENDENCIES:
    55          if quickinstaller.isProductInstalled(product):
    56              quickinstaller.reinstallProducts([product])
    57              transaction.savepoint()
    58          else:
    59              quickinstaller.installProduct(product)
    60              transaction.savepoint()
    61
    62
    63 -def setup_various(context):
    64      """Basically the install method"""
    65      if not is_icsemantic.catalog_profile(context):
    66          return
    67
    68      install_dependencies(context)
    69      add_indexes(context)
    70      update_portal_atct(context)
    71