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