Bugzilla – Attachment 91277 Details for
Bug 58664
Headless Mode Fails to Shutdown
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
reproducer ported to python3
bugHeadless3.py (text/x-python), 5.81 KB, created by
Riccardo Magliocchetti
on 2013-12-29 11:35:22 UTC
(
hide
)
Description:
reproducer ported to python3
Filename:
MIME Type:
Creator:
Riccardo Magliocchetti
Created:
2013-12-29 11:35:22 UTC
Size:
5.81 KB
patch
obsolete
># -*- coding: utf-8 -*- >""" >derived from the UnoContext class and its unit test >""" > >import unittest, sys, os, time, uno > >from com.sun.star.connection import NoConnectException > >class UnoContext (object): > """ > wrapper class for pyuno component contexts > """ > def __init__ (self): > self.reset() > self.unoHost = os.getenv('UNOHOST', 'localhost') > self.unoPort = os.getenv('UNOPORT', '2012') > > def reset (self): > self._localContext = self._officeContext = self._pathSettings = None > return self > > #@apply > def officeComponentContext (): > def fget (self): > if self._officeContext is None: > if self._localContext is None: > self._localContext = uno.getComponentContext() > local = self._localContext > try: > resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local) > self._officeContext = resolver.resolve("uno:{0};StarOffice.ComponentContext".format(self.unoUrp)) > except NoConnectException as e: > self.reset() > raise Exception("Office not running (?): {0}".format(str(e))) > return self._officeContext > > return property(**locals()) > > #@apply > def isOfficeRunning (): > def fget (self): > try: > self.officeComponentContext > except: > return False > else: > return True > > return property(**locals()) > > #@apply > def unoUrp(): > doc = """ > the essential part of the Office connection url: > this string is the --accept string used to start Office > the same string must be used to connect to Office > """ > def fget(self): > return 'socket,host={0},port={1};urp'.format(self.unoHost, str(self.unoPort)) > > return property(**locals()) > > def startOffice (self,porp=None): > """ > start an instance of Office: > cut down version to illustrate issue with headless operation > > With the special value 'headless', Office is started in the background. > Documents can be opened and manipulated but nothing will be visible > on the host OS desktop. > > Note: valid on Debian Squeeze - good luck elsewhere > """ > rootPath = '/usr/lib/libreoffice' > binPath = os.path.join(rootPath, 'program') > libPath = os.path.join(rootPath, 'basis-link/program') > > officeBin = 'soffice' > officePath = os.path.join(binPath, officeBin) > > if not os.path.exists(officePath): > raise Exception( 'Failed to find "{0}" in "{1}"'.format(officeBin, binPath)) > > args = [ > officePath, > '--accept={0}'.format(self.unoUrp), > '--norestore', > '--nofirststartwizard', > '--nologo', > ] > env = { > 'PATH' : '/bin:/usr/bin:{0}'.format(binPath), > 'PYTHONPATH' : libPath, > 'HOME' : os.getenv('HOME'), > 'LANG' : os.getenv('LANG'), > 'DISPLAY' : os.getenv('DISPLAY'), > 'XAUTHORITY' : os.getenv('XAUTHORITY'), > } > > # porp is known to be 'headless' > args.append('--{0}'.format(porp)) > > # spawn Office > try: > print(args[0], args) > print(env) > pid = os.spawnve(os.P_NOWAIT, args[0], args, env) > except Exception as e: > raise Exception( "Failed to start Office {0} ({1}): {2}".format(porp, self.unoUrp, e.message)) > > if pid <= 0: > raise Exception( "Failed to start Office {0} ({1})".format(porp, self.unoUrp)) > > # it may take Office a couple of seconds to start up > for ii in range (0, 9): > time.sleep(1) > try: > if not self.officeComponentContext is None: > return self > except Exception: > pass > raise Exception( "Failed to connect to Office {0} ({1})".format(porp, self.unoUrp)) > > def shutdownOffice (self): > """ > shutdown an instance of Office: > must have been started earlier with startOffice() > """ > if not self._officeContext is None: > print("shutdownOffice") > print(self._officeContext) > self._officeContext.dispose() > self.reset() > time.sleep(1) > return self > ># ----------------- > >class TestUnoContext (unittest.TestCase): > def testHeadless (self): > """Yet Another LibreOffice Issue""" > print('\n', self.shortDescription(), "...") > > unoContext = UnoContext() > > if unoContext.isOfficeRunning: > print("... looks to me Office is ALREADY running ...") > else: > print("... looks to me Office is not running ...") > > print("... start headless Office ...") > unoContext.startOffice('headless') > self.assertFalse(unoContext.officeComponentContext is None) > if unoContext.isOfficeRunning: > print("... looks to me Office is now running ...") > > print("""... check Office is running in the background > hint: ps -ef | fgrep headless > press return in this console when done ...""",) > input() > > print("... shutdown headless Office ...") > unoContext.shutdownOffice() > self.assertTrue(unoContext._officeContext is None) > if unoContext.isOfficeRunning: > print("""... looks to me Office is STILL running ...""") > else: > print("""... looks to me Office is not running ...""") > > print("""... check Office is no longer running in the background > hint: ps -ef | fgrep headless > press return in this console when done ...""",) > input() > >if __name__ == '__main__': > unittest.main() > ># EOF
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 58664
:
72002
|
91277
|
91286