unoconv/0001-python3-added-compatibility.2.patch
2014-04-19 12:29:35 +02:00

384 lines
19 KiB
Diff

From 34bbe9fa679d39921fd67002e01e7a9bf93b009a Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Sat, 19 Apr 2014 12:05:04 +0200
Subject: [PATCH] 0001-python3-added-compatibility.2.patch
---
unoconv | 142 +++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 86 insertions(+), 56 deletions(-)
diff --git a/unoconv b/unoconv
index 30e6706..8c45ad9 100755
--- a/unoconv
+++ b/unoconv
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
@@ -203,7 +203,7 @@ def office_environ(office):
### Set UNO_PATH so that "officehelper.bootstrap()" can find soffice executable:
os.environ['UNO_PATH'] = office.unopath
- ### Set URE_BOOTSTRAP so that "uno.getComponentContext()" bootstraps a complete
+ ### Set URE_BOOTSTRAP so that "global_uno.getComponentContext()" bootstraps a complete
### UNO environment
if os.name in ( 'nt', 'os2' ):
os.environ['URE_BOOTSTRAP'] = 'vnd.sun.star.pathname:' + realpath(office.basepath, 'program', 'fundamental.ini')
@@ -277,6 +277,7 @@ def python_switch(office):
try:
os.execvpe(office.python, [office.python, ] + sys.argv[0:], os.environ)
+ print(office.python, [office.python, ] + sys.argv[0:], osenviron)
except OSError:
### Mac OS X versions prior to 10.6 do not support execv in
### a process that contains multiple threads. Instead of
@@ -553,14 +554,14 @@ class Options:
if name in ('FilterOptions'):
self.exportfilteroptions = value
elif value in ('True', 'true'):
- self.exportfilter.append( PropertyValue( name, 0, True, 0 ) )
+ self.exportfilter.append( UnoPropertyValue( name, 0, True, 0 ) )
elif value in ('False', 'false'):
- self.exportfilter.append( PropertyValue( name, 0, False, 0 ) )
+ self.exportfilter.append( UnoPropertyValue( name, 0, False, 0 ) )
else:
try:
- self.exportfilter.append( PropertyValue( name, 0, int(value), 0 ) )
+ self.exportfilter.append( UnoPropertyValue( name, 0, int(value), 0 ) )
except ValueError:
- self.exportfilter.append( PropertyValue( name, 0, value, 0 ) )
+ self.exportfilter.append( UnoPropertyValue( name, 0, value, 0 ) )
else:
print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
elif opt in ['-f', '--format']:
@@ -572,14 +573,14 @@ class Options:
if name in ('FilterOptions'):
self.importfilteroptions = value
elif value in ('True', 'true'):
- self.importfilter.append( PropertyValue( name, 0, True, 0 ) )
+ self.importfilter.append( UnoPropertyValue( name, 0, True, 0 ) )
elif value in ('False', 'false'):
- self.importfilter.append( PropertyValue( name, 0, False, 0 ) )
+ self.importfilter.append( UnoPropertyValue( name, 0, False, 0 ) )
else:
try:
- self.importfilter.append( PropertyValue( name, 0, int(value), 0 ) )
+ self.importfilter.append( UnoPropertyValue( name, 0, int(value), 0 ) )
except ValueError:
- self.importfilter.append( PropertyValue( name, 0, value, 0 ) )
+ self.importfilter.append( UnoPropertyValue( name, 0, value, 0 ) )
else:
print >>sys.stderr, 'Warning: Option %s cannot be parsed, ignoring.' % arg
elif opt in ['-l', '--listener']:
@@ -657,7 +658,7 @@ class Options:
def version(self):
### Get office product information
- product = uno.getComponentContext().ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
+ product = global_uno.getComponentContext().ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
print 'unoconv %s' % VERSION
print 'Written by Dag Wieers <dag@wieers.com>'
@@ -706,7 +707,7 @@ class Convertor:
unocontext = None
### Do the LibreOffice component dance
- self.context = uno.getComponentContext()
+ self.context = global_uno.getComponentContext()
self.svcmgr = self.context.ServiceManager
resolver = self.svcmgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.context)
@@ -714,7 +715,7 @@ class Convertor:
info(3, 'Connection type: %s' % op.connection)
try:
unocontext = resolver.resolve("uno:%s" % op.connection)
- except NoConnectException, e:
+ except UnoNoConnectException, e:
# info(3, "Existing listener not found.\n%s" % e)
info(3, "Existing listener not found.")
@@ -724,7 +725,7 @@ class Convertor:
### Start our own OpenOffice instance
info(3, "Launching our own listener using %s." % office.binary)
try:
- product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
+ product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
if product.ooName != "LibreOffice" or LooseVersion(product.ooSetupVersion) <= LooseVersion('3.3'):
ooproc = subprocess.Popen([office.binary, "-headless", "-invisible", "-nocrashreport", "-nodefault", "-nofirststartwizard", "-nologo", "-norestore", "-accept=%s" % op.connection], env=os.environ)
else:
@@ -742,7 +743,7 @@ class Convertor:
try:
unocontext = resolver.resolve("uno:%s" % op.connection)
break
- except NoConnectException:
+ except UnoNoConnectException:
time.sleep(0.5)
timeout += 0.5
except:
@@ -759,7 +760,7 @@ class Convertor:
### And some more LibreOffice magic
unosvcmgr = unocontext.ServiceManager
self.desktop = unosvcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", unocontext)
- self.cwd = unohelper.systemPathToFileUrl( os.getcwd() )
+ self.cwd = global_unohelper.systemPathToFileUrl( os.getcwd() )
### List all filters
# self.filters = unosvcmgr.createInstanceWithContext( "com.sun.star.document.FilterFactory", unocontext)
@@ -824,22 +825,22 @@ class Convertor:
phase = "import"
### Load inputfile
- inputprops = UnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=QUIET_UPDATE)
+ inputprops = GlobalUnoProps(Hidden=True, ReadOnly=True, UpdateDocMode=UNO_QUIET_UPDATE)
# if op.password:
-# info = UnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
-# inputprops += UnoProps(ModifyPasswordInfo=info)
+# info = GlobalUnoProps(algorithm-name="PBKDF2", salt="salt", iteration-count=1024, hash="hash")
+# inputprops += GlobalUnoProps(ModifyPasswordInfo=info)
- ### Cannot use UnoProps for FilterData property
+ ### Cannot use GlobalUnoProps for FilterData property
if op.importfilteroptions:
# print "Import filter options: %s" % op.importfilteroptions
- inputprops += UnoProps(FilterOptions=op.importfilteroptions)
+ inputprops += GlobalUnoProps(FilterOptions=op.importfilteroptions)
- ### Cannot use UnoProps for FilterData property
+ ### Cannot use GlobalUnoProps for FilterData property
if op.importfilter:
- inputprops += ( PropertyValue( "FilterData", 0, uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.importfilter ), ), 0 ), )
+ inputprops += ( UnoPropertyValue( "FilterData", 0, global_uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.importfilter ), ), 0 ), )
- inputurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(inputfn))
+ inputurl = global_unohelper.absolutize(self.cwd, global_unohelper.systemPathToFileUrl(inputfn))
document = self.desktop.loadComponentFromURL( inputurl , "_blank", 0, inputprops )
if not document:
@@ -850,8 +851,8 @@ class Convertor:
if op.template:
if os.path.exists(op.template):
info(1, "Template file: %s" % op.template)
- templateprops = UnoProps(OverwriteStyles=True)
- templateurl = unohelper.absolutize(self.cwd, unohelper.systemPathToFileUrl(op.template))
+ templateprops = GlobalUnoProps(OverwriteStyles=True)
+ templateurl = global_unohelper.absolutize(self.cwd, global_unohelper.systemPathToFileUrl(op.template))
document.StyleFamilies.loadStylesFromURL(templateurl, templateprops)
else:
print >>sys.stderr, 'unoconv: template file `%s\' does not exist.' % op.template
@@ -885,26 +886,26 @@ class Convertor:
### Export phase
phase = "export"
- outputprops = UnoProps(FilterName=outputfmt.filter, OutputStream=OutputStream(), Overwrite=True)
+ outputprops = GlobalUnoProps(FilterName=outputfmt.filter, OutputStream=GlobalOutputStream(), Overwrite=True)
### Set default filter options
if op.exportfilteroptions:
# print "Export filter options: %s" % op.exportfilteroptions
- outputprops += UnoProps(FilterOptions=op.exportfilteroptions)
+ outputprops += GlobalUnoProps(FilterOptions=op.exportfilteroptions)
else:
if outputfmt.filter == 'Text (encoded)':
- outputprops += UnoProps(FilterOptions="76,LF")
+ outputprops += GlobalUnoProps(FilterOptions="76,LF")
elif outputfmt.filter == 'Text':
- outputprops += UnoProps(FilterOptions="76")
+ outputprops += GlobalUnoProps(FilterOptions="76")
elif outputfmt.filter == 'Text - txt - csv (StarCalc)':
- outputprops += UnoProps(FilterOptions="44,34,76")
+ outputprops += GlobalUnoProps(FilterOptions="44,34,76")
- ### Cannot use UnoProps for FilterData property
+ ### Cannot use GlobalUnoProps for FilterData property
if op.exportfilter:
- outputprops += ( PropertyValue( "FilterData", 0, uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.exportfilter ), ), 0 ), )
+ outputprops += ( UnoPropertyValue( "FilterData", 0, global_uno.Any("[]com.sun.star.beans.PropertyValue", tuple( op.exportfilter ), ), 0 ), )
if not op.stdout:
(outputfn, ext) = os.path.splitext(inputfn)
@@ -917,14 +918,14 @@ class Convertor:
else:
outputfn = op.output
- outputurl = unohelper.absolutize( self.cwd, unohelper.systemPathToFileUrl(outputfn) )
+ outputurl = global_unohelper.absolutize( self.cwd, global_unohelper.systemPathToFileUrl(outputfn) )
info(1, "Output file: %s" % outputfn)
else:
outputurl = "private:stream"
try:
document.storeToURL(outputurl, tuple(outputprops) )
- except IOException, e:
+ except UnoIOException, e:
raise UnoException("Unable to store document to %s (ErrCode %d)\n\nProperties: %s" % (outputurl, e.ErrCode, outputprops), None)
phase = "dispose"
@@ -935,24 +936,24 @@ class Convertor:
error("unoconv: SystemError during %s phase:\n%s" % (phase, e))
exitcode = 1
- except RuntimeException, e:
+ except UnoRuntimeException, e:
error("unoconv: RuntimeException during %s phase:\nOffice probably died. %s" % (phase, e))
exitcode = 6
- except DisposedException, e:
+ except UnoDisposedException, e:
error("unoconv: DisposedException during %s phase:\nOffice probably died. %s" % (phase, e))
exitcode = 7
- except IllegalArgumentException, e:
+ except UnoIllegalArgumentException, e:
error("UNO IllegalArgument during %s phase:\nSource file cannot be read. %s" % (phase, e))
exitcode = 8
- except IOException, e:
+ except UnoIOException, e:
# for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
error("unoconv: IOException during %s phase:\n%s" % (phase, e.Message))
exitcode = 3
- except CannotConvertException, e:
+ except UnoCannotConvertException, e:
# for attr in dir(e): print '%s: %s', (attr, getattr(e, attr))
error("unoconv: CannotConvertException during %s phase:\n%s" % (phase, e.Message))
exitcode = 4
@@ -975,14 +976,14 @@ class Listener:
global product
info(1, "Start listener on %s:%s" % (op.server, op.port))
- self.context = uno.getComponentContext()
+ self.context = global_uno.getComponentContext()
self.svcmgr = self.context.ServiceManager
try:
resolver = self.svcmgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", self.context)
- product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", UnoProps(nodepath="/org.openoffice.Setup/Product"))
+ product = self.svcmgr.createInstance("com.sun.star.configuration.ConfigurationProvider").createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", GlobalUnoProps(nodepath="/org.openoffice.Setup/Product"))
try:
unocontext = resolver.resolve("uno:%s" % op.connection)
- except NoConnectException, e:
+ except UnoNoConnectException, e:
pass
else:
info(1, "Existing %s listener found, nothing to do." % product.ooName)
@@ -1039,7 +1040,7 @@ def die(ret, msg=None):
info(3, 'Terminating %s instance.' % product.ooName)
try:
convertor.desktop.terminate()
- except DisposedException:
+ except UnoDisposedException:
info(2, '%s instance unsuccessfully closed, sending TERM signal.' % product.ooName)
try:
ooproc.terminate()
@@ -1080,7 +1081,7 @@ def main():
for inputfn in op.filenames:
convertor.convert(inputfn)
- except NoConnectException, e:
+ except UnoNoConnectException, e:
error("unoconv: could not find an existing connection to LibreOffice at %s:%s." % (op.server, op.port))
if op.connection:
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))
@@ -1094,7 +1095,8 @@ def main():
error("Warning: failed to launch Office suite. Aborting.")
### Main entrance
-if __name__ == '__main__':
+def run():
+ global exitcode
exitcode = 0
info(3, 'sysname=%s, platform=%s, python=%s, python-version=%s' % (os.name, sys.platform, sys.executable, sys.version))
@@ -1105,7 +1107,12 @@ if __name__ == '__main__':
office_environ(of)
# debug_office()
try:
- import uno, unohelper
+ global global_uno
+ global global_unohelper
+
+ import uno as global_uno
+ import unohelper as global_unohelper
+ global office
office = of
break
except:
@@ -1121,17 +1128,30 @@ if __name__ == '__main__':
sys.exit(1)
### Now that we have found a working pyuno library, let's import some classes
- from com.sun.star.beans import PropertyValue
- from com.sun.star.connection import NoConnectException
- from com.sun.star.document.UpdateDocMode import QUIET_UPDATE
- from com.sun.star.lang import DisposedException, IllegalArgumentException
- from com.sun.star.io import IOException, XOutputStream
- from com.sun.star.script import CannotConvertException
+ global UnoPropertyValue
+ global UnoNoConnectException
+ global UNO_QUIET_UPDATE
+ global UnoDisposedException
+ global UnoIllegalArgumentException
+ global UnoIOException
+ global UnoXOutputStream
+ global UnoCannotConvertException
+ global UnoException
+ global UnoRuntimeException
+
+ from com.sun.star.beans import PropertyValue as UnoPropertyValue
+ from com.sun.star.connection import NoConnectException as UnoNoConnectException
+ from com.sun.star.document.UpdateDocMode import QUIET_UPDATE as UNO_QUIET_UPDATE
+ from com.sun.star.lang import DisposedException as UnoDisposedException
+ from com.sun.star.lang import IllegalArgumentException as UnoIllegalArgumentException
+ from com.sun.star.io import IOException as UnoIOException
+ from com.sun.star.io import XOutputStream as UnoXOutputStream
+ from com.sun.star.script import CannotConvertException as UnoCannotConvertException
from com.sun.star.uno import Exception as UnoException
- from com.sun.star.uno import RuntimeException
+ from com.sun.star.uno import RuntimeException as UnoRuntimeException
### And now that we have those classes, build on them
- class OutputStream( unohelper.Base, XOutputStream ):
+ class OutputStream( global_unohelper.Base, UnoXOutputStream ):
def __init__( self ):
self.closed = 0
@@ -1144,15 +1164,22 @@ if __name__ == '__main__':
def flush( self ):
pass
+ global GlobalOutputStream
+ GlobalOutputStream = OutputStream
+
def UnoProps(**args):
props = []
for key in args:
- prop = PropertyValue()
+ prop = UnoPropertyValue()
prop.Name = key
prop.Value = args[key]
props.append(prop)
return tuple(props)
+ global GlobalUnoProps
+ GlobalUnoProps = UnoProps
+
+ global op
op = Options(sys.argv[1:])
info(2, "Using office base path: %s" % office.basepath)
@@ -1163,3 +1190,6 @@ if __name__ == '__main__':
except KeyboardInterrupt, e:
die(6, 'Exiting on user request')
die(exitcode)
+
+if __name__ == '__main__':
+ run()
--
1.9.0