def testGetMemoryUsage(self):
   """Test memory usage"""
   self.monitor = MonitorMemory(openoffice, 2, 400)
   openoffice.stop()
   memory_usage_int = self.monitor.get_memory_usage()
   self.assertEquals(memory_usage_int, 0)
   if not openoffice.status():
     openoffice.start()
   memory_usage_int = self.monitor.get_memory_usage()
   self.assertEquals(type(memory_usage_int), IntType)
 def testGetMemoryUsage(self):
   """Test memory usage"""
   self.monitor = MonitorMemory(openoffice, 2, 400)
   openoffice.stop()
   memory_usage_int = self.monitor.get_memory_usage()
   self.assertEquals(memory_usage_int, 0)
   if not openoffice.status():
     openoffice.start()
   memory_usage_int = self.monitor.get_memory_usage()
   self.assertEquals(type(memory_usage_int), IntType)
Beispiel #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
Beispiel #4
0
  def _callUnoConverter(self, *feature_list, **kw):
    """ """
    if not openoffice.status():
      openoffice.start()
    command_list = self._getCommand(*feature_list, **kw)
    stdout, stderr = self._subprocess(command_list)
    if not stdout and len(re.findall("\w*Exception|\w*Error", stderr)) >= 1:
      logger.debug(stderr)
      self.document.restoreOriginal()
      openoffice.restart()
      kw['document_url'] = self.document.getUrl()
      command = self._getCommand(*feature_list, **kw)
      stdout, stderr = self._subprocess(command)
      if stderr != "":
          raise Exception(stderr)

    return stdout, stderr
Beispiel #5
0
def bootstrapHandler(configuration_dict):
    # Bootstrap handler
    from signal import signal, SIGINT, SIGQUIT, SIGHUP
    from cloudooo.handler.ooo.mimemapper import mimemapper
    from cloudooo.handler.ooo.application.openoffice import openoffice
    import cloudooo.handler.ooo.monitor as monitor

    def stopProcesses(signum, frame):
        monitor.stop()
        openoffice.stop()

    # Signal to stop all processes
    signal(SIGINT, stopProcesses)
    signal(SIGQUIT, stopProcesses)
    signal(SIGHUP, stopProcesses)

    working_path = configuration_dict.get('working_path')
    application_hostname = configuration_dict.get('application_hostname')
    openoffice_port = int(configuration_dict.get('openoffice_port'))
    environment_dict = configuration_dict['env']
    # Loading Configuration to start OOo Instance and control it
    openoffice.loadSettings(
        application_hostname,
        openoffice_port,
        working_path,
        configuration_dict.get('office_binary_path'),
        configuration_dict.get('uno_path'),
        configuration_dict.get('openoffice_user_interface_language', 'en'),
        environment_dict=environment_dict,
    )
    openoffice.start()
    monitor.load(configuration_dict)

    timeout_response = int(configuration_dict.get('timeout_response'))
    kw = dict(uno_path=configuration_dict.get('uno_path'),
              office_binary_path=configuration_dict.get('office_binary_path'),
              timeout=timeout_response,
              ooo_disable_filter_list=configuration_dict.get(
                  'ooo_disable_filter_list'),
              ooo_disable_filter_name_list=configuration_dict.get(
                  'ooo_disable_filter_name_list'))

    # Load all filters
    openoffice.acquire()
    mimemapper.loadFilterList(application_hostname, openoffice_port, **kw)
    openoffice.release()
Beispiel #6
0
def bootstrapHandler(configuration_dict):
  # Bootstrap handler
  from signal import signal, SIGINT, SIGQUIT, SIGHUP
  from cloudooo.handler.ooo.mimemapper import mimemapper
  from cloudooo.handler.ooo.application.openoffice import openoffice
  import cloudooo.handler.ooo.monitor as monitor

  def stopProcesses(signum, frame):
    monitor.stop()
    openoffice.stop()

  # Signal to stop all processes
  signal(SIGINT, stopProcesses)
  signal(SIGQUIT, stopProcesses)
  signal(SIGHUP, stopProcesses)

  working_path = configuration_dict.get('working_path')
  application_hostname = configuration_dict.get('application_hostname')
  openoffice_port = int(configuration_dict.get('openoffice_port'))
  environment_dict = configuration_dict['env']
  # Loading Configuration to start OOo Instance and control it
  openoffice.loadSettings(application_hostname,
                          openoffice_port,
                          working_path,
                          configuration_dict.get('office_binary_path'),
                          configuration_dict.get('uno_path'),
                          configuration_dict.get('openoffice_user_interface_language',
                                                 'en'),
                          environment_dict=environment_dict,
                          )
  openoffice.start()
  monitor.load(configuration_dict)

  timeout_response = int(configuration_dict.get('timeout_response'))
  kw = dict(uno_path=configuration_dict.get('uno_path'),
            office_binary_path=configuration_dict.get('office_binary_path'),
            timeout=timeout_response,
            ooo_disable_filter_list=configuration_dict.get('ooo_disable_filter_list'),
            ooo_disable_filter_name_list=configuration_dict.get('ooo_disable_filter_name_list'))

  # Load all filters
  openoffice.acquire()
  mimemapper.loadFilterList(application_hostname,
                            openoffice_port, **kw)
  openoffice.release()
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
 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()
Beispiel #9
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()
Beispiel #10
0
  def _callUnoConverter(self, *feature_list, **kw):
    """ """
    if not openoffice.status():
      openoffice.start()
    command_list = self._getCommand(*feature_list, **kw)
    stdout, stderr = self._subprocess(command_list)
    if not stdout and stderr:
      first_error = stderr
      logger.error(stderr)
      self.document.restoreOriginal()
      openoffice.restart()
      kw['document_url'] = self.document.getUrl()
      command = self._getCommand(*feature_list, **kw)
      stdout, stderr = self._subprocess(command)
      if not stdout and stderr:
        second_error = "\nerror of the second run: " + stderr
        logger.error(second_error)
        raise Exception(first_error + second_error)

    return stdout, stderr
Beispiel #11
0
 def setUp(self):
   if not openoffice.status():
     openoffice.start()
 def setUp(self):
   if not openoffice.status():
     openoffice.start()