[Solved] [Python] Errors report - Debugging configuration

Keyboard macros or custom scripts

[Solved] [Python] Errors report - Debugging configuration

Postby OlivierR » Tue Jul 27, 2010 6:21 pm

Hi,

I am beginning to write an extension in Python, but I am very frustrated, for I don’t succeed to get any report when Python crashes/stops.

I have changed the configuation values in OpenOffice.org 3\Basis\program\pythonscript.py :
Code: Select all   Expand viewCollapse view
#LogLevel.use = LogLevel.NONE                # production level
#LogLevel.use = LogLevel.ERROR               # for script developers
LogLevel.use = LogLevel.DEBUG               # for script framework developers
LOG_STDOUT = False                          # True, writes to stdout (difficult on windows)
                                            # False, writes to user/Scripts/python/log.txt
ENABLE_EDIT_DIALOG=False                    # offers a minimal editor for editing.

Anyway, whatever values I set, nothing changes. No messages, no file user/Scripts/python/log.txt.
This way, debugging is extremely difficult.

What should I do?

If there is no solution, where is stdout on Windows? That would be better than nothing.
Last edited by OlivierR on Fri Aug 13, 2010 7:13 pm, edited 1 time in total.
LibreOffice 6.2Windows 10
OlivierR
 
Posts: 35
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Python] Errors report - Debugging configuration

Postby gurfle » Wed Aug 11, 2010 8:23 pm

Oliver:

This is probably not of much help, but whenever python bombs on me, I get a very descriptive message box that always indicates the precise line number where the error occured. I did not know about the configurations in pythonscript.py until seeing your post, but when I changed the settings to what you have, the file "C:\Documents and Settings\<WindowsUserid>\Application Data\OpenOffice.org\3\user\Scripts\python\log.txt" is created that includes the same error messages seen in the message box.

I am using OOo 3.1.1 that comes with Python 2.6.1 on Windows XP, so it is a slightly different configuration than you have. I have heard that there are problems with python if you do not use the version that gets installed with OOo, but believe if that were your problem you would not be able to get python to work at all from OOo which it does not appear to be the case, right?

I wish you good luck, because I have had good results with python and think it probably is the best (or at least easiest) way to get serious programming done for OOo automation.
Nicholas Dreyer
AMD sempron 3.4GHz, 1G RAM, nForce3-250Gb motherboard

AntiX M11
LibreOffice 3.4.3

Posts prior to Aug. 18, 2011 referenced
Linux Debian (lenny-backports or squeeze)
OpenOffice 3.2.1
User avatar
gurfle
 
Posts: 67
Joined: Wed Dec 02, 2009 5:40 am

Re: [Python] Errors report - Debugging configuration

Postby OlivierR » Wed Aug 11, 2010 10:15 pm

Thanks for your answer, Nicholas.
I was wondering how it worked for others windows users. At least, I know now that it can work. ;)

I also tried OOo 3.2.1 on Windows XP, and I don't get any error messages either, whatever method I try. Just nothing.

On the both machines, Python 2.6.5 and Python 3.1.2 are installed. But I am writing an extension, and I installed it each times I want to test it. So, as far as I know, OOo uses the Python version bundled in its code, not the two other ones.

May be a bug in OOo 3.2? I will test with OOo 3.1 tomorrow.
LibreOffice 6.2Windows 10
OlivierR
 
Posts: 35
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Python] Errors report - Debugging configuration

Postby hanya » Thu Aug 12, 2010 5:52 am

Hi,
are you making your extension as UNO component implemented in Python?
The configuration of the pythonscript.py is influence to only scripts written in python and it does not work with components.

pythonloader.py does not provide the logging function because error occured in your component does not catched in the loader.
Replace your standard output and error with your own logger to make log file.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Python] Errors report - Debugging configuration

Postby OlivierR » Fri Aug 13, 2010 2:45 pm

Hi hanya,

hanya wrote:are you making your extension as UNO component implemented in Python?
The configuration of the pythonscript.py is influence to only scripts written in python and it does not work with components.

Yes.
Actually, I have used your code to implement a contextual menu.
viewtopic.php?p=123613#p123613

Replace your standard output and error with your own logger to make log file.

That's what I did.

Code: Select all   Expand viewCollapse view
sys.stderr = codecs.open("C:\_stderr_log.txt", "w", "utf-8")
sys.stdout = codecs.open("C:\_stdout_log.txt", "w", "utf-8")

print >> sys.stderr, "error"
print >> sys.stdout, "message"
print "another message"

This works, except that no error message is sent to stderr if I make a syntax error or if Python stops.
LibreOffice 6.2Windows 10
OlivierR
 
Posts: 35
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Python] Errors report - Debugging configuration

Postby hanya » Fri Aug 13, 2010 3:48 pm

OlivierR wrote:This works, except that no error message is sent to stderr if I make a syntax error or if Python stops.
All syntax error of component files are ignored simply in the pythonloader.py.
If you want to get it, you have to edit pythonloader.py to show syntax error. But you can find syntax error using normal python interpreter. Simply, pass your script to interpreter.

If you want to modify pythonloader.py, syntax error should be caused on compile function call in the getModuleFromUrl method. Add another except statement. Here is an example:
Code: Select all   Expand viewCollapse view
# pythonloader.py
class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
      def __init__(self, ctx ):
#...
      def getModuleFromUrl( self, url ):
          if DEBUG:
#...
          try:
                if "file" == protocol:
                      # code of the component is compiled
# ...
          except ImportError, e:
                raise RuntimeException( "Couldn't load "+url+ " for reason "+str(e), None)
          except SyntaxError, e: # added
              print(e)
          return None


Additionally, syntax error of python script (written as macro) can be seen using my modified script provider. If you are writing a macro as automation script, this does not needed.
http://hermione.s41.xrea.com/pukiwiki/i ... -0.4.2.oxt
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Python] Errors report - Debugging configuration

Postby OlivierR » Fri Aug 13, 2010 7:12 pm

Thank you, hanya. This is very helpful. :super:

By the way, there is very cool stuff in your website. 8-)
LibreOffice 6.2Windows 10
OlivierR
 
Posts: 35
Joined: Sun Jul 25, 2010 3:13 pm

Re: [Solved] [Python] Errors report - Debugging configuratio

Postby OlivierR » Tue Apr 16, 2013 8:08 pm

Hi *,

I got some news about this problem.
There is a workaround to get a working stdout on Windows with Python.

(Thanks to Tor Lillqvist.)

To get a console to be used as stdout, apply the following instructions.

1. Close LibreOffice.

2. Download Visual Studio Express 2010 C++ (I assume it may work with other versions) and install it.

3. Open the Console for Visual Studio.

4. Type:

Code: Select all   Expand viewCollapse view
    editbin.exe /subsystem:console "C:\Program Files\LibreOffice 5\program\soffice.exe"
    editbin.exe /subsystem:console "C:\Program Files\LibreOffice 5\program\soffice.bin"


Now, a console will be shown when you open LibreOffice. It will be the stdout for the “print” command.

And you can get Python errors while LO is running if you use traceback.

Code: Select all   Expand viewCollapse view
    import traceback
    […]
    try:
        […]
    except:
        traceback.print_exc()


But syntax errors still won’t be reported there.
LibreOffice 6.2Windows 10
OlivierR
 
Posts: 35
Joined: Sun Jul 25, 2010 3:13 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 5 guests