def tearDown(self):
   """Restart the openoffice in cases that the openoffice is stopped"""
   if not openoffice.status():
     openoffice.acquire()
     openoffice.restart()
     openoffice.release()
   if self.monitor.is_alive():
     self.monitor.terminate()
 def tearDown(self):
   """Restart the openoffice in cases that the openoffice is stopped"""
   if not openoffice.status():
     openoffice.acquire()
     openoffice.restart()
     openoffice.release()
   if self.monitor.is_alive():
     self.monitor.terminate()
Beispiel #3
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()
 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()
 def testStopOpenOffice(self):
   """Test if the openoffice stop by the monitor"""
   openoffice.acquire()
   try:
     monitor_timeout = self._createMonitor(1)
     monitor_timeout.start()
     sleep(2)
     self.assertEquals(openoffice.status(), False)
     openoffice.restart()
     self.assertTrue(openoffice.status())
   finally:
     monitor_timeout.terminate()
     openoffice.release()
Beispiel #6
0
 def setMetadata(self, metadata):
   """Returns a document with new metadata.
   Keyword arguments:
   metadata -- expected an dictionary with metadata.
   """
   metadata_pickled = json.dumps(metadata)
   logger.debug("setMetadata")
   kw = dict(metadata=encodestring(metadata_pickled))
   openoffice.acquire()
   try:
     stdout, stderr = self._callUnoConverter(*['setmetadata'], **kw)
   finally:
     openoffice.release()
   doc_loaded = self.document.getContent()
   self.document.trash()
   return doc_loaded
Beispiel #7
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 #8
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 #9
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 testStopOpenOfficeTwice(self):
   """Test the cases that is necessary start the monitors twice"""
   openoffice.acquire()
   try:
     monitor_timeout = self._createMonitor(1)
     monitor_timeout.start()
     sleep(2)
     self.assertEquals(openoffice.status(), False)
     monitor_timeout.terminate()
     openoffice.restart()
     self.assertTrue(openoffice.status())
     monitor_timeout = self._createMonitor(1)
     monitor_timeout.start()
     sleep(2)
     self.assertEquals(openoffice.status(), False)
     monitor_timeout.terminate()
     sleep(1)
     self.assertEquals(monitor_timeout.is_alive(), False)
   finally:
     monitor_timeout.terminate()
     openoffice.release()
Beispiel #12
0
 def convert(self, destination_format=None, **kw):
   """Convert a document to another format supported by the OpenOffice
   Keyword Arguments:
   destination_format -- extension of document as String
   """
   logger.debug("OooConvert: %s > %s" % (self.source_format, destination_format))
   kw['source_format'] = self.source_format
   if destination_format:
     kw['destination_format'] = destination_format
   kw['mimemapper'] = self._serializeMimemapper(self.source_format,
                                                destination_format)
   kw['refresh'] = json.dumps(self.refresh)
   openoffice.acquire()
   try:
     stdout, stderr = self._callUnoConverter(*['convert'], **kw)
   finally:
     openoffice.release()
   url = stdout.replace('\n', '')
   self.document.reload(url)
   content = self.document.getContent(self.zip)
   self.document.trash()
   return content
Beispiel #13
0
 def getMetadata(self, base_document=False):
   """Returns a dictionary with all metadata of document.
   Keywords Arguments:
   base_document -- Boolean variable. if true, the document is also returned
   along with the metadata."""
   logger.debug("getMetadata")
   kw = dict(mimemapper=self._serializeMimemapper())
   if base_document:
     feature_list = ['getmetadata', 'convert']
   else:
     feature_list = ['getmetadata']
   openoffice.acquire()
   try:
     stdout, stderr = self._callUnoConverter(*feature_list, **kw)
   finally:
     openoffice.release()
   metadata = json.loads(decodestring(stdout))
   if 'document_url' in metadata:
     self.document.reload(metadata['document_url'])
     metadata['Data'] = self.document.getContent()
     del metadata['document_url']
   self.document.trash()
   return metadata
 def tearDown(self):
   """Called to unlock the openoffice"""
   openoffice.release()
Beispiel #15
0
 def tearDown(self):
   """ """
   environ['uno_path'] = self.uno_path
   environ['office_binary_path'] = self.office_binary_path
   openoffice.release()
Beispiel #16
0
 def tearDown(self):
     """ """
     environ['uno_path'] = self.uno_path
     environ['office_binary_path'] = self.office_binary_path
     openoffice.release()