| 1 |
### Register Transforms |
|---|
| 2 |
### This is interesting because we don't expect all transforms to be |
|---|
| 3 |
### available on all platforms. To do this we allow things to fail at |
|---|
| 4 |
### two levels |
|---|
| 5 |
### 1) Imports |
|---|
| 6 |
### If the import fails the module is removed from the list and |
|---|
| 7 |
### will not be processed/registered |
|---|
| 8 |
### 2) Registration |
|---|
| 9 |
### A second phase happens when the loaded modules register method |
|---|
| 10 |
### is called and this produces an instance that will used to |
|---|
| 11 |
### implement the transform, if register needs to fail for now it |
|---|
| 12 |
### should raise an ImportError as well (dumb, I know) |
|---|
| 13 |
# |
|---|
| 14 |
# $Id$ |
|---|
| 15 |
|
|---|
| 16 |
from Products.PortalTransforms.libtransforms.utils import MissingBinary |
|---|
| 17 |
from zLOG import LOG, DEBUG, WARNING |
|---|
| 18 |
|
|---|
| 19 |
logKey = 'PortalTransforms' |
|---|
| 20 |
|
|---|
| 21 |
modules = [ |
|---|
| 22 |
'st', # zopish |
|---|
| 23 |
'rest', # docutils |
|---|
| 24 |
'word_to_html', # uno, com, wvware |
|---|
| 25 |
'word_to_text', # lxml, wvware |
|---|
| 26 |
'xls_to_html', # xlhtml |
|---|
| 27 |
'ppt_to_html', # ppthtml |
|---|
| 28 |
'ooo_to_html', # unzip + xsltproc |
|---|
| 29 |
'opendocument_to_html', # unzip + xsltproc http://opendocumentfoundation.org |
|---|
| 30 |
'ooo_to_docbook', # OOo2sDBK http://www.chez.com/ebellot/ooo2sdbk/ |
|---|
| 31 |
'docbook_to_html',# xsltproc + http://docbook.sourceforge.net/ |
|---|
| 32 |
'text_to_html', # wrap text in a verbatim env |
|---|
| 33 |
'pdf_to_html', # sf.net/projects/pdftohtml |
|---|
| 34 |
'pdf_to_text', # www.foolabs.com/xpdf |
|---|
| 35 |
'rtf_to_html', # sf.net/projects/rtf-converter |
|---|
| 36 |
'rtf_to_xml', # sf.net/projects/rtf2xml |
|---|
| 37 |
'lynx_dump', # lynx -dump |
|---|
| 38 |
'html_to_text', # re based transform |
|---|
| 39 |
'python', # python source files, no dependancies |
|---|
| 40 |
'identity', # identity transform, no dependancies |
|---|
| 41 |
] |
|---|
| 42 |
|
|---|
| 43 |
g = globals() |
|---|
| 44 |
transforms = [] |
|---|
| 45 |
for m in modules: |
|---|
| 46 |
try: |
|---|
| 47 |
LOG(logKey, DEBUG, "Importing module = %s" % m) |
|---|
| 48 |
ns = __import__(m, g, g, None) |
|---|
| 49 |
LOG(logKey, DEBUG, "Appending transform = %s" % ns) |
|---|
| 50 |
transforms.append(ns.register()) |
|---|
| 51 |
except Exception, exc: |
|---|
| 52 |
LOG(logKey, WARNING, exc) |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
def initialize(engine): |
|---|
| 56 |
for transform in transforms: |
|---|
| 57 |
engine.registerTransform(transform) |
|---|
| 58 |
|
|---|