Back to index

plone3  3.1.7
lynx_dump.py
Go to the documentation of this file.
00001 """
00002 Uses lynx -dump
00003 """
00004 from Products.PortalTransforms.interfaces import itransform
00005 from Products.PortalTransforms.libtransforms.commandtransform import commandtransform
00006 from Products.PortalTransforms.libtransforms.commandtransform import popentransform
00007 import os
00008 
00009 class lynx_dump(popentransform):
00010     __implements__ = itransform
00011 
00012     __name__ = "lynx_dump"
00013     inputs   = ('text/html',)
00014     output  = 'text/plain'
00015     
00016     __version__ = '2004-07-02.1'
00017 
00018     binaryName = "lynx"
00019     # XXX does -stdin work on windows?
00020     binaryArgs = "-dump -stdin -force_html"
00021     useStdin = True
00022     
00023 class old_lynx_dump(commandtransform):
00024     __implements__ = itransform
00025 
00026     __name__ = "lynx_dump"
00027     inputs   = ('text/html',)
00028     output  = 'text/plain'
00029 
00030     binaryName = "lynx"
00031     binaryArgs = "-dump"
00032 
00033     def __init__(self):
00034         commandtransform.__init__(self, binary=self.binaryName)
00035 
00036     def convert(self, data, cache, **kwargs):
00037         kwargs['filename'] = 'unknown.html'
00038         tmpdir, fullname = self.initialize_tmpdir(data, **kwargs)
00039         outname = "%s/%s.txt" % (tmpdir, orig_name)
00040         self.invokeCommand(tmpdir, fullname, outname)
00041         text = self.astext(outname)
00042         self.cleanDir(tmpdir)
00043         cache.setData(text)
00044         return cache
00045 
00046     def invokeCommand(self, tmpdir, inputname, outname):
00047         os.system('cd "%s" && %s %s "%s" 1>"%s" 2>/dev/null' % \
00048                (tmpdir, self.binary, self.binaryArgs, inputname, outname))
00049 
00050     def astext(self, outname):
00051         txtfile = open("%s" % (outname), 'r')
00052         txt = txtfile.read()
00053         txtfile.close()
00054         return txt
00055 
00056 def register():
00057     return lynx_dump()