9 debug
Mauricio Baeza edited this page 2019-09-30 02:58:11 +00:00

Tools for debug

Show info in shell

  • Only GNU/Linux
def debug():

    # ~ Show message info
    app.info("Python it's great")

    # ~ Show message debug
    app.debug('Path of file')

    # ~ Show errors
    app.error('Caution...')

    return

image

  • In Windows, you need to have open document Writer with name debug.odt.
def debug():

    # ~ Show message debug
    app.debug('Please, used GNU/Linux')

    return

image


MsgBox

  • Show any data in message box
def message():

    msg = 'Please, save the planet'
    app.msgbox(msg)

    msg = ('one', 2, 'three')
    app.msgbox(msg)

    msg = {'name': 'Teresa'}
    app.msgbox(msg)

    app.msgbox(app)

    return

image

Log to file

  • Save log in file
def log():
    app.save_log('/home/mau/log.txt', 'PyUNO')
    app.save_log('/home/mau/log.txt', app.INFO_DEBUG)
    return
  • Automatic add date and time.
mau@oficina ~ $ cat log.txt
2019-09-20 18:24:27 -ZAZ- 'PyUNO'
2019-09-20 18:24:27 -ZAZ- ('3.7.4 (default, Jul 16 2019, 07:12:58) \n'
 '[GCC 9.1.0]\n'
 '\n'
 'Linux-5.2.14-arch2-1-ARCH-x86_64-with-arch\n'
 '\n'
 '/usr/lib/libreoffice/program\n'
 '/home/mau/Projects/libre_office/extensions/zaz-easymacro\n'
 '/usr/lib/python37.zip\n'
 '/usr/lib/python3.7\n'
 '/usr/lib/python3.7/lib-dynload\n'
 '/usr/lib/python3.7/site-packages\n'
 '/usr/lib/libreoffice/program/\n'
 '/home/mau/.config/libreoffice/4/user/uno_packages/cache/uno_packages/lu26382sorjlr.tmp_/ZAZFavorites_v0.1.0.oxt/pythonpath')

Call MRI

  • MRI is the best extension for introspection of objects for LibreOffice. Download and install. Then.
def call_mri()
    doc = XSCRIPTCONTEXT.getDocument()
    app.mri(doc)
    return

image


Catch exceptions

  • In generally, LibreOffice try show you any error.
def error1():
    if True:
    app.msgbox('This not work')
    return

image

def error2():
    r = 1 / 0
    return

image

  • Sometimes, for difficult errors, you can used.
@app.catch_exception
def test():
    r = 1 / 0
    return
  • Show in shell
29/09/2019 21:50:51 - ERROR - test
Traceback (most recent call last):
  File "/home/mau/.config/libreoffice/4/user/Scripts/python/pythonpath/easymacro.py", line 231, in func
    return f(*args, **kwargs)
  File "/home/mau/.config/libreoffice/4/user/Scripts/python/mymacros.py", line 12, in test
    r = 1 / 0
ZeroDivisionError: division by zero

And not, not used this function in production.


Info debug

If you have any problem in your code, you can open issue in this project, always show the information of INFO_DEBUG in your ticket.

def info_debug()
    app.msgbox(app.INFO_DEBUG)
    return

image