A server that waits for requests for conversion of documents.
Important code fragments are from regular Python documentation.
A handler for the ThreadedTCPServer.
It implements the protocol, the PyUNO server actually works with.
The protocol:
The request:
REQUEST ::= CONVERT_CMD | FIND_CMD | TEST_CMD CONVERT_CMD ::= CMD PATH CMD ::= "CONVERT_PDF<NL>" | "CONVERT_HTML<NL>" FIND_CMD ::= "FIND<NL>" TEST_CMD ::= "TEST<NL>" PATH ::= "PATH=" PATH_TO_DOCUMENT PATH_TO_DOCUMENT ::= <file-path>Response:
RESPONSE ::= OK_RESULT | ERR_RESULT | VERSION_RESULT OK_RESULT ::= "OK " STATUS PATH_TO_RESULT ERR_RESULT ::= "ERR " STATUS ERR_MSG STATUS ::= <integer-number> PATH_TO_RESULT ::= <file-path> ERR_MSG ::= <textblock> VERSION_RESULT ::= "OK 0 " <server-version>with:
- <NL>
- NewLine character
- <file-path>
- a valid path to a local file
- <integer-number>
- an integer number
- <server-version>
- a string like 0.1dev
- <text>
- a string, possibly containing several lines.
Examples:
Request:
CONVERT_PDF PATH=/home/foo/bar.odtResponse:
OK 0 /tmp/asdqwe.pdfRequest:
CONVERT_HTML PATH=/home/foo/bar.docxResponse:
OK 0 /tmp/sdfwqerRequest:
FIND PATH=/home/foo/bar.docx REGEX=regexResponse:
OK 0 [{'page':1},{'page':33}]Request:
TEST
Response:
ERR -1 Could not reach OpenOffice.org server on port 2002 Please make sure to start oooctl.
Move results to a secure destination.
If the result is HTML we try to untar the result file.
Before we can feed the cachemanager, we tar HTML results.
We move the source to a secure location.
This way we prevent results from being polluted by already existing files not belonging to the result.
An asynchronous TCP server.
The cache manager instance used by any server isntance.
Marker to check while serving for stop-requests.
A logger instance.
Bind server to socket.
We use SO_REUSEADDR to ensure, that we can reuse the port on restarts immediately. Otherwise we would be blocked by TIME_WAIT for several seconds or minutes.
Start an instance of ThreadedTCPServer.