Skip to content
Browse files

Version 0.3 preparations. Hold on tight.

  • Loading branch information...
1 parent aec7f47 commit 5f5b561187c7d1baa5e69fab8cd08cfe4a3ecc99 @dagwieers committed Aug 31, 2007
Showing with 213 additions and 181 deletions.
  1. +4 −1 ChangeLog
  2. +8 −2 README
  3. +7 −2 TODO
  4. +0 −135 docs/unoconv.1
  5. +141 −0 docs/unoconv.1.txt
  6. +3 −1 tests/Makefile
  7. +47 −37 unoconv
  8. +3 −3 unoconv.spec
View
5 ChangeLog
@@ -1,10 +1,13 @@
-* 0.2svn - released 28/08/2007
+* 0.3 - released 31/08/2007
- Determine doctype from input filename (if not specified)
- Created a seperate class and allow to use as a library (like DocumentConverter.py)
- Makefile now adds symlinks for different ODF formats like eg, odt2pdf or odp2pdf
- Added MacOSX NeoOffice path '/Applications/NeoOffice.app/Contents/program/' (Peter Stevens)
- Added OpenSUSE 10 OpenOffice path '/usr/lib*/ooo*/program/' (Leo Eraly)
- Start and stop OpenOffice automatically when needed (Matthieu Moy)
+- Added --listener option to make OpenOffice accept client requests (Matthieu Moy)
+- Changed -b option to -f option to match a2x options
+- Add unoconv manual page
* 0.2 - released 20/05/2007
- Added support for almost 100 graphics, presentation and spreadsheet documents
View
10 README
@@ -11,13 +11,19 @@ ooffice instance depends on some outside factors.
You can always start an instance yourself at the default port 2002 and
then use unoconv until you're finished using it and then stop it.
- ooffice -nologo -nodefault "-accept=socket,host=localhost,port=2002;urp;" &
+ unoconv --listener &
unoconv -b pdf *.odt
unoconv -b doc *.odt
unoconv -b html *.odt
kill -15 %-
-Other tools that are useful:
+Also possible is to use a listener or OpenOffice instance that accepts
+conntections on another system and use it from unoconv remotely. This
+way the conversion tasks are performed on a dedicated system instead
+of on the client system.
+
+
+Other tools that are useful or similar in operation:
+ Text based document generation
http://www.methods.co.nz/asciidoc/
View
9 TODO
@@ -14,5 +14,10 @@ contact me as well. :) Send an email to: Dag Wieers <dag@wieers.com>
- Maybe change the commandline interface to reflect ImageMagick's convert
- Add the list of input formats as well, and print that list too
-### Documentation
-- Add manpage
+### OpenOffice execution
+- If an openoffice exists, -accept modifies the existing behaviour of
+ the running instance. In that case we need to -unaccept afterwards
+ (and not try to kill a ghost)
+- If a unoconv-listener has been started, and you start an openoffice
+ gui, the openoffice gui runs as the same process as the listeners.
+ In that case we need to -unaccept afterwards (and not kill the gui)
View
135 docs/unoconv.1
@@ -1,135 +0,0 @@
-.\" ** You probably do not want to edit this file directly **
-.\" It was generated using the DocBook XSL Stylesheets (version 1.69.1).
-.\" Instead of manually editing it, you probably should edit the DocBook XML
-.\" source for it and then use the DocBook XSL Stylesheets to regenerate it.
-.TH "UNOCONV" "1" "08/30/2007" "" ""
-.\" disable hyphenation
-.nh
-.\" disable justification (adjust text to left margin only)
-.ad l
-.SH "NAME"
-unoconv \- convert any document from and to any OpenOffice supported format
-.SH "SYNOPSIS"
-unoconv \-\-listener [\-\-server srv] [\-\-port prt]
-.sp
-unoconv \-b pdf [options] file [file2 ..]
-.sp
-.SH "DESCRIPTION"
-unoconv is a command line utility that can convert any file format that OpenOffice can import, to any file format that OpenOffice is capable of exporting.
-.sp
-unoconv uses the OpenOffice's UNO bindings for non\-interactive conversion of documents and therefor needs an OpenOffice instance to communicate with. Therefore if it cannot find one, it will start its own instance for temporary usage. If desired, one can start a \(lqlistener\(rq instance to use for subsequent connections or even for remote connections.
-.sp
-.SH "OPTIONS"
-.TP
-\-b, \-\-backend
-Specify the format to convert to
-.TP
-\-d, \-\-doctype
-Specify the doctype of the backend format
-.TP
-\-c, \-\-connection
-Connection string
-.TP
-\-s, \-\-server
-Server to listen on (as listener) or to connect to (as client)
-.TP
-\-p, \-\-port
-Port to listen on (as listener) or to connect to (as client)
-.TP
-\-l, \-\-listener
-Start unoconv as listener for unoconv clients to connect to
-.TP
-\-\-list
-List possible input/output formats
-.TP
-\-\-stdout
-Print output file to stdout
-.TP
-\-v, \-\-verbose
-Be more and more verbose
-.SH "ARGUMENTS"
-You can provide one or more \fBfiles\fR as arguments to convert each of them to the specified \fBbackend format\fR.
-.sp
-.SH "USAGE"
-You can use unoconv in standalone mode, this means that in absence of an OpenOffice listener, it will starts its own:
-.sp
-.sp
-.nf
-unoconv \-b pdf some\-document.odt
-.fi
-One can use unoconv as a listener (by default localhost:2002) to let other unoconv instances connect to it:
-.sp
-.sp
-.nf
-unoconv \-\-listener &
-unoconv \-b pdf some\-document.odt
-unoconv \-b doc other\-document.odt
-unoconv \-b jpg some\-image.png
-unoconv \-b xsl some\-spreadsheet.csv
-kill \-15 %\-
-.fi
-This also works on a remote host:
-.sp
-.sp
-.nf
-unoconv \-\-listener \-\-server 1.2.3.4 \-\-port 4567
-.fi
-and then connect another system to convert documents:
-.sp
-.sp
-.nf
-unoconv \-\-server 1.2.3.4 \-\-port 4567
-.fi
-.SH "BUGS"
-unoconv uses the UNO bindings to connect to OpenOffice, in absence of a usable socket, it will start its own OpenOffice instance with the correct parameters. However, OpenOffice requires a working DISPLAY (even with \-headless option) and therefor you cannot run it in a true console, you need X.
-.sp
-.sp
-.it 1 an-trap
-.nr an-no-space-flag 1
-.nr an-break-flag 1
-.br
-\fBNote\fR
-Please see the TODO file for known bugs and future plans.
-.sp
-.SH "SEE ALSO"
-.sp
-.nf
-convert(1), file(1), odt2txt
-.fi
-.SH "REFERENCES"
-.TP 3
-\(bu
-[1]\&\fIText based document generation\fR
-.TP
-\(bu
-[2]\&\fIDocBook to OpenDocument XSLT\fR
-.TP
-\(bu
-[3]\&\fISimple (and stupid) converter from OpenDocument Text to plain text\fR
-.TP
-\(bu
-[4]\&\fIAnother python tool to aid in converting files using UNO\fR
-.SH "AUTHOR"
-Written by Dag Wieers [5]\&\fIdag@wieers.com\fR
-.sp
-Homepage at [6]\&\fIhttp://dag.wieers.com/home\-made/unoconv/\fR
-.sp
-.SH "REFERENCES"
-.TP 3
-1.\ Text based document generation
-\%http://www.methods.co.nz/asciidoc/
-.TP 3
-2.\ DocBook to OpenDocument XSLT
-\%http://open.comsultia.com/docbook2odf/
-.TP 3
-3.\ Simple (and stupid) converter from OpenDocument Text to plain text
-\%http://stosberg.net/odt2txt/
-.TP 3
-4.\ Another python tool to aid in converting files using UNO
-\%http://www.artofsolving.com/opensource/pyodconverter
-.TP 3
-5.\ dag@wieers.com
-\%mailto:dag@wieers.com
-.TP 3
-6.\ http://dag.wieers.com/home\-made/unoconv/
-\%http://dag.wieers.com/home\-made/unoconv/
View
141 docs/unoconv.1.txt
@@ -0,0 +1,141 @@
+= unoconv(1)
+Dag Wieers <dag@wieers.com>
+v0.3, 31 august 2007
+
+
+== NAME
+unoconv - convert any document from and to any OpenOffice supported format
+
+
+== SYNOPSIS
+'unoconv' [options] file [file2 ..]
+
+'unoconv' --listener [--server server] [--port port]
+
+
+== DESCRIPTION
+unoconv is a command line utility that can convert any file format that
+OpenOffice can import, to any file format that OpenOffice is capable of
+exporting.
+
+unoconv uses the OpenOffice's UNO bindings for non-interactive conversion
+of documents and therefor needs an OpenOffice instance to communicate with.
+Therefore if it cannot find one, it will start its own instance for temporary
+usage. If desired, one can start a ``listener'' instance to use for subsequent
+connections or even for remote connections.
+
+
+== OPTIONS
+-c, --connection::
+ UNO connection string to be used by the client to connect to an
+ OpenOffice instance, or used by the listener to make OpenOffice
+ listen.
++
+ Default connection string is "socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
+
+-d, --doctype::
+ Specify the OpenOffice document type of the backend format. Possible
+ document types are: 'document', 'graphics', 'presentation',
+ 'spreadsheet'.
++
+ Default document type is 'document'.
+
+-f, --format::
+ Specify the output format for the document. You can get a list of
+ possible output formats per document type by using the +--list+ option.
++
+ Default document type is 'pdf'.
+
+--list::
+ Show the possible output formats to be used with +-f+.
+
+-l, --listener::
+ Start unoconv as listener for unoconv clients to connect to.
+
+-p, --port::
+ Port to listen on (as listener) or to connect to (as client).
++
+ Default port is '2002'.
+
+-s, --server::
+ Server (address) to listen on (as listener) or to connect to (as client).
++
+ Default server is 'localhost'.
+
+--stdout::
+ Print converted output file to stdout.
+
+-v, --verbose::
+ Be more and more and more verbose.
+
+
+== ARGUMENTS
+You can provide one or more *files* as arguments to convert each of them to
+the specified *output format*.
+
+
+== EXAMPLES
+You can use unoconv in standalone mode, this means that in absence of an
+OpenOffice listener, it will starts its own:
+
+ unoconv -f pdf some-document.odt
+
+
+One can use unoconv as a listener (by default localhost:2002) to let other
+unoconv instances connect to it:
+
+ unoconv --listener &
+ unoconv -f pdf some-document.odt
+ unoconv -f doc other-document.odt
+ unoconv -f jpg some-image.png
+ unoconv -f xsl some-spreadsheet.csv
+ kill -15 %-
+
+
+This also works on a remote host:
+
+ unoconv --listener --server 1.2.3.4 --port 4567
+
+
+and then connect another system to convert documents:
+
+ unoconv --server 1.2.3.4 --port 4567
+
+
+== BUGS
+unoconv uses the UNO bindings to connect to OpenOffice, in absence of a usable
+socket, it will start its own OpenOffice instance with the correct parameters.
+However, OpenOffice requires a working +DISPLAY+ (even with +-headless+
+option) and therefor you cannot run it in a true console, you need X.
+
+[NOTE]
+Please see the TODO file for known bugs and future plans.
+
+
+== SEE ALSO
+ convert(1), file(1), odt2txt
+
+
+== REFERENCES
+unoconv is very useful together with the following tools:
+
+Asciidoc::
+ http://www.methods.co.nz/asciidoc/
+
+docbook2odf::
+ http://open.comsultia.com/docbook2odf/
+
+
+== AUTHOR
+Written by Dag Wieers, <mailto:dag@wieers.com[]>
+
+
+== RESOURCES
+Main web site: http://dag.wieers.com/home-made/unoconv/[]
+
+
+== COPYING
+Copyright \(C) 2007 Dag Wieers. Free use of this software is granted under the
+terms of the GNU General Public License (GPL).
+
+// vim: set syntax=asciidoc
View
4 tests/Makefile
@@ -1,3 +1,5 @@
+### Please modify and send me improvements
+
all: clean bib doc6 doc95 doc docbook html ooxml pdb pdf psw rtf latex sdw3 sdw4 sdw sxw text txt xhtml
#xml: curriculum-vitae-dag-wieers.txt
@@ -9,7 +11,7 @@ all: clean bib doc6 doc95 doc docbook html ooxml pdb pdf psw rtf latex sdw3 sdw4
%:
# -killall ooffice soffice.bin
- -../unoconv -b $@ document-example.odt
+ -../unoconv -f $@ document-example.odt
# @ps aux | grep office
# -unoconv -f $@ dag.gif
# docbook2pdf -d curriculum-vitae.dsl#print curriculum-vitae-dag-wieers.xml
View
84 unoconv
@@ -41,7 +41,7 @@ from com.sun.star.uno import Exception as UnoException
__version__ = "$Revision$"
# $Source$
-VERSION = '0.2svn'
+VERSION = '0.3'
doctypes = ('document', 'graphics', 'presentation', 'spreadsheet')
@@ -94,7 +94,7 @@ class FmtList:
for fmt in self.list:
if fmt.doctype == doctype:
print >>sys.stderr, " %-8s - %s" % (fmt.name, fmt)
- print >>sys.stderr
+ print >>sys.stderr
class OutputStream( unohelper.Base, XOutputStream ):
def __init__( self ):
@@ -251,8 +251,8 @@ class Options:
### Get options from the commandline
try:
- opts, args = getopt.getopt (args, 'b:c:d:hLlp:s:t:v',
- ['backend=', 'connection=', 'doctype=', 'help', 'listener', 'list', 'port=', 'server=', 'stdout', 'verbose', 'version'] )
+ opts, args = getopt.getopt (args, 'c:d:f:hLlp:s:t:v',
+ ['connection=', 'doctype=', 'format=', 'help', 'list', 'listener', 'port=', 'server=', 'stdout', 'verbose', 'version'] )
except getopt.error, exc:
print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
sys.exit(255)
@@ -263,12 +263,12 @@ class Options:
print
self.help()
sys.exit(1)
- elif opt in ['-b', '--backend']:
- self.format = arg
elif opt in ['-c', '--connection']:
self.connection = arg
elif opt in ['-d', '--doctype']:
self.doctype = arg
+ elif opt in ['-f', '--format']:
+ self.format = arg
elif opt in ['-l', '--listener']:
self.listener = True
elif opt in ['-L', '--list']:
@@ -303,7 +303,7 @@ class Options:
### Make it easier for people to use a doctype (first letter is enough)
if self.doctype:
for doctype in doctypes:
- if self.doctype[0] == doctype[0]:
+ if doctype.startswith(self.doctype):
self.doctype = doctype
### Check if the user request to see the list of formats
@@ -315,7 +315,7 @@ class Options:
fmts.display(t)
sys.exit(0)
- ### if no format was specified, probe it or provide it
+ ### If no format was specified, probe it or provide it
if not self.format:
l = sys.argv[0].split('2')
if len(l) == 2:
@@ -340,40 +340,48 @@ class Options:
print >>sys.stderr, '''Convert from and to any format supported by OpenOffice
unoconv options:
- -b, --backend=format specify the output format
-c, --connection=string use a custom connection string
- -d, --doctype=type specify document type (document, graphics, presentation, spreadsheet)
- -l, --list list the available output formats
- -p, --port specify a different port (default: 2002)
- -s, --server specify a different server (default: localhost)
+ -d, --doctype=type specify document type
+ (document, graphics, presentation, spreadsheet)
+ -f, --format=format specify the output format
+ --list list the available output formats
+ -l, --listener start a listener to use by unoconv clients
+ -p, --port specify the port (default: 2002)
+ to be used by client or listener
+ -s, --server specify the server address (default: localhost)
+ to be used by client or listener
--stdout write output to stdout
'''
class Convertor:
def __init__(self):
global oopid
+ ### Do the OpenOffice component dance
self.context = uno.getComponentContext()
resolver = self.context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.context)
+ ### Test for an existing connection
try:
unocontext = resolver.resolve("uno:%s" % op.connection)
- except NoConnectException, e:
- try:
- error(1, "Warning: failed to connect, trying to launch soffice.bin.")
- oopid = os.spawnvp(os.P_NOWAIT, "soffice.bin", ["soffice.bin", "-nologo", "-nodefault", "-headless", "-accept=%s" % op.connection]);
- if not oopid: raise
- time.sleep(1)
- unocontext = resolver.resolve("uno:%s" % op.connection)
- except:
- error(1, "Warning: failed to connect, trying to launch soffice.")
- oopid = os.spawnvp(os.P_NOWAIT, "soffice", ["soffice", "-nologo", "-nodefault", "-headless", "-accept=%s" % op.connection]);
- if not oopid: raise
- time.sleep(1)
- unocontext = resolver.resolve("uno:%s" % op.connection)
-
+# except NoConnectException, e:
+ except Exception, e:
+ error(2, "Existing listener not found.\n%s" % e)
+
+ ### Test if we can use an Openoffice *binary* in our (modified) path
+ for bin in ('boffice', 'soffice.bin', 'soffice', ):
+ error(2, "Trying to launch %s as our own listener." % bin)
+ try:
+ oopid = os.spawnvp(os.P_NOWAIT, bin, [bin, "-nologo", "-nodefault", "-accept=%s" % op.connection]);
+ time.sleep(1)
+ unocontext = resolver.resolve("uno:%s" % op.connection)
+ break
+ except Exception, e:
+ error(3, "Launch of %s failed.\n%s" % (bin, e))
+ continue
+
+ ### And some more OpenOffice magic
unosvcmgr = unocontext.ServiceManager
-
self.desktop = unosvcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", unocontext)
self.cwd = unohelper.systemPathToFileUrl( os.getcwd() )
@@ -484,20 +492,21 @@ class Convertor:
class Listener:
def __init__(self):
- error(1, "Started listener on %s:%s" % (op.server, op.port))
- try:
- os.execvp("soffice.bin", ["soffice.bin", "-nologo", "-nodefault", "-accept=%s" % op.connection]);
- except:
+ info(1, "Start listener on %s:%s" % (op.server, op.port))
+ for bin in ('soffice.bin', 'soffice', ):
+ error(2, "Warning: trying to launch %s." % bin)
try:
- os.execvp("soffice", ["soffice", "-nologo", "-nodefault", "-accept=%s" % op.connection]);
+ os.execvp(bin, [bin, "-nologo", "-nodefault", "-accept=%s" % op.connection]);
except:
- pass
- error(0, "Failed to start listener on %s:%s" % (op.server, op.port))
+ continue
+ else:
+ die(254, "Failed to start listener on %s:%s" % (op.server, op.port))
+ die(253, "Existing listener found, aborting.")
def error(level, str):
"Output error message"
if level <= op.verbose:
- print >>sys.stderr, "Error: %s" % str
+ print >>sys.stderr, str
def info(level, str):
"Output info message"
@@ -508,14 +517,15 @@ def die(ret, str=None):
"Print error and exit with errorcode"
global oopid
if str:
- error(0, str)
+ error(0, 'Error: %s' % str)
if oopid:
error(2, 'Taking down OpenOffice with pid %s' % oopid)
# os.setpgid(oopid, 0)
# os.killpg(os.getpgid(oopid), 15)
os.kill(oopid, 15)
error(2, 'Waiting for OpenOffice with pid %s to disappear' % oopid)
os.waitpid(oopid, os.WUNTRACED)
+
sys.exit(ret)
def main():
View
6 unoconv.spec
@@ -8,7 +8,7 @@
Summary: Tool to convert between any document format supported by OpenOffice
Name: unoconv
-Version: 0.2svn
+Version: 0.3
Release: 1
License: GPL
Group: System Environment/Base
@@ -57,8 +57,8 @@ and many more...
%{_bindir}/unoconv
%changelog
-* Tue May 22 2007 Dag Wieers <dag@wieers.com> - 0.2svn-1
-- Updated to release 0.2svn.
+* Fri Aug 31 2007 Dag Wieers <dag@wieers.com> - 0.3-1
+- Updated to release 0.3.
* Sun May 20 2007 Dag Wieers <dag@wieers.com> - 0.2-1
- Updated to release 0.2.

0 comments on commit 5f5b561

Please sign in to comment.
Something went wrong with that request. Please try again.