Example #1
0
 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()
Example #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()
Example #5
0
 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()
Example #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
Example #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
Example #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()
Example #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()
Example #10
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 #11
0
 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()
Example #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
Example #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 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')
Example #15
0
 def afterSetUp(self):
   """ """
   self.package_namespace = "cloudooo.handler.ooo"
   environ['uno_path'] = ''
   environ['office_binary_path'] = ''
   openoffice.acquire()
Example #16
0
 def afterSetUp(self):
     """ """
     self.package_namespace = "cloudooo.handler.ooo"
     environ['uno_path'] = ''
     environ['office_binary_path'] = ''
     openoffice.acquire()