Using PyODConverter with non-default ports
I've been using the excellent PyODConverter (aka Python OpenDocument Converter) for quite sometime now. It's a very small Python script that uses OpenOffice's Python-UNO bridge to convert documents between formats. For example, to convert test.doc
to a PDF file, you could execute:
As a small side note, for the Python-UNO bridge (and thus PyODConverter) to work, you do need to use the python
binary that installs with OpenOffice, so you will most likely need to full-qualify the python
command like:
Anyway, PyODConverter always tries to talk to OpenOffice via (the somewhat arbitrary) port 8100. But today I found myself needing to able to tell PyODConverter which port to use via the command line. So, I went about modifying the PyODConverter code - which was very easy, thanks to it being already very well written.
However, since PyODConverter is officially released under the GNU LGPL, my understanding is that I am now obliged to publish back the changes... sounds like a great excuse for another blog post ;)
So, here's the diff
output for my (very minor) modifications to PyODConverter's DocumentConverter.py v1.0.0 script:
> port = DEFAULT_OPENOFFICE_PORT
135c136
< print "USAGE: python %s
---
> print "USAGE: python %s
136a138,139
> elif len(argv) > 3:
> port = argv[3]
142c145
< converter = DocumentConverter()
---
> converter = DocumentConverter(port)
As you can see, the changes are quite simple and few. They enable the port number as an optional third command line parameter. For example:
In that example, PyODConverter will try to use port 12345
to talk to OpenOffice. Of course, if you omit the optional port parameter, PyODConverter will simply default back to the original port 8100.