Skip to content

Commit

Permalink
Now properly check if there is a GUI attached and terminate() or -una…
Browse files Browse the repository at this point in the history
…ccept instance

git-svn-id: http://svn.rpmforge.net/svn/trunk/tools/unoconv@5803 60da1e97-ced4-0310-9a99-dd04229c09c9
  • Loading branch information
dag committed Sep 1, 2007
1 parent 705adef commit 11510b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 0.3svn - released 01/09/2007
- Now properly check if there is a GUI attached and terminate() or -unaccept instance

* 0.3 - released 31/08/2007
- Determine doctype from input filename (if not specified)
- Created a seperate class and allow to use as a library (like DocumentConverter.py)
Expand Down
42 changes: 33 additions & 9 deletions unoconv
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ else:

from com.sun.star.beans import PropertyValue
from com.sun.star.connection import NoConnectException
from com.sun.star.lang import DisposedException
from com.sun.star.io import IOException, XOutputStream
from com.sun.star.script import CannotConvertException
from com.sun.star.uno import Exception as UnoException

__version__ = "$Revision$"
# $Source$

VERSION = '0.3'
VERSION = '0.3svn'

doctypes = ('document', 'graphics', 'presentation', 'spreadsheet')

Expand Down Expand Up @@ -518,21 +519,42 @@ def info(level, str):
def die(ret, str=None):
"Print error and exit with errorcode"
global oopid
global convertor

if str:
error(0, 'Error: %s' % str)
if oopid:
error(2, 'Taking down OpenOffice with pid %s.' % oopid)

### Did we start a process and is it bound to a GUI ?
if oopid and not convertor.desktop.getCurrentFrame():
# error(2, 'Taking down OpenOffice with pid %s.' % oopid)
try:
### FIXME: Send terminate event to perfectly good OpenOffice GUI
convertor.desktop.terminate()
except DisposedException:
error(2, 'OpenOffice instance successfully terminated.')

### Otherwise -unaccept connection
elif convertor.desktop.getCurrentFrame():
for bin in ('soffice.bin', 'soffice', ):
try:
os.spawnvp(os.P_NOWAIT, bin, [bin, "-nologo", "-nodefault", "-unaccept=%s" % op.connection]);
error(2, 'OpenOffice listener successfully disabled.')
break
except Exception, e:
continue

# os.setpgid(oopid, 0)
# os.killpg(os.getpgid(oopid), 15)
try:
os.kill(oopid, 15)
error(2, 'Waiting for OpenOffice with pid %s to disappear.' % oopid)
os.waitpid(oopid, os.WUNTRACED)
except:
error(2, 'No OpenOffice with pid %s to take down' % oopid)
# try:
# os.kill(oopid, 15)
# error(2, 'Waiting for OpenOffice with pid %s to disappear.' % oopid)
# os.waitpid(oopid, os.WUNTRACED)
# except:
# error(2, 'No OpenOffice with pid %s to take down' % oopid)
sys.exit(ret)

def main():
global convertor
try:
if op.listener:
listener = Listener()
Expand All @@ -555,6 +577,8 @@ def main():
except OSError:
error(0, "Warning: failed to launch OpenOffice. Aborting.")

convertor = None

### Main entrance
if __name__ == '__main__':
exitcode = 0
Expand Down
5 changes: 4 additions & 1 deletion unoconv.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Summary: Tool to convert between any document format supported by OpenOffice
Name: unoconv
Version: 0.3
Version: 0.3svn
Release: 1
License: GPL
Group: System Environment/Base
Expand Down Expand Up @@ -57,6 +57,9 @@ and many more...
%{_bindir}/unoconv

%changelog
* Sat Sep 01 2007 Dag Wieers <dag@wieers.com> - 0.3svn-1
- Updated to release 0.3svn.

* Fri Aug 31 2007 Dag Wieers <dag@wieers.com> - 0.3-1
- Updated to release 0.3.

Expand Down

0 comments on commit 11510b7

Please sign in to comment.