1 From fc59dd90f03cf88f4cf16c07204809f2239284ee Mon Sep 17 00:00:00 2001
2 From: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
3 Date: Thu, 20 Dec 2012 00:02:53 +0100
4 Subject: [PATCH] Add support for python3
6 Libreoffice 4.0 will switch its internal python version to 3.3.0
7 so it's to support that.
9 Porting done automatically 2to3 plus print_function import added
10 manually. Tested on both libreoffice master with internal python
11 and with libreoffince 3.6.4 on debian with system python 2.7.
13 This bumps the minimal python version to 2.6 since 2.5 does not
14 have the print function.
16 unoconv | 124 +++++++++++++++++++++++++++++++++-------------------------------
17 1 file changed, 63 insertions(+), 61 deletions(-)
19 diff --git a/unoconv b/unoconv
20 index 30e6706..f72cf08 100755
24 -#!/usr/bin/env python
25 +#!/usr/bin/env python3
27 ### This program is free software; you can redistribute it and/or modify
28 ### it under the terms of the GNU General Public License as published by
30 ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 ### Copyright 2007-2010 Dag Wieers <dag@wieers.com>
33 +from __future__ import print_function
35 from distutils.version import LooseVersion
38 @@ -77,11 +79,11 @@ def find_offices():
41 if os.name in ( 'nt', 'os2' ):
42 - if 'PROGRAMFILES' in os.environ.keys():
43 + if 'PROGRAMFILES' in list(os.environ.keys()):
44 extrapaths += glob.glob(os.environ['PROGRAMFILES']+'\\LibreOffice*') + \
45 glob.glob(os.environ['PROGRAMFILES']+'\\OpenOffice.org*')
47 - if 'PROGRAMFILES(X86)' in os.environ.keys():
48 + if 'PROGRAMFILES(X86)' in list(os.environ.keys()):
49 extrapaths += glob.glob(os.environ['PROGRAMFILES(X86)']+'\\LibreOffice*') + \
50 glob.glob(os.environ['PROGRAMFILES(X86)']+'\\OpenOffice.org*')
52 @@ -233,18 +235,18 @@ def office_environ(office):
55 if 'URE_BOOTSTRAP' in os.environ:
56 - print >>sys.stderr, 'URE_BOOTSTRAP=%s' % os.environ['URE_BOOTSTRAP']
57 + print('URE_BOOTSTRAP=%s' % os.environ['URE_BOOTSTRAP'], file=sys.stderr)
58 if 'UNO_PATH' in os.environ:
59 - print >>sys.stderr, 'UNO_PATH=%s' % os.environ['UNO_PATH']
60 + print('UNO_PATH=%s' % os.environ['UNO_PATH'], file=sys.stderr)
61 if 'UNO_TYPES' in os.environ:
62 - print >>sys.stderr, 'UNO_TYPES=%s' % os.environ['UNO_TYPES']
63 - print 'PATH=%s' % os.environ['PATH']
64 + print('UNO_TYPES=%s' % os.environ['UNO_TYPES'], file=sys.stderr)
65 + print('PATH=%s' % os.environ['PATH'])
66 if 'PYTHONHOME' in os.environ:
67 - print >>sys.stderr, 'PYTHONHOME=%s' % os.environ['PYTHONHOME']
68 + print('PYTHONHOME=%s' % os.environ['PYTHONHOME'], file=sys.stderr)
69 if 'PYTHONPATH' in os.environ:
70 - print >>sys.stderr, 'PYTHONPATH=%s' % os.environ['PYTHONPATH']
71 + print('PYTHONPATH=%s' % os.environ['PYTHONPATH'], file=sys.stderr)
72 if 'LD_LIBRARY_PATH' in os.environ:
73 - print >>sys.stderr, 'LD_LIBRARY_PATH=%s' % os.environ['LD_LIBRARY_PATH']
74 + print('LD_LIBRARY_PATH=%s' % os.environ['LD_LIBRARY_PATH'], file=sys.stderr)
76 def python_switch(office):
78 @@ -335,11 +337,11 @@ class FmtList:
81 def display(self, doctype):
82 - print >>sys.stderr, "The following list of %s formats are currently available:\n" % doctype
83 + print("The following list of %s formats are currently available:\n" % doctype, file=sys.stderr)
85 if fmt.doctype == doctype:
86 - print >>sys.stderr, " %-8s - %s" % (fmt.name, fmt)
88 + print(" %-8s - %s" % (fmt.name, fmt), file=sys.stderr)
89 + print(file=sys.stderr)
93 @@ -530,14 +532,14 @@ class Options:
94 'outputpath', 'password=', 'pipe=', 'port=', 'server=',
95 'timeout=', 'show', 'stdout', 'template', 'verbose',
97 - except getopt.error, exc:
98 - print 'unoconv: %s, try unoconv -h for a list of all the options' % str(exc)
99 + except getopt.error as exc:
100 + print('unoconv: %s, try unoconv -h for a list of all the options' % str(exc))
103 for opt, arg in opts:
104 if opt in ['-h', '--help']:
110 elif opt in ['-c', '--connection']:
111 @@ -562,7 +564,7 @@ class Options:
113 self.exportfilter.append( PropertyValue( name, 0, value, 0 ) )
115 - print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
116 + print('Warning: Option %s cannot be parsed, ignoring.' % arg, file=sys.stderr)
117 elif opt in ['-f', '--format']:
119 elif opt in ['-i', '--import']:
120 @@ -581,7 +583,7 @@ class Options:
122 self.importfilter.append( PropertyValue( name, 0, value, 0 ) )
124 - print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
125 + print('Warning: Option %s cannot be parsed, ignoring.' % arg, file=sys.stderr)
126 elif opt in ['-l', '--listener']:
128 elif opt in ['-n', '--no-launch']:
129 @@ -589,7 +591,7 @@ class Options:
130 elif opt in ['-o', '--output']:
132 elif opt in ['--outputpath']:
133 - print >>sys.stderr, 'Warning: This option is deprecated by --output.'
134 + print('Warning: This option is deprecated by --output.', file=sys.stderr)
136 elif opt in ['--password']:
138 @@ -615,13 +617,13 @@ class Options:
141 if self.verbose >= 2:
142 - print >>sys.stderr, 'Verbosity set to level %d' % self.verbose
143 + print('Verbosity set to level %d' % self.verbose, file=sys.stderr)
145 self.filenames = args
147 if not self.listener and not self.showlist and self.doctype != 'list' and not self.filenames:
148 - print >>sys.stderr, 'unoconv: you have to provide a filename as argument'
149 - print >>sys.stderr, 'Try `unoconv -h\' for more information.'
150 + print('unoconv: you have to provide a filename as argument', file=sys.stderr)
151 + print('Try `unoconv -h\' for more information.', file=sys.stderr)
154 ### Set connection string
155 @@ -659,21 +661,21 @@ class Options:
156 ### Get office product information
157 product = uno.getComponentContext().ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
159 - print 'unoconv %s' % VERSION
160 - print 'Written by Dag Wieers <dag@wieers.com>'
161 - print 'Homepage at http://dag.wieers.com/home-made/unoconv/'
163 - print 'platform %s/%s' % (os.name, sys.platform)
164 - print 'python %s' % sys.version
165 - print product.ooName, product.ooSetupVersion
166 + print('unoconv %s' % VERSION)
167 + print('Written by Dag Wieers <dag@wieers.com>')
168 + print('Homepage at http://dag.wieers.com/home-made/unoconv/')
170 + print('platform %s/%s' % (os.name, sys.platform))
171 + print('python %s' % sys.version)
172 + print(product.ooName, product.ooSetupVersion)
174 # print 'build revision $Rev$'
177 - print >>sys.stderr, 'usage: unoconv [options] file [file2 ..]'
178 + print('usage: unoconv [options] file [file2 ..]', file=sys.stderr)
181 - print >>sys.stderr, '''Convert from and to any format supported by LibreOffice
182 + print('''Convert from and to any format supported by LibreOffice
185 -c, --connection=string use a custom connection string
186 @@ -698,7 +700,7 @@ unoconv options:
187 -t, --template=file import the styles from template (.ott)
188 -T, --timeout=secs timeout after secs if connection to listener fails
189 -v, --verbose be more and more verbose (-vvv for debugging)
191 +''', file=sys.stderr)
195 @@ -714,7 +716,7 @@ class Convertor:
196 info(3, 'Connection type: %s' % op.connection)
198 unocontext = resolver.resolve("uno:%s" % op.connection)
199 - except NoConnectException, e:
200 + except NoConnectException as e:
201 # info(3, "Existing listener not found.\n%s" % e)
202 info(3, "Existing listener not found.")
204 @@ -749,7 +751,7 @@ class Convertor:
207 error("Failed to connect to %s (pid=%s) in %d seconds.\n%s" % (office.binary, ooproc.pid, op.timeout, e))
208 - except Exception, e:
209 + except Exception as e:
211 error("Launch of %s failed.\n%s" % (office.binary, e))
213 @@ -799,9 +801,9 @@ class Convertor:
214 ### No format found, throw error
217 - print >>sys.stderr, 'unoconv: format [%s/%s] is not known to unoconv.' % (op.doctype, op.format)
218 + print('unoconv: format [%s/%s] is not known to unoconv.' % (op.doctype, op.format), file=sys.stderr)
220 - print >>sys.stderr, 'unoconv: format [%s] is not known to unoconv.' % op.format
221 + print('unoconv: format [%s] is not known to unoconv.' % op.format, file=sys.stderr)
225 @@ -813,10 +815,10 @@ class Convertor:
226 outputfmt = self.getformat(inputfn)
229 - print >>sys.stderr, 'Input file:', inputfn
230 + print('Input file:', inputfn, file=sys.stderr)
232 if not os.path.exists(inputfn):
233 - print >>sys.stderr, 'unoconv: file `%s\' does not exist.' % inputfn
234 + print('unoconv: file `%s\' does not exist.' % inputfn, file=sys.stderr)
238 @@ -854,7 +856,7 @@ class Convertor:
239 templateurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(op.template))
240 document.StyleFamilies.loadStylesFromURL(templateurl, templateprops)
242 - print >>sys.stderr, 'unoconv: template file `%s\' does not exist.' % op.template
243 + print('unoconv: template file `%s\' does not exist.' % op.template, file=sys.stderr)
246 ### Update document links
247 @@ -924,40 +926,40 @@ class Convertor:
250 document.storeToURL(outputurl, tuple(outputprops) )
251 - except IOException, e:
252 + except IOException as e:
253 raise UnoException("Unable to store document to %s (ErrCode %d)\n\nProperties: %s" % (outputurl, e.ErrCode, outputprops), None)
259 - except SystemError, e:
260 + except SystemError as e:
261 error("unoconv: SystemError during %s phase:\n%s" % (phase, e))
264 - except RuntimeException, e:
265 + except RuntimeException as e:
266 error("unoconv: RuntimeException during %s phase:\nOffice probably died. %s" % (phase, e))
269 - except DisposedException, e:
270 + except DisposedException as e:
271 error("unoconv: DisposedException during %s phase:\nOffice probably died. %s" % (phase, e))
274 - except IllegalArgumentException, e:
275 + except IllegalArgumentException as e:
276 error("UNO IllegalArgument during %s phase:\nSource file cannot be read. %s" % (phase, e))
279 - except IOException, e:
280 + except IOException as e:
281 # for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
282 error("unoconv: IOException during %s phase:\n%s" % (phase, e.Message))
285 - except CannotConvertException, e:
286 + except CannotConvertException as e:
287 # for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
288 error("unoconv: CannotConvertException during %s phase:\n%s" % (phase, e.Message))
291 - except UnoException, e:
292 + except UnoException as e:
293 if hasattr(e, 'ErrCode'):
294 error("unoconv: UnoException during %s phase in %s (ErrCode %d)" % (phase, repr(e.__class__), e.ErrCode))
296 @@ -982,7 +984,7 @@ class Listener:
297 product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
299 unocontext = resolver.resolve("uno:%s" % op.connection)
300 - except NoConnectException, e:
301 + except NoConnectException as e:
304 info(1, "Existing %s listener found, nothing to do." % product.ooName)
305 @@ -991,25 +993,25 @@ class Listener:
306 subprocess.call([office.binary, "-headless", "-invisible", "-nocrashreport", "-nodefault", "-nologo", "-nofirststartwizard", "-norestore", "-accept=%s" % op.connection], env=os.environ)
308 subprocess.call([office.binary, "--headless", "--invisible", "--nocrashreport", "--nodefault", "--nologo", "--nofirststartwizard", "--norestore", "--accept=%s" % op.connection], env=os.environ)
309 - except Exception, e:
310 + except Exception as e:
311 error("Launch of %s failed.\n%s" % (office.binary, e))
313 info(1, "Existing %s listener found, nothing to do." % product.ooName)
316 "Output error message"
317 - print >>sys.stderr, msg
318 + print(msg, file=sys.stderr)
320 def info(level, msg):
321 "Output info message"
322 if 'op' not in globals():
324 elif op.verbose >= 3 and level >= 3:
325 - print >>sys.stderr, "DEBUG:", msg
326 + print("DEBUG:", msg, file=sys.stderr)
327 elif not op.stdout and level <= op.verbose:
328 - print >>sys.stdout, msg
329 + print(msg, file=sys.stdout)
330 elif level <= op.verbose:
331 - print >>sys.stderr, msg
332 + print(msg, file=sys.stderr)
334 def die(ret, msg=None):
335 "Print optional error and exit with errorcode"
336 @@ -1031,7 +1033,7 @@ def die(ret, msg=None):
337 subprocess.Popen([office.binary, "--headless", "--invisible", "--nocrashreport", "--nodefault", "--nofirststartwizard", "--nologo", "--norestore", "--unaccept=%s" % op.connection], env=os.environ)
339 info(2, '%s listener successfully disabled.' % product.ooName)
340 - except Exception, e:
341 + except Exception as e:
342 error("Terminate using %s failed.\n%s" % (office.binary, e))
344 ### If there is no GUI attached to the instance, terminate instance
345 @@ -1080,7 +1082,7 @@ def main():
346 for inputfn in op.filenames:
347 convertor.convert(inputfn)
349 - except NoConnectException, e:
350 + except NoConnectException as e:
351 error("unoconv: could not find an existing connection to LibreOffice at %s:%s." % (op.server, op.port))
353 info(0, "Please start an LibreOffice instance on server '%s' by doing:\n\n unoconv --listener --server %s --port %s\n\nor alternatively:\n\n soffice -nologo -nodefault -accept=\"%s\"" % (op.server, op.server, op.port, op.connection))
354 @@ -1110,14 +1112,14 @@ if __name__ == '__main__':
358 - print >>sys.stderr, "unoconv: Cannot find a suitable pyuno library and python binary combination in %s" % of
359 - print >>sys.stderr, "ERROR:", sys.exc_info()[1]
361 + print("unoconv: Cannot find a suitable pyuno library and python binary combination in %s" % of, file=sys.stderr)
362 + print("ERROR:", sys.exc_info()[1], file=sys.stderr)
363 + print(file=sys.stderr)
366 - print >>sys.stderr, "unoconv: Cannot find a suitable office installation on your system."
367 - print >>sys.stderr, "ERROR: Please locate your office installation and send your feedback to:"
368 - print >>sys.stderr, " http://github.com/dagwieers/unoconv/issues"
369 + print("unoconv: Cannot find a suitable office installation on your system.", file=sys.stderr)
370 + print("ERROR: Please locate your office installation and send your feedback to:", file=sys.stderr)
371 + print(" http://github.com/dagwieers/unoconv/issues", file=sys.stderr)
374 ### Now that we have found a working pyuno library, let's import some classes
375 @@ -1160,6 +1162,6 @@ if __name__ == '__main__':
379 - except KeyboardInterrupt, e:
380 + except KeyboardInterrupt as e:
381 die(6, 'Exiting on user request')
386 Hide changes when converting a document. Closes: #624295.
388 diff --git a/unoconv b/unoconv
389 index 972e962..dd43884 100755
392 @@ -882,6 +882,11 @@ class Convertor:
393 info(2, "Selected office filter: %s" % outputfmt.filter)
394 info(2, "Used doctype: %s" % outputfmt.doctype)
396 + ### Document properties phase
397 + phase = "properties"
398 + if hasattr(document, 'ShowChanges'):
399 + document.ShowChanges = False
404 Description: Fix spelling errors in unoconv.1
405 Forwarded: https://github.com/dagwieers/unoconv/pull/117
406 Author: Vincent Bernat <bernat@debian.org>
407 Last-Update: 2013-02-18
409 Index: unoconv-0.6/doc/unoconv.1
410 ===================================================================
411 --- unoconv-0.6.orig/doc/unoconv.1 2013-02-18 17:04:12.127613761 +1300
412 +++ unoconv-0.6/doc/unoconv.1 2013-02-18 17:04:33.479614342 +1300
417 -For a list of posible encoding types, you can use the above link to find the possible options\&.
418 +For a list of possible encoding types, you can use the above link to find the possible options\&.
426 -For a list of posible encoding types, you can use the above link to find the possible options\&.
427 +For a list of possible encoding types, you can use the above link to find the possible options\&.
435 -For a list of posible encoding types, you can use the above link to find the possible options\&.
436 +For a list of possible encoding types, you can use the above link to find the possible options\&.
440 Index: unoconv-0.6/doc/unoconv.1.txt
441 ===================================================================
442 --- unoconv-0.6.orig/doc/unoconv.1.txt 2013-02-18 17:04:12.127613761 +1300
443 +++ unoconv-0.6/doc/unoconv.1.txt 2013-02-18 17:04:42.235614582 +1300
448 -For a list of posible encoding types, you can use the above link to find the
449 +For a list of possible encoding types, you can use the above link to find the
455 -i FilterOptions=9/32,,9,2
457 -For a list of posible encoding types, you can use the above link to find the
458 +For a list of possible encoding types, you can use the above link to find the
464 -e FilterOptions=9/32,,9
466 -For a list of posible encoding types, you can use the above link to find the
467 +For a list of possible encoding types, you can use the above link to find the
471 From: Caolán McNamara <caolanm@redhat.com>
472 Subject: Fix "can't write bytes direct to stdout in python3"
473 Origin: https://github.com/caolanm/unoconv/commit/3249fd3df136f1a859ac0272f75fcbf010926d58
474 Forwarded: https://github.com/dagwieers/unoconv/pull/170
476 diff --git a/unoconv b/unoconv
477 index a4f9490..2b0b0eb 100755
480 @@ -1146,7 +1146,7 @@ if __name__ == '__main__':
483 def writeBytes( self, seq ):
484 - sys.stdout.write( seq.value )
485 + sys.stdout.buffer.write( seq.value )
492 From a59b9b05824868266dc0bc82518132942821515e Mon Sep 17 00:00:00 2001
493 From: Josias Montag <josias@montag.info>
494 Date: Wed, 14 Aug 2013 12:51:04 +0200
495 Subject: [PATCH] add Microsoft Works (.wps) import filter
499 1 file changed, 1 insertion(+)
501 diff --git a/unoconv b/unoconv
502 index a4f9490..7a4b89c 100755
505 @@ -375,6 +375,7 @@ fmts.add('document', 'uot', 'uot', 'Unified Office Format text','UOF text') ###
506 fmts.add('document', 'vor', 'vor', 'StarWriter 5.0 Template', 'StarWriter 5.0 Vorlage/Template') ### 6
507 fmts.add('document', 'vor4', 'vor', 'StarWriter 4.0 Template', 'StarWriter 4.0 Vorlage/Template') ### 5
508 fmts.add('document', 'vor3', 'vor', 'StarWriter 3.0 Template', 'StarWriter 3.0 Vorlage/Template') ### 4
509 +fmts.add('document', 'wps', 'wps', 'Microsoft Works', 'MS_Works')
510 fmts.add('document', 'xhtml', 'html', 'XHTML Document', 'XHTML Writer File') ### 33
516 From 20b34c08622089c6b081c602a6428d6009aec0a3 Mon Sep 17 00:00:00 2001
517 From: Josias Montag <josias@montag.info>
518 Date: Tue, 7 May 2013 12:40:47 +0300
519 Subject: [PATCH] Add XLSX support
521 add the 'Calc MS Excel 2007 XML' (XLSX) export filter
524 1 file changed, 1 insertion(+)
526 diff --git a/unoconv b/unoconv
527 index 30e6706..ea18a38 100755
530 @@ -419,6 +419,7 @@ fmts.add('spreadsheet', 'xls95', 'xls', 'Microsoft Excel 95', 'MS Excel 95') ###
531 fmts.add('spreadsheet', 'xlt', 'xlt', 'Microsoft Excel 97/2000/XP Template', 'MS Excel 97 Vorlage/Template') ### 6
532 fmts.add('spreadsheet', 'xlt5', 'xlt', 'Microsoft Excel 5.0 Template', 'MS Excel 5.0/95 Vorlage/Template') ### 28
533 fmts.add('spreadsheet', 'xlt95', 'xlt', 'Microsoft Excel 95 Template', 'MS Excel 95 Vorlage/Template') ### 21
534 +fmts.add('spreadsheet', 'xlsx', 'xlsx', 'Microsoft Excel 2007/2010 XML', 'Calc MS Excel 2007 XML')
537 fmts.add('graphics', 'bmp', 'bmp', 'Windows Bitmap', 'draw_bmp_Export') ### 21