Back to index

plone3  3.1.7
__init__.py
Go to the documentation of this file.
00001 ### Register Transforms
00002 ### This is interesting because we don't expect all transforms to be
00003 ### available on all platforms. To do this we allow things to fail at
00004 ### two levels
00005 ### 1) Imports
00006 ###    If the import fails the module is removed from the list and
00007 ###    will not be processed/registered
00008 ### 2) Registration
00009 ###    A second phase happens when the loaded modules register method
00010 ###    is called and this produces an instance that will used to
00011 ###    implement the transform, if register needs to fail for now it
00012 ###    should raise an ImportError as well (dumb, I know)
00013 
00014 from logging import DEBUG, ERROR
00015 from Products.PortalTransforms.utils import log
00016 from Products.PortalTransforms.libtransforms.utils import MissingBinary
00017 modules = [
00018     'st',             # zopish
00019     'rest',           # docutils
00020     'word_to_html',   # uno, com, wvware
00021     'safe_html',      # extract <body> and remove potentially harmful tags
00022     'html_body',      # extract only the contents of the <body> tag
00023     'html_to_text',   # re based transform
00024     'text_to_html',   # wrap text in a verbatim env
00025     'text_pre_to_html', # wrap text into a pre
00026     'pdf_to_html',    # sf.net/projects/pdftohtml
00027     'pdf_to_text',    # www.foolabs.com/xpdf
00028     'rtf_to_html',    # sf.net/projects/rtf-converter
00029     'rtf_to_xml',     # sf.net/projects/rtf2xml
00030     'image_to_png',   # transforms any image to a PNG image
00031     'image_to_gif',   # transforms any image to a GIF image
00032     'image_to_jpeg',  # transforms any image to a JPEG image
00033     'image_to_pcx',   # transforms any image to a PCX image
00034     'image_to_ppm',   # transforms any image to a PPM image
00035     'image_to_tiff',  # transforms any image to a TIFF image
00036     'image_to_bmp',   # transforms any image to a BMP image
00037     'lynx_dump',      # lynx -dump
00038     'python',         # python source files, no dependancies
00039     'identity',       # identity transform, no dependancies
00040     'markdown_to_html', # markdown, depends on http://surfnet.dl.sourceforge.net/sourceforge/python-markdown/markdown-1-5.py
00041     'textile_to_html',# textile, depends on PyTextile http://dom.eav.free.fr/python/textile-mirror-2.0.10.tar.gz 
00042     'web_intelligent_plain_text_to_html',
00043     'html_to_web_intelligent_plain_text',
00044     ]
00045 
00046 g = globals()
00047 transforms = []
00048 for m in modules:
00049     try:
00050         ns = __import__(m, g, g, None)
00051         transforms.append(ns.register())
00052     except ImportError, e:
00053         msg = "Problem importing module %s : %s" % (m, e)
00054         log(msg, severity=ERROR)
00055     except MissingBinary, e:
00056         log(str(e), severity=DEBUG)
00057     except Exception, e:
00058         import traceback
00059         traceback.print_exc()
00060         log("Raised error %s for %s" % (e, m), severity=ERROR)
00061 
00062 def initialize(engine):
00063     for transform in transforms:
00064         engine.registerTransform(transform)