def afterSetUp(self):
     """Mimemapper is created and load uno path."""
     self.mimemapper = MimeMapper()
     openoffice.acquire()
     hostname, port = openoffice.getAddress()
     self.mimemapper.loadFilterList(hostname,
                                    port,
                                    python_path=self.python_path)
     openoffice.release()
Example #2
0
 def afterSetUp(self):
   """Mimemapper is created and load uno path."""
   self.mimemapper = MimeMapper()
   openoffice.acquire()
   hostname, port = openoffice.getAddress()
   self.mimemapper.loadFilterList(hostname,
                                 port,
                                 python_path=self.python_path)
   openoffice.release()
Example #3
0
def startFakeEnvironment(start_openoffice=True, conf_path=None):
    """Create a fake environment"""

    config.read(conf_path)
    uno_path = config.get("app:main", "uno_path")
    working_path = config.get("app:main", "working_path")
    hostname = config.get("server:main", "host")
    openoffice_port = int(config.get("app:main", "openoffice_port"))
    office_binary_path = config.get("app:main", "office_binary_path")
    environment_dict = {}
    for item in config.options("app:main"):
        if item.startswith("env-"):
            environment_dict[item[4:].upper()] = config.get("app:main", item)
    tmp_dir = path.join(working_path, 'tmp')
    check_folder(working_path, tmp_dir)
    if not environ.get('uno_path'):
        environ['uno_path'] = uno_path
    office_binary_path = config.get("app:main", "office_binary_path")
    if not environ.get('office_binary_path'):
        environ['office_binary_path'] = office_binary_path

    if uno_path not in sys.path:
        sys.path.append(uno_path)

    fundamentalrc_file = '%s/fundamentalrc' % office_binary_path
    if path.exists(fundamentalrc_file) and \
        'URE_BOOTSTRAP' not in environ:
        putenv('URE_BOOTSTRAP',
               'vnd.sun.star.pathname:%s' % fundamentalrc_file)

    if start_openoffice:
        default_language = config.get(
            'app:main', 'openoffice_user_interface_language', False,
            {'openoffice_user_interface_language': 'en'})
        openoffice.loadSettings(hostname, openoffice_port, working_path,
                                office_binary_path, uno_path, default_language,
                                environment_dict)
        openoffice.start()
        openoffice.acquire()
        hostname, port = openoffice.getAddress()
        kw = dict(uno_path=config.get("app:main", "uno_path"),
                  office_binary_path=config.get("app:main",
                                                "office_binary_path"))
        if not mimemapper.isLoaded():
            mimemapper.loadFilterList(hostname, port, **kw)
        openoffice.release()
        return openoffice
Example #4
0
def startFakeEnvironment(start_openoffice=True, conf_path=None):
    """Create a fake environment"""

    config.read(conf_path)
    uno_path = config.get("app:main", "uno_path")
    working_path = config.get("app:main", "working_path")
    hostname = config.get("server:main", "host")
    openoffice_port = int(config.get("app:main", "openoffice_port"))
    office_binary_path = config.get("app:main", "office_binary_path")
    environment_dict = {}
    for item in config.options("app:main"):
        if item.startswith("env-"):
            environment_dict[item[4:].upper()] = config.get("app:main", item)
    tmp_dir = path.join(working_path, "tmp")
    check_folder(working_path, tmp_dir)
    if not environ.get("uno_path"):
        environ["uno_path"] = uno_path
    office_binary_path = config.get("app:main", "office_binary_path")
    if not environ.get("office_binary_path"):
        environ["office_binary_path"] = office_binary_path

    if uno_path not in sys.path:
        sys.path.append(uno_path)

    fundamentalrc_file = "%s/fundamentalrc" % office_binary_path
    if path.exists(fundamentalrc_file) and "URE_BOOTSTRAP" not in environ:
        putenv("URE_BOOTSTRAP", "vnd.sun.star.pathname:%s" % fundamentalrc_file)

    if start_openoffice:
        default_language = config.get(
            "app:main", "openoffice_user_interface_language", False, {"openoffice_user_interface_language": "en"}
        )
        openoffice.loadSettings(
            hostname, openoffice_port, working_path, office_binary_path, uno_path, default_language, environment_dict
        )
        openoffice.start()
        openoffice.acquire()
        hostname, port = openoffice.getAddress()
        kw = dict(
            uno_path=config.get("app:main", "uno_path"), office_binary_path=config.get("app:main", "office_binary_path")
        )
        if not mimemapper.isLoaded():
            mimemapper.loadFilterList(hostname, port, **kw)
        openoffice.release()
        return openoffice
