Permalink
Browse files

Initial import of universal OpenOffice convertor

  • Loading branch information...
dagwieers committed May 19, 2007
0 parents commit 5ab3cbe7561a73ffde5d45a0906e761e933c6c8e
Showing with 645 additions and 0 deletions.
  1. +1 −0 AUTHORS
  2. +340 −0 COPYING
  3. +2 −0 ChangeLog
  4. +32 −0 Makefile
  5. +3 −0 README
  6. +12 −0 TODO
  7. +32 −0 WISHLIST
  8. +177 −0 unoconv
  9. +46 −0 unoconv.spec
@@ -0,0 +1 @@
+Dag Wieers <dag@wieers.com>
340 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,2 @@
+* 0.1svn - ... - released 19/05/2007
+- Initial release
@@ -0,0 +1,32 @@
+name = unoconv
+version = $(shell awk '/^Version: / {print $$2}' $(name).spec)
+
+prefix = /usr
+sysconfdir = /etc
+bindir = $(prefix)/bin
+sbindir = $(prefix)/sbin
+libdir = $(prefix)/lib
+datadir = $(prefix)/share
+mandir = $(datadir)/man
+localstatedir = /var
+
+all:
+ @echo "There is nothing to be build. Try install !"
+
+install:
+ install -Dp -m0755 unoconv $(DESTDIR)$(bindir)/unoconv
+
+docs:
+ make -C docs
+
+dist:
+ find . ! -path '*/.svn*' | pax -d -w -x ustar -s ',^.,$(name)-$(version),' | bzip2 >../$(name)-$(version).tar.bz2
+
+rpm: dist
+ rpmbuild -tb --clean --rmsource --rmspec --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" --define "_rpmdir ../" ../$(name)-$(version).tar.bz2
+
+srpm: dist
+ rpmbuild -ts --clean --rmsource --rmspec --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" --define "_srcrpmdir ../" ../$(name)-$(version).tar.bz2
+
+clean:
+ rm -f README*.html
3 README
@@ -0,0 +1,3 @@
+
+---
+Please send me improvements to this document.
12 TODO
@@ -0,0 +1,12 @@
+### Disclaimer
+This is my TODO list. If you're interested in one of these features, there
+are 3 options. Either wait for someone to implement it, sponsor someone
+to implement it or implement it yourself.
+
+If you want to implement something, please contact me first so that we can
+discuss acceptable implementations. In some cases I haven't thought about
+it too deeply, but for others I know exactly what I require.
+
+If you have other nice ideas that you think would be an improvement, please
+contact me as well. :) Send an email to: Dag Wieers <dag@wieers.com>
+
@@ -0,0 +1,32 @@
+If you want to thank me because my packages have saved you already
+a lot of work, or if one of my tools is making your work much more
+enjoyable (or even indirectly got you a raise!) If people praise
+your wisdom, but you actually copied it directly from my website,
+you owe me bigtime :-)
+
+There are several ways you can thank me, and each of them will
+encourage me to try to do my best.
+
+ 1. The easiest and cheapest way for you to thank me is by sending
+ a lousy email with a small thank you. I enjoy if people take the
+ time for that.
+
+ 2. Another way of thanking me is to help other people on one of the
+ related mailinglists so I don't have to. You will not only earn
+ my respect, but also be regarded highly by others.
+
+ 3. A much better way to thank me is to think about what improvements
+ I could make to my packages or tools and add that to your
+ Thank-you email. Again, you will help others too and end up in
+ a wall-of-fame changelog.
+
+ 4. And the final way to thank me and making my time packaging and
+ developing stuff more worthwhile, is by picking something from
+ my Amazon wishlist. This will not only keep me happy, but it may
+ convince relatives of the worthy cause that is eating all my free
+ time.
+
+ http://dag.wieers.com/personal/wishlist.php
+ http://www.amazon.co.uk/gp/registry/registry.html/202-4247851-9308633?id=2684V6SI0NLN0
+
+Also a combination of these earns you some extra karma points ! :-)
177 unoconv
@@ -0,0 +1,177 @@
+#!/usr/bin/python
+
+import getopt, sys, os
+
+if os.path.isfile('/usr/lib/openoffice.org2.0/program/pyuno.so'):
+ sys.path.append('/usr/lib/openoffice.org2.0/program/')
+else:
+ print >>sys.stderr, "Error: Cannot find the pyuno.so library."
+ print >>sys.stderr, "Please locate this library and send feedback to <tools@lists.rpmforge.net>."
+ sys.exit(1)
+
+import uno, unohelper
+from com.sun.star.beans import PropertyValue
+from com.sun.star.uno import Exception as UnoException
+from com.sun.star.io import IOException, XOutputStream
+from com.sun.star.connection import NoConnectException
+
+class Fmt:
+ def __init__(self, name, extension, filter, summary):
+ self.name = name
+ self.extension = extension
+ self.filter = filter
+ self.summary = summary
+
+class FmtList:
+ def __init__(self):
+ self.list = []
+ def add(self, name, extension, filter, summary):
+ self.list.append(Fmt(name, extension, filter, summary))
+ def byextension(self, extension):
+ for fmt in self.list:
+ if extension == fmt.extension:
+ return fmt
+ def byname(self, name):
+ for fmt in self.list:
+ if name == fmt.name:
+ return fmt
+ def search(self, keyword):
+ pass
+ def display(self):
+ for fmt in self.list:
+ print >>sys.stderr, " %-8s - %s (.%s)" % (fmt.name, fmt.summary, fmt.extension)
+
+class OutputStream( unohelper.Base, XOutputStream ):
+ def __init__( self ):
+ self.closed = 0
+ def closeOutput(self):
+ self.closed = 1
+ def writeBytes( self, seq ):
+ sys.stdout.write( seq.value )
+ def flush( self ):
+ pass
+
+outputmap = FmtList()
+outputmap.add('doc', 'doc', 'MS Word 97', 'Microsoft Word 97/2000/XP')
+outputmap.add('doc95', 'doc', 'MS Word 95', 'Microsoft Word 95')
+outputmap.add('docbook', 'xml', 'DocBook 5.0', 'DocBook')
+outputmap.add('html', 'html', 'HTML (StarWriter)', 'HTML')
+outputmap.add('ooxml', 'xml', 'MS Word 2003 XML', 'Microsoft Office Open XML')
+outputmap.add('pdf', 'pdf', 'writer_pdf_Export', 'Portable Document Format')
+outputmap.add('rtf', 'rtf', 'Rich Text Format', 'Rich Text Format')
+outputmap.add('sdw', 'sdw', 'StarWriter 5.0', 'StarWriter 5.0')
+outputmap.add('sdw4', 'sdw', 'StarWriter 4.0', 'StarWriter 4.0')
+outputmap.add('sdw3', 'sdw', 'StarWriter 3.0', 'StarWriter 3.0')
+outputmap.add('sxw', 'sxw', 'Open Office.org 1.0', 'Open Office.org 1.0 Text Document')
+outputmap.add('txt', 'txt', 'Text (Encoded)', 'Plain text')
+
+def usage():
+ print >>sys.stderr, 'usage: unoconv [options] <fmt> file1 file2'
+
+def help():
+ print >>sys.stderr, '''Convert from and to any format supported by OpenOffice
+
+unoconv options:
+ -c, --connection=<conn> use a custom connection string
+ -e, --extension=ext specify custom extension
+ -f, --format=format specify the format to convert to
+ -s, --stdout write output to stdout
+'''
+
+args = sys.argv[1:]
+stdout = False
+format = 'pdf'
+server = 'localhost'
+port = '2002'
+connection = "uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (server, port)
+
+try:
+ opts, args = getopt.getopt (args, 'c:e:f:hs',
+ ['connection:', 'extension:', 'format:', 'help', 'stdout'] )
+except getopt.error, exc:
+ print >>sys.stderr, 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
+ sys.exit(1)
+
+for opt, arg in opts:
+ if opt in ['-h', '--help']:
+ help()
+ sys.exit(1)
+ elif opt in ['-c', '--connection']:
+ connection = arg
+ elif opt in ['-f', '--format']:
+ format = arg
+ elif opt in ['-s', '--stdout']:
+ stdout = True
+
+if not args:
+ print >>sys.stderr, 'You have to provide a file to convert.'
+ sys.exit(1)
+
+if format == 'list':
+ print >>sys.stderr, 'The following list of formats are currently available:'
+ print >>sys.stderr
+ outputmap.display()
+ print >>sys.stderr
+ sys.exit(1)
+
+outputfmt = outputmap.byname(format)
+if not outputfmt:
+ print >>sys.stderr, 'Format is not known to unoconv.'
+ sys.exit(1)
+
+rc = 0
+
+try:
+ context = uno.getComponentContext()
+ svcmgr = context.ServiceManager
+
+ resolver = svcmgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
+ unocontext = resolver.resolve(connection)
+ unosvcmgr = unocontext.ServiceManager
+
+ desktop = unosvcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", unocontext)
+ cwd = unohelper.systemPathToFileUrl( os.getcwd() )
+
+ inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
+ outProps = (
+ PropertyValue( "FilterName" , 0, outputfmt.filter , 0 ),
+ PropertyValue( "Overwrite" , 0, True , 0 ),
+ PropertyValue( "OutputStream", 0, OutputStream(), 0)
+ )
+
+ for path in args:
+ try:
+ filename = unohelper.absolutize(cwd, unohelper.systemPathToFileUrl(path))
+ doc = desktop.loadComponentFromURL( filename , "_blank", 0, inProps )
+
+ if not doc:
+ raise UnoException( "Couldn't open stream for unknown reason", None )
+
+ if not stdout:
+ (dest, ext) = os.path.splitext(path)
+ dest = dest + "." + outputfmt.extension
+ destUrl = unohelper.absolutize( cwd, unohelper.systemPathToFileUrl(dest) )
+ sys.stderr.write(destUrl + "\n")
+ doc.storeToURL(destUrl, outProps)
+ else:
+ doc.storeToURL("private:stream", outProps)
+
+ except IOException, e:
+ print >>sys.stderr, "Error during conversion: %s" % e.Message
+ sys.exit(1)
+ except UnoException, e:
+ print >>sys.stderr, "Error (%s) during conversion: %s" % (repr(e.__class__), e.Message)
+ rc = 1
+ if doc:
+ doc.dispose()
+
+except NoConnectException, e:
+ print >>sys.stderr, "Error: Could not find an existing connection to Open Office."
+ print >>sys.stderr, "Please start an oowriter instance by doing:\n oowriter \"-accept=socket,host=%s,port=%s;urp;\"" % (server, port)
+ sys.exit(1)
+
+except UnoException, e:
+ print >>sys.stderr, "Error (%s) : %s" % (repr(e.__class__), e.Message)
+ sys.exit(1)
+
+sys.exit(rc)
@@ -0,0 +1,46 @@
+# $Id$
+# Authority: dag
+# Upstream: Dag Wieers <dag$wieers,com>
+
+Summary: Convert any document to any document supported by OpenOffice
+Name: unoconv
+Version: 0.1
+Release: 1
+License: GPL
+Group: System Environment/Base
+URL: http://dag.wieers.com/home-made/unoconv/
+
+Packager: Dag Wieers <dag@wieers.com>
+Vendor: Dag Apt Repository, http://dag.wieers.com/apt/
+
+Source: http://dag.wieers.com/home-made/unoconv/unoconv-%{version}.tar.bz2
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+
+BuildArch: noarch
+BuildRequires: python-devel, openoffice-core
+Requires: python >= 2.0
+
+%description
+unoconv converts any document format that OpenOffice can import, to any
+document format that OpenOffice can export.
+
+%prep
+%setup
+
+%build
+
+%install
+%{__rm} -rf %{buildroot}
+%{__make} install DESTDIR="%{buildroot}"
+
+%clean
+%{__rm} -rf %{buildroot}
+
+%files
+%defattr(-, root, root, 0755)
+%doc AUTHORS ChangeLog COPYING README THANKS TODO WISHLIST
+%{_bindir}/unoconv
+
+%changelog
+* Sat May 19 2007 Dag Wieers <dag@wieers.com> - 0.1-1
+- Initial package. (using DAR)

0 comments on commit 5ab3cbe

Please sign in to comment.