File unoconv-output-argument.patch of Package unoconv

From 9b3cf1bab1859743d4e59a691aa56d3b3e954fe0 Mon Sep 17 00:00:00 2001
From: Dag Wieers <dag@wieers.com>
Date: Mon, 25 Oct 2010 08:46:13 +0000
Subject: [PATCH] Change to how -o/--output/--outputpath works (can now output
 to filenames too)

(patch tweaked to apply)

--- a/docs/unoconv.1.txt
+++ b/docs/unoconv.1.txt
@@ -60,8 +60,11 @@ connections or even for remote connections.
 -l, --listener::
     Start unoconv as listener for unoconv clients to connect to.
 
--o, --outputpath::
-    Directory to put converted documents.
+-o, --output::
+    If the argument is a directory, put the converted documents in this
+    directory. If multiple input files are provided, use it as a 
+    basename (and add output extension). Otherwise use it as the
+    output filename.
 
 --pipe::
     Use a pipe as an alternative connection mechanism to talk to OpenOffice.

diff --git a/unoconv b/unoconv
index 239c261..2c8f620 100755
--- a/unoconv
+++ b/unoconv
@@ -333,7 +333,7 @@ class Options:
         self.format = None
         self.importfilter = ""
         self.listener = False
-        self.outputpath = None
+        self.output = None
         self.pipe = None
         self.port = '2002'
         self.server = 'localhost'
@@ -347,9 +347,9 @@ class Options:
         try:
             opts, args = getopt.getopt (args, 'c:d:e:f:hi:Llo:p:s:t:T:v',
                 ['connection=', 'doctype=', 'export', 'format=', 'help',
-                 'import', 'listener', 'outputpath=', 'pipe=', 'port=',
-                 'server=', 'timeout=', 'show', 'stdout', 'template',
-                 'verbose', 'version'] )
+                 'import', 'listener', 'output=', 'outputpath', 'pipe=',
+                 'port=', 'server=', 'timeout=', 'show', 'stdout',
+                 'template', 'verbose', 'version'] )
         except getopt.error, exc:
             print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
             sys.exit(255)
@@ -382,8 +382,11 @@ class Options:
                 self.importfilter = arg
             elif opt in ['-l', '--listener']:
                 self.listener = True
-            elif opt in ['-o', '--outputpath']:
-                self.outputpath = arg
+            elif opt in ['-o', '--output']:
+                self.output = arg
+            elif opt in ['--outputpath']:
+                print >>sys.stderr, 'Warning: This option is deprecated by --output.' % arg
+                self.output = arg
             elif opt in ['--pipe']:
                 self.pipe = arg
             elif opt in ['-p', '--port']:
@@ -474,7 +477,7 @@ unoconv options:
   -i, --import=string      set import filter option string
                              eg. -i utf8
   -l, --listener           start a listener to use by unoconv clients
-  -o, --outputpath=name    output directory
+  -o, --output=name        output basename, filename or directory
       --pipe=name          alternative method of connection using a pipe
   -p, --port=port          specify the port (default: 2002)
                              to be used by client or listener
@@ -656,10 +659,15 @@ class Convertor:
 
             if not op.stdout:
                 (outputfn, ext) = os.path.splitext(inputfn)
-                if not op.outputpath:
+                if not op.output:
                     outputfn = outputfn + os.extsep + outputfmt.extension
+                elif os.path.isdir(op.output):
+                    outputfn = os.path.join(op.output, os.path.basename(outputfn) + os.extsep + outputfmt.extension)
+                elif len(op.filenames) > 1:
+                    outputfn = op.output + os.extsep + outputfmt.extension
                 else:
-                    outputfn = os.path.join(op.outputpath, os.path.basename(outputfn) + os.extsep + outputfmt.extension)
+                    outputfn = op.output
+
                 outputurl = unohelper.absolutize( self.cwd, unohelper.systemPathToFileUrl(outputfn) )
                 doc.storeToURL(outputurl, tuple(outputprops) )
                 info(1, "Output file: %s" % outputfn)
openSUSE Build Service is sponsored by