185 lines
3.1 KiB
Markdown
185 lines
3.1 KiB
Markdown
|
+++
|
||
|
title = "Herramientas para depurar"
|
||
|
weight = 2
|
||
|
+++
|
||
|
|
||
|
### INFO_DEBUG
|
||
|
|
||
|
Mostrar información de depuración en un cuadro de mensaje.
|
||
|
|
||
|
Si tiene cualquier problema en su código durante el desarrollo de sus macros, puede [abrir un ticket][1] de soporte en el sistema de ticket de este proyecto. Siempre copie la información de depuración mostrada en este mensaje.
|
||
|
|
||
|
```python
|
||
|
import easymacro as app
|
||
|
|
||
|
def info():
|
||
|
app.msgbox(app.INFO_DEBUG)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
![Info debug](tools_01.png)
|
||
|
|
||
|
|
||
|
### debug
|
||
|
|
||
|
Mostrar información en la terminal.
|
||
|
|
||
|
```python
|
||
|
import easymacro as app
|
||
|
|
||
|
def test_debug():
|
||
|
msg = 'Verificar esta información...'
|
||
|
app.debug(msg)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
11/08/2022 18:15:45 - DEBUG - Verificar esta información...
|
||
|
```
|
||
|
|
||
|
|
||
|
### info
|
||
|
|
||
|
Mostrar mensajes informativos en la terminal.
|
||
|
|
||
|
```python
|
||
|
import easymacro as app
|
||
|
|
||
|
def test_info():
|
||
|
msg = 'Iniciando proceso...'
|
||
|
app.info(msg)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
11/08/2022 18:23:53 - INFO - Iniciando proceso...
|
||
|
```
|
||
|
|
||
|
|
||
|
### error
|
||
|
|
||
|
Mostrar mensajes de error en la terminal.
|
||
|
|
||
|
```python
|
||
|
import easymacro as app
|
||
|
|
||
|
def test_error():
|
||
|
msg = 'Error 505'
|
||
|
app.error(msg)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
11/08/2022 18:27:34 - ERROR - Error 505
|
||
|
```
|
||
|
|
||
|
|
||
|
### save_log
|
||
|
|
||
|
Guardar registro en un archivo, automáticamente se agrega la fecha y hora.
|
||
|
|
||
|
```python
|
||
|
import easymacro as app
|
||
|
|
||
|
def test_save_log():
|
||
|
|
||
|
app.save_log('/home/mau/log.txt', 'PyUNO')
|
||
|
app.save_log('/home/mau/log.txt', 'Maldito Mundo')
|
||
|
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
cat ~/log.txt
|
||
|
2022-08-11 18:30:11 - 'PyUNO'
|
||
|
2022-08-11 18:30:11 - 'Maldito Mundo'
|
||
|
```
|
||
|
|
||
|
|
||
|
### msgbox
|
||
|
|
||
|
Mostrar cualquier información en un cuadro de mensaje.
|
||
|
|
||
|
```python
|
||
|
def message():
|
||
|
|
||
|
msg = 'Por favor, consume menos.'
|
||
|
app.msgbox(msg)
|
||
|
|
||
|
msg = ('uno', 2, 'tres')
|
||
|
app.msgbox(msg)
|
||
|
|
||
|
msg = {'nombre': 'Teresa'}
|
||
|
app.msgbox(msg)
|
||
|
|
||
|
app.msgbox(app)
|
||
|
|
||
|
return
|
||
|
```
|
||
|
|
||
|
### catch_exception
|
||
|
|
||
|
Capturar cualquier error que se produzca al ejecutar una macro.
|
||
|
|
||
|
```python
|
||
|
@app.catch_exception
|
||
|
def test_capturar_error():
|
||
|
r = 1 / 0
|
||
|
return
|
||
|
```
|
||
|
|
||
|
```
|
||
|
11/08/2022 18:44:36 - ERROR - test_capturar_error
|
||
|
Traceback (most recent call last):
|
||
|
File "/home/mau/.config/libreoffice/4/user/Scripts/python/pythonpath/easymacro/easytools.py", line 115, in func
|
||
|
return f(*args, **kwargs)
|
||
|
File "/home/mau/.config/libreoffice/4/user/Scripts/python/test.py", line 18, in test_capturar_error
|
||
|
r = 1 / 0
|
||
|
ZeroDivisionError: division by zero
|
||
|
```
|
||
|
|
||
|
{{% notice warning %}}
|
||
|
Usa este método solo en tiempo de desarrollo. No la uses en producción.
|
||
|
{{% /notice %}}
|
||
|
|
||
|
|
||
|
### mri
|
||
|
|
||
|
[MRI][2] es la mejor extensión para inspeccionar cualquier objeto UNO de LibreOffice. Necesita instalarla primero para poder llamarla.
|
||
|
|
||
|
|
||
|
```python
|
||
|
def inspeccionar_objeto():
|
||
|
obj = app.active
|
||
|
app.mri(obj)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
### inspect
|
||
|
|
||
|
Inspeccionar un objeto.
|
||
|
|
||
|
```python
|
||
|
def inspeccionar_objeto():
|
||
|
doc = app.active
|
||
|
data = app.inspect(doc)
|
||
|
for p in data.properties:
|
||
|
app.debug(p)
|
||
|
for m in data.methods:
|
||
|
app.debug(m)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
Vaciar en una hoja de calculo.
|
||
|
|
||
|
```python
|
||
|
def inspeccionar_objeto():
|
||
|
doc = app.active
|
||
|
app.inspect(doc, True)
|
||
|
return
|
||
|
```
|
||
|
|
||
|
|
||
|
[1]: https://git.cuates.net/elmau/easymacro/issues
|
||
|
[2]: https://github.com/hanya/MRI
|