easymacro/docs/source/tools_debug.rst

217 lines
3.6 KiB
ReStructuredText

Tools for debug
===============
INFO_DEBUG
----------
Show info debug, show in message box.
If you have any problem in your code, you can `open issue`_ in this project,
always copy the information of **INFO_DEBUG** in your ticket.
.. code-block:: python
import easymacro as app
def info():
app.msgbox(app.INFO_DEBUG)
return
.. image:: _static/images/install_01.png
|
Show in shell.
.. code-block:: python
import easymacro as app
def info():
app.debug(app.INFO_DEBUG)
return
.. code-block:: console
mau@oficina ~> soffice --calc
25/02/2022 16:44:24 - DEBUG - LibreOffice v7.3 en-US
Python: 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
Linux-5.16.11-arch1-1-x86_64-with-glibc2.35
/usr/lib/libreoffice/program
/usr/lib/python310.zip
/usr/lib/python3.10
/usr/lib/python3.10/lib-dynload
/home/mau/.local/lib/python3.10/site-packages
/usr/lib/python3.10/site-packages
/usr/lib/libreoffice/program/
/home/mau/.config/libreoffice/4/user/Scripts/python/pythonpath
Log error
---------
Show message error in shell.
.. code-block:: python
import easymacro as app
def test_error():
msg = 'My error 500'
app.error(msg)
return
.. image:: _static/images/toolsdebug_01.png
Log debug
---------
Show message debug in shell.
.. code-block:: python
import easymacro as app
def test_debug():
msg = 'Verify this data...'
app.debug(msg)
return
.. image:: _static/images/toolsdebug_02.png
Log info
--------
Show message info in shell.
.. code-block:: python
import easymacro as app
def test_info():
msg = 'Start process...'
app.info(msg)
return
.. image:: _static/images/toolsdebug_03.png
Log to file
-----------
Save log to file, automatic add date and time.
.. code-block:: python
import easymacro as app
def log():
app.save_log('/home/mau/log.txt', 'PyUNO')
app.save_log('/home/mau/log.txt', 'Damed World')
return
.. image:: _static/images/toolsdebug_04.png
Message Box
-----------
Show any data in message box
.. code-block:: python
import easymacro as app
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:: _static/images/toolsdebug_05.png
Catch exceptions
----------------
Sometimes, for difficult errors, you can catch exceptions.
.. code-block:: python
import easymacro as app
@app.catch_exception
def test():
r = 1 / 0
return
.. image:: _static/images/toolsdebug_06.png
.. warning::
Not, not used you this function in production.
Call MRI
--------
`MRI`_ is the best extension for debug any object in LibreOffice, you need
install before call it.
.. code-block:: python
import easymacro as app
def error():
obj = app.active
app.mri(obj)
return
.. image:: _static/images/toolsdebug_07.png
Inspect
-------
Show info in shell debug
.. code-block:: python
import easymacro as app
def inspect():
obj = app.active
data = app.inspect(doc)
for p in data.properties:
app.debug(p)
for m in data.methods:
app.debug(m)
return
Or show in new Calc document.
.. code-block:: python
obj = app.active
app.inspect(doc, True)
.. _MRI: https://github.com/hanya/MRI
.. _open issue: https://git.cuates.net/elmau/easymacro/issues