#!/bin/bash # office2office - simple bash wrapper for DocumentConverter.py, which # uses OpenOffice.org (OOo) to convert from any supported file format # to any other supported file format. Built atop DocumentConverter.py # version 1.0.0. # Copyright (c) 2009 Claude Rubinson # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. DOCUMENTCONVERTER=~/bin/DocumentConverter.py # upstream is http://www.artofsolving.com/opensource/pyodconverter function help () { echo "Usage: office2office [-h] infile outfile" } while getopts "h" Opt; do case $Opt in h ) help; exit 0 ;; * ) help > /dev/stderr; exit 1 ;; esac done infile=$1 outfile=$2 # rudimentary error trapping if ! [ -a $infile ]; then echo "office2office: $infile: File missing" > /dev/stderr exit 1 fi if [ -z $outfile ]; then echo "office2office: Outfile missing" > /dev/stderr exit 1 fi # if OOo is already running, DocumentConverter.py fails. This is a # crass workaround; ideally, figure out how to connect to running # instance and/or start up new instance runningpid="$(ps ax|grep soffice.bin|grep -v grep|cut -d" " -f1)" if [ -n "$runningpid" ]; then echo "OpenOffice.org is already running at pid $runningpid. You'll need to shut down all instances of OpenOffice.org before proceeding." > /dev/stderr exit 1 fi # start up OOo in headless mode on port 8100. If you change this # port, you'll also need to change it in the DocumentConverter.py # script # # note that this will fail if an instance (headless or not) of OOo is # already running; should fix ooffice -headless -accept="socket,port=8100;urp;" sleep 1 # it takes a second or so for OOo to start up; try increasing # this timeout if you get an error from DocumentConverter.py # saying that it can't connect to the OOo instance. # do it python $DOCUMENTCONVERTER $infile $outfile # get PID of OOo instance and kill oopid=$(ps ax|grep soffice.bin|grep -v grep|cut -d" " -f1) kill -KILL $oopid