Back to index

plone3  3.1.7
setuphandlers.py
Go to the documentation of this file.
00001 """
00002 MimetypesRegistry setup handlers.
00003 """
00004 
00005 from Products.CMFCore.utils import getToolByName
00006 
00007 from StringIO import StringIO
00008 
00009 def fixUpSMIGlobs(portal, out=None):
00010     from Products.MimetypesRegistry.mime_types import smi_mimetypes
00011     from Products.Archetypes.debug import log
00012     mtr = getToolByName(portal, 'mimetypes_registry')
00013     smi_mimetypes.initialize(mtr)
00014 
00015     # Now comes the fun part. For every glob, lookup a extension
00016     # matching the glob and unregister it.
00017     for glob in mtr.globs.keys():
00018         if mtr.extensions.has_key(glob):
00019             log('Found glob %s in extensions registry, removing.' % glob)
00020             mti = mtr.extensions[glob]
00021             del mtr.extensions[glob]
00022             if glob in mti.extensions:
00023                 log('Found glob %s in mimetype %s extensions, '
00024                     'removing.' % (glob, mti))
00025                 exts = list(mti.extensions)
00026                 exts.remove(glob)
00027                 mti.extensions = tuple(exts)
00028                 mtr.register(mti)
00029 
00030 
00031 def installMimetypesRegistry(portal):
00032     out = StringIO()
00033 
00034     fixUpSMIGlobs(portal, out)
00035 
00036 
00037 def setupMimetypesRegistry(context):
00038     """
00039     Setup MimetypesRegistry step.
00040     """
00041     # Only run step if a flag file is present (e.g. not an extension profile)
00042     if context.readDataFile('mimetypes-registry-various.txt') is None:
00043         return
00044     out = []
00045     site = context.getSite()
00046     installMimetypesRegistry(site)
00047