Пример #1
0
 def _add_pt(self, template):
     if hasattr(self.aq_explicit, _script_id):
         return
     
     name, extension = os.path.splitext(template)
     installer = INSTALLERS.get(extension, None)
     if installer is None:
         logger.info(u"don't know how to install file %s for code source %s" % (template, 'sitemap'))
     else:
         with open(pjoin(_phome, _folder, template), 'rb') as data:
             installer(self, data, _script_id, extension)
Пример #2
0
def install_code_sources(folder, cs_path, code_sources={}, derived_code_sources={}, product='RwCSCollection'):
    '''
    Method to install Silva code source objects.
    The code source objects described in the dictionary are created in the specified folder.

    @param folder: the Zope folder where the code sources are created
    @param cs_path: the path to the code source templates in the file system
    @param code_sources: dictionnary describing the code sources to install
    @param derived_code_sources:  dictionnary describing derived code sources to install, e.g.
        {'show_sitemap':{'title':'Sitemap', 'constructor':'manage_addSiteMap'} [,...]}
    @param product: the name of the product that can create the object [default: RwCSCollection]
    '''
    factory = folder.manage_addProduct['SilvaExternalSources']
    for cs_name, cs_info in code_sources.items():
        cs_id = _cs_prefix + cs_name
        if hasattr(folder.aq_inner.aq_explicit, cs_id):
            continue

        factory.manage_addCodeSource(cs_id, cs_info['title'], cs_name)
        source = getattr(folder, cs_id)
        source.set_description(cs_info['description'])
        source.set_previewable(cs_info.get('previewable', False))
        source.set_cacheable(cs_info.get('cacheable', False))
        source.set_usable(cs_info.get('usable', False))
        
        codesource_path = pjoin(cs_path, cs_name)
        for filename in os.listdir(codesource_path):
            name, extension = os.path.splitext(filename)
            installer = INSTALLERS.get(extension, None)
            if installer is None:
                logger.info(u"don't know how to install file %s for code source %s" % (filename, cs_name))
                continue
            with open(os.path.join(codesource_path, filename), 'rb') as data:
                installer(source, data, name, extension)

    for cs_name, cs_info in derived_code_sources.items():
        if not cs_info.get('install', False):
            continue
        
        cs_id = _cs_prefix + cs_name
        if hasattr(folder.aq_inner.aq_explicit, cs_id):
            continue

        constructor = getattr(folder.manage_addProduct[product], cs_info['constructor'])
        if constructor:
            constructor(cs_id, cs_info['title'])