Example #5
0
  def _getCommand(self, *args, **kw):
    """Transforms all parameters passed in a command"""
    hostname, port = openoffice.getAddress()
    kw['hostname'] = hostname
    kw['port'] = port
    python = path.join(self.office_binary_path, "python")
    command_list = [path.exists(python) and python or "python",
                    pkg_resources.resource_filename(__name__,
                                 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()]
    for arg in args:
      command_list.insert(3, "--%s" % arg)
    for k, v in kw.iteritems():
      command_list.append("--%s=%s" % (k, v))

    return command_list
Example #6
0
 def testWithoutOpenOffice(self):
   """Test when the openoffice is stopped"""
   error_msg = "couldn\'t connect to socket (Success)\n"
   hostname, host = openoffice.getAddress()
   openoffice.stop()
   python = path.join(self.office_binary_path, "python")
   command = [path.exists(python) and python or "python",
           pkg_resources.resource_filename(self.package_namespace,
                                           "/helper/unomimemapper.py"),
           "--uno_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(command,
                          stdout=PIPE,
                          stderr=PIPE).communicate()
   self.assertEquals(stdout, '')
   self.assertTrue(stderr.endswith(error_msg), stderr)
   openoffice.start()
Example #7
0
 def testWithoutOpenOffice(self):
     """Test when the openoffice is stopped"""
     error_msg = "couldn\'t connect to socket (Success)\n"
     hostname, host = openoffice.getAddress()
     openoffice.stop()
     python = path.join(self.office_binary_path, "python")
     command = [
         path.exists(python) and python or "python",
         pkg_resources.resource_filename(self.package_namespace,
                                         "/helper/unomimemapper.py"),
         "--uno_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(command, stdout=PIPE, stderr=PIPE).communicate()
     self.assertEquals(stdout, '')
     self.assertTrue(stderr.endswith(error_msg), stderr)
     openoffice.start()
Example #8
0
 def testCallUnoMimemapperOnlyHostNameAndPort(self):
   """ Test call unomimemapper without uno_path and office_binary_path"""
   hostname, host = openoffice.getAddress()
   command = [path.join(self.office_binary_path, "python"),
           pkg_resources.resource_filename(self.package_namespace,
                                      "/helper/unomimemapper.py"),
           "--hostname=%s" % self.hostname,
           "--port=%s" % self.openoffice_port]
   stdout, stderr = Popen(command,
                          stdout=PIPE,
                          stderr=PIPE).communicate()
   self.assertEquals(stderr, '')
   filter_dict, type_dict = json.loads(stdout)
   self.assertTrue('filter_dict' in locals())
   self.assertTrue('type_dict' in locals())
   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, '')
Example #9
0
 def testCallUnoMimemapperOnlyHostNameAndPort(self):
     """ Test call unomimemapper without uno_path and office_binary_path"""
     hostname, host = openoffice.getAddress()
     command = [
         path.join(self.office_binary_path, "python"),
         pkg_resources.resource_filename(self.package_namespace,
                                         "/helper/unomimemapper.py"),
         "--hostname=%s" % self.hostname,
         "--port=%s" % self.openoffice_port
     ]
     stdout, stderr = Popen(command, stdout=PIPE, stderr=PIPE).communicate()
     self.assertEquals(stderr, '')
     filter_dict, type_dict = json.loads(stdout)
     self.assertTrue('filter_dict' in locals())
     self.assertTrue('type_dict' in locals())
     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, '')
Example #10
0
 def testCreateLocalAttributes(self):
   """Test if filters returns correctly the filters and types in dict"""
   hostname, host = openoffice.getAddress()
   python = path.join(self.office_binary_path, "python")
   command = [path.exists(python) and python or "python",
           pkg_resources.resource_filename(self.package_namespace,
                                      "/helper/unomimemapper.py"),
           "--uno_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(command,
                          stdout=PIPE,
                          stderr=PIPE).communicate()
   self.assertEquals(stderr, '')
   filter_dict, type_dict = json.loads(stdout)
   self.assertTrue('filter_dict' in locals())
   self.assertTrue('type_dict' in locals())
   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, '')
Example #11
0
 def testCreateLocalAttributes(self):
     """Test if filters returns correctly the filters and types in dict"""
     hostname, host = openoffice.getAddress()
     python = path.join(self.office_binary_path, "python")
     command = [
         path.exists(python) and python or "python",
         pkg_resources.resource_filename(self.package_namespace,
                                         "/helper/unomimemapper.py"),
         "--uno_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(command, stdout=PIPE, stderr=PIPE).communicate()
     self.assertEquals(stderr, '')
     filter_dict, type_dict = json.loads(stdout)
     self.assertTrue('filter_dict' in locals())
     self.assertTrue('type_dict' in locals())
     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 afterSetUp(self):
   """ """
   openoffice.acquire()
   self.hostname, self.port = openoffice.getAddress()
   data = open("data/test.odt", 'r').read()
   self.document = FileSystemDocument(self.tmp_url, data, 'odt')