[Erp5-report] r38771 gabriel - in /erp5/trunk/utils/cloudooo/cloudooo: ./ application/ hand...
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Sep 29 22:54:43 CEST 2010
Author: gabriel
Date: Wed Sep 29 22:54:43 2010
New Revision: 38771
URL: http://svn.erp5.org?rev=38771&view=rev
Log:
refactor code to use python provided by openoffice
Modified:
erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py
erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py
erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py
erp5/trunk/utils/cloudooo/cloudooo/mimemapper.py
erp5/trunk/utils/cloudooo/cloudooo/tests/testUnoMimemapper.py
Modified: erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py?rev=38771&r1=38770&r2=38771&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/application/openoffice.py [utf8] Wed Sep 29 22:54:43 2010
@@ -31,7 +31,6 @@ from os import environ
from os.path import exists, join
from subprocess import Popen, PIPE
from threading import Lock
-from sys import executable as python_path
from zope.interface import implements
from application import Application
from xvfb import xvfb
@@ -58,7 +57,7 @@ class OpenOffice(Application):
def _testOpenOffice(self, host, port):
"""Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], self.pid()))
- command = [python_path
+ command = [join(self.office_binary_path, "python")
, pkg_resources.resource_filename("cloudooo",
join("helper", "openoffice_tester.py"))
, "'--hostname=%s'" % host
Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py?rev=38771&r1=38770&r2=38771&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/oohandler.py [utf8] Wed Sep 29 22:54:43 2010
@@ -67,14 +67,17 @@ class OOHandler:
def _getCommand(self, *args, **kw):
"""Transforms all parameters passed in a command"""
hostname, port = openoffice.getAddress()
+ jsonpickle_path = "/".join(pkg_resources.resource_filename("jsonpickle",
+ "").split("/")[:-1])
kw['hostname'] = hostname
kw['port'] = port
- command_list = [python_path
+ command_list = [path.join(self.office_binary_path, "python")
, pkg_resources.resource_filename("cloudooo",
path.join("helper", "unoconverter.py"))
, "--uno_path='%s'" % self.uno_path
, "--office_binary_path='%s'" % self.office_binary_path
- , "--document_url='%s'" % self.document.getUrl()]
+ , "--document_url='%s'" % self.document.getUrl()
+ , "--jsonpickle_path='%s'" % jsonpickle_path]
for arg in args:
command_list.insert(3, "'--%s'" % arg)
for k, v in kw.iteritems():
Modified: erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py?rev=38771&r1=38770&r2=38771&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/helper/unoconverter.py [utf8] Wed Sep 29 22:54:43 2010
@@ -28,7 +28,6 @@
##############################################################################
import sys
-import jsonpickle
import helper_utils
from types import UnicodeType, InstanceType
from os import environ, putenv
@@ -264,15 +263,22 @@ def main():
"hostname=", "port=", "source_format=",
"document_url=", "destination_format=",
"mimemapper=", "metadata=",
- "unomimemapper_bin="])
+ "unomimemapper_bin=", "jsonpickle_path="])
except GetoptError, msg:
msg = msg.msg + help_msg
print >> sys.stderr, msg
sys.exit(2)
- param_list = [tuple[0] for tuple in opt_list]
+ param_list = [tuple[0] for tuple in iter(opt_list)]
- for opt, arg in opt_list:
+ for opt, arg in iter(opt_list):
+ if opt == "--jsonpickle_path":
+ sys.path.append(arg)
+ break
+
+ import jsonpickle
+
+ for opt, arg in iter(opt_list):
if opt in ('-h', '--help'):
help()
elif opt == '--hostname':
Modified: erp5/trunk/utils/cloudooo/cloudooo/mimemapper.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/mimemapper.py?rev=38771&r1=38770&r2=38771&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/mimemapper.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/mimemapper.py [utf8] Wed Sep 29 22:54:43 2010
@@ -107,7 +107,7 @@ class MimeMapper(object):
uno_path = kw.get("uno_path", environ.get('uno_path'))
office_binary_path = kw.get("office_binary_path",
environ.get('office_binary_path'))
- command = [python_path
+ command = [path.join(office_binary_path, "python")
, pkg_resources.resource_filename(__name__,
path.join("helper","unomimemapper.py"))
, "'--uno_path=%s'" % uno_path
Modified: erp5/trunk/utils/cloudooo/cloudooo/tests/testUnoMimemapper.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/tests/testUnoMimemapper.py?rev=38771&r1=38770&r2=38771&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/tests/testUnoMimemapper.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/tests/testUnoMimemapper.py [utf8] Wed Sep 29 22:54:43 2010
@@ -26,10 +26,10 @@
#
##############################################################################
-import unittest
+import unittest, pkg_resources
from cloudooo.application.openoffice import openoffice
from subprocess import Popen, PIPE
-from os import environ
+from os import environ, path
from cloudoooTestCase import cloudoooTestCase, make_suite
class TestUnoMimeMapper(cloudoooTestCase):
@@ -50,15 +50,15 @@ class TestUnoMimeMapper(cloudoooTestCase
def testCreateLocalAttributes(self):
"""Test if filters returns correctly the filters and types in dict"""
hostname, host = openoffice.getAddress()
- command = [self.python_path,
- "-c",
- "'from cloudooo.bin.unomimemapper import main; main()'",
+ command = [path.join(self.office_binary_path, "python"),
+ pkg_resources.resource_filename("cloudooo", "helper/unomimemapper.py"),
"'--uno_path=%s'" % self.uno_path,
- "'--office_binary_path=%s'" % self.uno_path,
+ "'--office_binary_path=%s'" % self.office_binary_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.openoffice_port]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
+ self.assertEquals(stderr, '')
exec(stdout)
self.assertEquals('filter_dict' in locals(), True)
self.assertEquals('type_dict' in locals(), True)
@@ -68,29 +68,36 @@ class TestUnoMimeMapper(cloudoooTestCase
self.assertEquals(type_dict.get('writer8').get('PreferredFilter'), 'writer8')
self.assertEquals(stderr, '')
- def testCallUnoMimemapperWithoutSomeParameters(self):
+ def testCallUnoMimemapperOnlyHostNameAndPort(self):
""" Test call unomimemapper without uno_path and office_binary_path"""
hostname, host = openoffice.getAddress()
- command = [self.python_path,
- "-c",
- "'from cloudooo.bin.unomimemapper import main; main()'",
+ command = [path.join(self.office_binary_path, "python"),
+ pkg_resources.resource_filename("cloudooo",
+ "helper/unomimemapper.py"),
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.openoffice_port]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
- self.assertEquals(stderr.endswith('No module named uno\n'), True)
- self.assertEquals(stdout, '')
+ self.assertEquals(stderr, '')
+ exec(stdout)
+ self.assertEquals('filter_dict' in locals(), True)
+ self.assertEquals('type_dict' in locals(), True)
+ self.assertNotEquals(filter_dict.get('writer8'), None)
+ self.assertEquals(type_dict.get('writer8').get('Name'), 'writer8')
+ self.assertNotEquals(filter_dict.get('writer8'), None)
+ self.assertEquals(type_dict.get('writer8').get('PreferredFilter'), 'writer8')
+ self.assertEquals(stderr, '')
def testWithoutOpenOffice(self):
"""Test when the openoffice is stopped"""
error_msg = "couldn\'t connect to socket (Success)\n"
hostname, host = openoffice.getAddress()
openoffice.stop()
- command = [self.python_path,
- "-c",
- "'from cloudooo.bin.unomimemapper import main; main()'",
+ command = [path.join(self.office_binary_path, "python"),
+ pkg_resources.resource_filename("cloudooo",
+ "helper/unomimemapper.py"),
"'--uno_path=%s'" % self.uno_path,
- "'--office_binary_path=%s'" % self.uno_path,
+ "'--office_binary_path=%s'" % self.office_binary_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.openoffice_port]
stdout, stderr = Popen(' '.join(command), shell=True,
More information about the Erp5-report
mailing list