zaz/doc/source/main/tools_for_debug.rst

154 lines
2.2 KiB
ReStructuredText
Raw Normal View History

2021-02-08 22:30:10 -06:00
2021-06-10 22:25:03 -05:00
Tools for debug
---------------
2021-02-08 22:30:10 -06:00
2021-06-18 23:04:07 -05:00
INFO_DEBUG
^^^^^^^^^^
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
Show info debug, show in message box.
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
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.
2021-02-08 22:30:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
def info():
app.msgbox(INFO_DEBUG)
return
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
Show in shell.
2021-02-08 22:30:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
def info():
app.debug(INFO_DEBUG)
return
2021-02-08 22:30:10 -06:00
2021-06-18 23:04:07 -05:00
Log error
^^^^^^^^^
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
Show error message in shell.
2021-02-08 22:30:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
def error():
msg = 'My error 500'
app.error(msg)
return
2021-02-08 22:30:10 -06:00
2021-06-18 23:04:07 -05:00
Log debug
^^^^^^^^^
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
Show debug message in shell.
2021-02-08 22:30:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
def error():
msg = 'Verify this data...'
app.debug(msg)
return
2021-02-08 22:30:10 -06:00
2021-02-08 22:39:56 -06:00
2021-06-18 23:04:07 -05:00
Log info
^^^^^^^^
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
Show info message in shell.
2021-02-08 22:39:56 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
def error():
msg = 'Start process...'
app.info(msg)
return
2021-02-08 22:39:56 -06:00
2021-06-18 23:04:07 -05:00
Log to file
^^^^^^^^^^^
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
Save log to file, automatic add date and time.
2021-02-08 22:39:56 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
def log():
app.save_log('/home/mau/log.txt', 'PyUNO')
app.save_log('/home/mau/log.txt', app.INFO_DEBUG)
return
2021-02-08 22:39:56 -06:00
2021-06-18 23:04:07 -05:00
Message box
^^^^^^^^^^^
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
Show any data in message box
2021-02-08 22:39:56 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 22:39:56 -06:00
2021-06-03 17:47:12 -05:00
def message():
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
msg = 'Please, save the planet'
app.msgbox(msg)
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
msg = ('one', 2, 'three')
app.msgbox(msg)
2021-02-08 22:50:04 -06:00
2021-06-03 17:47:12 -05:00
msg = {'name': 'Teresa'}
app.msgbox(msg)
2021-02-08 22:50:04 -06:00
2021-06-03 17:47:12 -05:00
app.msgbox(app)
2021-02-08 22:50:04 -06:00
2021-06-03 17:47:12 -05:00
return
2021-02-08 22:50:04 -06:00
2021-06-18 23:04:07 -05:00
Catch exceptions
^^^^^^^^^^^^^^^^
2021-02-08 22:30:10 -06:00
2021-06-03 17:47:12 -05:00
Sometimes, for difficult errors, you can catch exceptions.
2021-02-08 23:02:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 23:02:10 -06:00
2021-06-03 17:47:12 -05:00
@app.catch_exception
def test():
r = 1 / 0
return
2021-02-08 23:02:10 -06:00
2021-06-03 17:47:12 -05:00
And not, not used you this function in production.
2021-02-08 23:02:10 -06:00
2021-06-18 23:04:07 -05:00
Call MRI
^^^^^^^^
2021-02-08 23:02:10 -06:00
2021-06-03 17:47:12 -05:00
`MRI`_ is the better extension for debug any object in LibreOffice, you need
install before call it.
2021-02-08 23:02:10 -06:00
.. code-block:: python
2021-06-03 17:47:12 -05:00
import easymacro as app
2021-02-08 23:02:10 -06:00
2021-06-03 17:47:12 -05:00
def error():
obj = app.active
app.mri(obj)
return
2021-02-08 23:02:10 -06:00
2021-02-08 22:30:10 -06:00
.. _MRI: https://github.com/hanya/MRI
2021-06-03 17:47:12 -05:00
.. _open issue: https://git.cuates.net/elmau/zaz/issues