Wei Chong wrote:
Hi all,
I a newbie both in Python and in UNO.
I have done the following code in practicing my new
skill:
import uno
def initDoc(filename):
unoctx = uno.getComponentContext()
resolver =
unoctx.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
unoctx)
oooctx =
resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop =
oooctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
oooctx)
return desktop.loadComponentFromURL(filename,
"_blank", 0, () )
def replaceStr(document):
replace = document.createReplaceDescriptor()
replace.SearchString = "original"
replace.ReplaceString = "replace"
document.replaceAll(replace)
#--main--#
filename = "/home/weichong78/test.odt"
document = initDoc(filename)
replaceStr(document)
document.store()
document.close(1)
However, when I execute the code, the resulting Writer
open the Text document, replacing the string, show the
progress bar that it saves content and throw the below
exception without actually complete saving them (this
i s verified by the fact that the content of file stay
the same the next time I open them). I try to read
from the Developer Guide about the XClosable interface
but do not fully understand. Especially in this case
the document is already provided/opened from existing
file, shouldn't the URL automatically point to it?
Traceback (most recent call last):
File "ooo-replace.py", line 20, in ?
document.store()
__main__.com.sun.star.task.ErrorCodeIOException
python: pthread_mutex_lock.c:108:
__pthread_mutex_lock: Assertion `mutex->__data.__owner
== 0' failed.
Aborted
Thanks,
Wei Chong.
1. what happens if you do NOT store and close the document? Is the
replacement made?
2. Your filename is NOT a URL. I recomment that you use a URL to specify
the file.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]