Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Private Attributes
command.ExternalCommandTransform Class Reference
Inheritance diagram for command.ExternalCommandTransform:
Inheritance graph
[legend]
Collaboration diagram for command.ExternalCommandTransform:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __getattr__
def convert
def invokeCommand

Public Attributes

 config
 config_metadata
 input_extension

Static Private Attributes

tuple __implements__ = (itransform,)
string __name__ = "command_transform"

Detailed Description

Custom external command

transform content by launching an external command

the command should take the content in an input file (designed by '%s' in
the command line parameters) and return output on stdout.
Input and output mime types must be set correctly !

Definition at line 14 of file command.py.


Constructor & Destructor Documentation

def command.ExternalCommandTransform.__init__ (   self,
  name = None,
  input_extension = None,
  kwargs 
)

Definition at line 27 of file command.py.

00027 
00028     def __init__(self, name=None, input_extension=None, **kwargs):
00029         self.config = {
00030             'binary_path'  : '',
00031             'command_line' : '',
00032             'inputs'       : ('text/plain',),
00033             'output'       : 'text/plain',
00034             }
00035         self.config_metadata = {
00036             'binary_path'  : ('string', 'Binary path',
00037                               'Path of the executable on the server.'),
00038             'command_line' : ('string', 'Command line',
00039                               '''Additional command line option.
00040 There should be at least the input file (designed by "%(input)s").
00041 The transformation\'s result must be printed on stdout.
00042 '''),
00043             'inputs'       : ('list', 'Inputs', 'Input(s) MIME type. Change with care.'),
00044             'output'       : ('string', 'Output', 'Output MIME type. Change with care.'),
00045             }
00046         self.config.update(kwargs)
00047         commandtransform.__init__(self, name=name, binary=self.config['binary_path'],  **kwargs)
00048 
00049         # use the full binary path
00050         self.config.update({'binary_path':self.binary})
00051         self.input_extension = input_extension


Member Function Documentation

Definition at line 52 of file command.py.

00052 
00053     def __getattr__(self, attr):
00054         if attr == 'inputs':
00055             return self.config['inputs']
00056         if attr == 'output':
00057             return self.config['output']
00058         raise AttributeError(attr)
00059 

Here is the caller graph for this function:

def command.ExternalCommandTransform.convert (   self,
  data,
  cache,
  kwargs 
)

Definition at line 60 of file command.py.

00060 
00061     def convert(self, data, cache, **kwargs):
00062         filename = kwargs.get('filename') or 'unknown'
00063         if self.input_extension is not None:
00064             kwargs['filename'] = 'unknown' + self.input_extension
00065         else:
00066             kwargs['filename'] = 'unknown' + os.path.splitext(filename)[-1]
00067         tmpdir, fullname = self.initialize_tmpdir(data, **kwargs)
00068 
00069         data = self.invokeCommand(fullname)
00070         cache.setData(data)
00071         path, images = self.subObjects(tmpdir)
00072         objects = {}
00073         if images:
00074             self.fixImages(path, images, objects)
00075             cache.setSubObjects(objects)
00076         self.cleanDir(tmpdir)
00077         return cache
00078 

Here is the call graph for this function:

def command.ExternalCommandTransform.invokeCommand (   self,
  input_name 
)

Definition at line 79 of file command.py.

00079 
00080     def invokeCommand(self, input_name):
00081         command = '%(binary_path)s %(command_line)s' % self.config
00082         input, output, error = popen3(command % input_name)
00083         input.close()
00084         # first read stderr, else we may hang on stout
00085         # but, still hang my windows, so commented it :-(
00086         # error_data = error.read()
00087         error_data = 'error while running "%s"' % (command % input_name)
00088         error.close()
00089         data = output.read()
00090         output.close()
00091         if error_data and not data:
00092             data = error_data
00093         else:
00094             log('Error while running "%s":\n %s' % (command % input_name,
00095                                                     error_data))
00096         return data

Here is the caller graph for this function:


Member Data Documentation

tuple command.ExternalCommandTransform.__implements__ = (itransform,) [static, private]

Definition at line 23 of file command.py.

string command.ExternalCommandTransform.__name__ = "command_transform" [static, private]

Definition at line 25 of file command.py.

Definition at line 28 of file command.py.

Definition at line 34 of file command.py.

Definition at line 50 of file command.py.


The documentation for this class was generated from the following file: