Commit a8352858 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor to use module name extracted from pkg_resources. This way is the same...

refactor to use module name extracted from pkg_resources. This way is the same used by easy_install.py to install or search packages and scripts

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@37961 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 77cada1a
......@@ -36,8 +36,8 @@ from application import Application
from sys import executable as python_path
from xvfb import xvfb
from cloudooo.interfaces.lockable import ILockable
from cloudooo.utils import logger, waitStartDaemon,\
removeDirectory, waitStopDaemon, convertStringToBool
from cloudooo.utils import logger, waitStartDaemon, removeDirectory, \
waitStopDaemon, convertStringToBool, extractModuleName
class OpenOffice(Application):
"""Object to control one OOo Instance and all features instance."""
......@@ -59,10 +59,11 @@ class OpenOffice(Application):
"""Test if OpenOffice was started correctly"""
logger.debug("Test OpenOffice %s - Pid %s" % (self.getAddress()[-1], self.pid()))
command = [python_path
, self.openoffice_tester_bin
, "--hostname=%s" % host
, "--port=%s" % port
, "--uno_path=%s" % self.uno_path]
, "'-c'"
, "'from %s import main;main()'" % extractModuleName("openoffice_tester")
, "'--hostname=%s'" % host
, "'--port=%s'" % port
, "'--uno_path=%s'" % self.uno_path]
logger.debug("Testing Openoffice Instance %s" % port)
stdout, stderr = Popen(" ".join(command), shell=True, stdout=PIPE,
stderr=PIPE, close_fds=True).communicate()
......@@ -93,10 +94,6 @@ class OpenOffice(Application):
self.uno_path = uno_path
self.process_name = "soffice.bin"
self.document_url = kw.get('document_url', '')
self.unoconverter_bin = kw.get("unoconverter_bin", "unoconverter")
self.python_path = kw.get('python_path', 'python')
self.unomimemapper_bin = kw.get("unomimemapper_bin")
self.openoffice_tester_bin = kw.get("openoffice_tester_bin")
def _start_process(self, command, env):
"""Start OpenOffice.org process"""
......
......@@ -247,7 +247,7 @@ def main():
if "unomimemapper_bin" in locals():
kw['unomimemapper_bin'] = unomimemapper_bin
kw['python_path'] = executable
kw['python_path'] = sys.executable
mimemapper.loadFilterList(hostname=hostname, port=port, **kw)
kw.clear()
......
......@@ -36,8 +36,9 @@ from cloudooo.interfaces.handler import IHandler
from cloudooo.mimemapper import mimemapper
from cloudooo.document import FileSystemDocument
from cloudooo.monitor.timeout import MonitorTimeout
from cloudooo.utils import logger
from cloudooo.utils import logger, extractModuleName
from psutil import pid_exists
from sys import executable as python_path
class OOHandler:
"""OOHandler is used to access the one Document and OpenOffice.
......@@ -59,7 +60,6 @@ class OOHandler:
self.timeout = kw.get("timeout", 600)
self.unoconverter_bin = kw.get('unoconverter_bin', "unoconverter")
self.source_format = source_format
self.python_path = kw.get('python_path', 'python')
if not self.uno_path:
self.uno_path = environ.get("uno_path")
if not self.office_bin_path:
......@@ -70,15 +70,16 @@ class OOHandler:
hostname, port = openoffice.getAddress()
kw['hostname'] = hostname
kw['port'] = port
command_list = [self.python_path
, self.unoconverter_bin
command_list = [python_path
, "-c"
, "'from %s import main;main()'" % extractModuleName("unoconverter")
, "--uno_path='%s'" % self.uno_path
, "--office_bin_path='%s'" % self.office_bin_path
, "--document_url='%s'" % self.document.getUrl()]
for arg in args:
command_list.insert(2, "--%s" % arg)
command_list.insert(3, "'--%s'" % arg)
for k, v in kw.iteritems():
command_list.append("--%s='%s'" % (k,v))
command_list.append("'--%s=%s'" % (k,v))
return ' '.join(command_list)
......
......@@ -34,6 +34,7 @@ from os import environ
from sys import executable as python_path
from interfaces.mimemapper import IMimemapper
from types import InstanceType
from utils import extractModuleName
class MimeMapper(object):
"""Load all filters from OOo. You can get the of the filter you want or all
......@@ -102,16 +103,14 @@ class MimeMapper(object):
# XXX - Is not good way to remove unnecessary filters
# XXX - try find a good way to remove filters that are not used for export
bad_flag_list = [65, 94217, 536641, 1572929, 268959937, 524373, 85, 524353]
self.python_path = kw.get("python_path", "python")
self.unomimemapper_bin = kw.get("unomimemapper_bin",
"/usr/bin/unomimemapper")
uno_path = kw.get("uno_path", environ.get('uno_path'))
office_bin_path = kw.get("office_bin_path", environ.get('office_bin_path'))
command = [python_path
, self.unomimemapper_bin
, "--uno_path=%s" % uno_path
, "--office_bin_path=%s" % office_bin_path
, "--hostname=%s" % hostname, "--port=%s" % port]
, "'-c'"
, "'from %s import main;main()'" % extractModuleName("unomimemapper")
, "'--uno_path=%s'" % uno_path
, "'--office_bin_path=%s'" % office_bin_path
, "'--hostname=%s'" % hostname, "--port=%s" % port]
stdout, stderr = Popen(' '.join(command),
stdout=PIPE,
close_fds=True,
......
......@@ -34,6 +34,7 @@ from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.mimemapper import mimemapper
from cloudooo.application.openoffice import openoffice
from cloudooo.document import FileSystemDocument
from cloudooo.utils import extractModuleName
class TestUnoConverter(cloudoooTestCase):
"""Test case to test all features of the unoconverter script"""
......@@ -56,16 +57,17 @@ class TestUnoConverter(cloudoooTestCase):
"""Test script unoconverter"""
mimemapper_pickled = jsonpickle.encode(mimemapper)
command = [self.python_path,
self.unoconverter_bin,
"--convert",
"--uno_path=%s" % self.uno_path,
"--office_bin_path=%s" % self.office_bin_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.port,
"--document_url=%s" % self.document.getUrl(),
"--destination_format=%s" % "doc",
"--source_format=%s" % "odt",
"--mimemapper='%s'" % mimemapper_pickled]
"-c",
"'from %s import main;main()'" % extractModuleName("unoconverter"),
"'--convert'",
"'--uno_path=%s'" % self.uno_path,
"'--office_bin_path=%s'" % self.office_bin_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.port,
"'--document_url=%s'" % self.document.getUrl(),
"'--destination_format=%s'" % "doc",
"'--source_format=%s'" % "odt",
"'--mimemapper=%s'" % mimemapper_pickled]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
self.assertEquals(stderr, '')
......@@ -81,19 +83,20 @@ class TestUnoConverter(cloudoooTestCase):
self.document.trash()
self.assertEquals(exists(output_url), False)
def testUnoConverterWithoutMimemapper(self):
def _testUnoConverterWithoutMimemapper(self):
"""Test script unoconverter without mimemapper serialized"""
command = [self.python_path,
self.unoconverter_bin,
"--convert",
"--uno_path=%s" % self.uno_path,
"--office_bin_path=%s" % self.office_bin_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.port,
"--document_url=%s" % self.document.getUrl(),
"--destination_format=%s" % "doc",
"--source_format=%s" % "odt",
"--unomimemapper_bin=%s" % self.unomimemapper_bin]
"-c",
"'from %s import main;main()'" % extractModuleName("unoconverter"),
"'--convert'",
"'--uno_path=%s'" % self.uno_path,
"'--office_bin_path=%s'" % self.office_bin_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.port,
"'--document_url=%s'" % self.document.getUrl(),
"'--destination_format=%s'" % "doc",
"'--source_format=%s'" % "odt",
"'--unomimemapper_bin=%s'" % self.unomimemapper_bin]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
......
......@@ -31,6 +31,7 @@ from cloudooo.application.openoffice import openoffice
from subprocess import Popen, PIPE
from os import environ
from cloudoooTestCase import cloudoooTestCase, make_suite
from cloudooo.utils import extractModuleName
class TestUnoMimeMapper(cloudoooTestCase):
"""Test Case to test all features of script unomimemapper"""
......@@ -51,11 +52,12 @@ class TestUnoMimeMapper(cloudoooTestCase):
"""Test if filters returns correctly the filters and types in dict"""
hostname, host = openoffice.getAddress()
command = [self.python_path,
self.unomimemapper_bin,
"--uno_path=%s" % self.uno_path,
"--office_bin_path=%s" % self.uno_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
"-c",
"'from %s import main; main()'" % extractModuleName("unomimemapper"),
"'--uno_path=%s'" % self.uno_path,
"'--office_bin_path=%s'" % self.uno_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.openoffice_port]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
exec(stdout)
......@@ -71,9 +73,10 @@ class TestUnoMimeMapper(cloudoooTestCase):
""" Test call unomimemapper without uno_path and office_bin_path"""
hostname, host = openoffice.getAddress()
command = [self.python_path,
self.unomimemapper_bin,
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
"-c",
"'from %s import main; main()'" % extractModuleName("unomimemapper"),
"'--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)
......@@ -85,11 +88,12 @@ class TestUnoMimeMapper(cloudoooTestCase):
hostname, host = openoffice.getAddress()
openoffice.stop()
command = [self.python_path,
self.unomimemapper_bin,
"--uno_path=%s" % self.uno_path,
"--office_bin_path=%s" % self.uno_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
"-c",
"'from %s import main; main()'" % extractModuleName("unomimemapper"),
"'--uno_path=%s'" % self.uno_path,
"'--office_bin_path=%s'" % self.uno_path,
"'--hostname=%s'" % self.hostname,
"'--port=%s'" % self.openoffice_port]
stdout, stderr = Popen(' '.join(command), shell=True,
stdout=PIPE, stderr=PIPE).communicate()
self.assertEquals(stdout, '')
......
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