Commit e258e183 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code to use python provided by openoffice

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@38771 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 86263538
......@@ -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
......
......@@ -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():
......
......@@ -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':
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment