easymacro/docs/en/docs/debug.md

199 lines
3.3 KiB
Markdown
Raw Normal View History

2023-12-07 19:08:49 -06:00
## Tools for debug
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
<br>
### **INFO_DEBUG**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Show debugging information in a message box.
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
If you have any problems in your code during the development of your macros, you can [open a ticket][1] support in the system ticket of this project. Always copy the debugging information shown in your issue.
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
```py
2022-08-11 22:33:41 -05:00
import easymacro as app
def info():
app.msgbox(app.INFO_DEBUG)
return
```
2023-04-23 11:31:58 -06:00
![Info debug](img/install_01.png)
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **debug**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Show information at the terminal.
2023-04-23 11:31:58 -06:00
```py
2022-08-11 22:33:41 -05:00
import easymacro as app
def test_debug():
2023-12-07 19:08:49 -06:00
msg = 'Verify this information...'
2022-08-11 22:33:41 -05:00
app.debug(msg)
return
```
2023-12-07 19:08:49 -06:00
To view this message, you need to start LibreOffice from the command line:
2023-04-23 11:31:58 -06:00
```
soffice --calc
```
2023-12-07 19:08:49 -06:00
After executing the previous macro, you should see:
2022-08-11 22:33:41 -05:00
```
2023-12-07 19:08:49 -06:00
21/04/2023 17:04:49 - DEBUG - Verify this information...
2022-08-11 22:33:41 -05:00
```
2023-04-23 11:31:58 -06:00
<br>
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **info**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Show information messages at the terminal.
2023-04-23 11:31:58 -06:00
```py
2022-08-11 22:33:41 -05:00
import easymacro as app
def test_info():
2023-12-07 19:08:49 -06:00
msg = 'Starting process...'
2022-08-11 22:33:41 -05:00
app.info(msg)
return
```
```
2023-12-07 19:08:49 -06:00
11/08/2022 18:23:53 - INFO - Starting process...
2022-08-11 22:33:41 -05:00
```
2023-04-23 11:31:58 -06:00
<br>
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **error**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Show error messages at the terminal.
2023-04-23 11:31:58 -06:00
```py
2022-08-11 22:33:41 -05:00
import easymacro as app
def test_error():
msg = 'Error 505'
app.error(msg)
return
```
```
11/08/2022 18:27:34 - ERROR - Error 505
```
2023-04-23 11:31:58 -06:00
<br>
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **save_log**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Save log in file, automatically add date and time.
2023-04-23 11:31:58 -06:00
```py
2022-08-11 22:33:41 -05:00
import easymacro as app
def test_save_log():
app.save_log('/home/mau/log.txt', 'PyUNO')
2023-12-07 19:08:49 -06:00
app.save_log('/home/mau/log.txt', 'World Damn')
2022-08-11 22:33:41 -05:00
return
```
```
cat ~/log.txt
2022-08-11 18:30:11 - 'PyUNO'
2023-12-07 19:08:49 -06:00
2022-08-11 18:30:11 - 'World Damn'
2022-08-11 22:33:41 -05:00
```
2023-04-23 11:31:58 -06:00
<br>
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **msgbox**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Show any information in a message box.
2022-08-11 22:33:41 -05:00
```python
2023-04-23 11:31:58 -06:00
import easymacro as app
2022-08-11 22:33:41 -05:00
def message():
2023-12-07 19:08:49 -06:00
msg = 'Please, consume less.'
2022-08-11 22:33:41 -05:00
app.msgbox(msg)
2023-12-07 19:08:49 -06:00
msg = ('one', 2, 'three')
2022-08-11 22:33:41 -05:00
app.msgbox(msg)
2023-12-07 19:08:49 -06:00
msg = {'name': 'Teresa'}
2022-08-11 22:33:41 -05:00
app.msgbox(msg)
app.msgbox(app)
return
```
2023-04-23 11:31:58 -06:00
<br>
### **catch_exception**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Capture any error that occurs when running a macro.
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
!!! warning inline end "Caution"
2023-04-23 11:31:58 -06:00
2023-12-07 19:08:49 -06:00
Use this method only in development time. **Do not use it in production**.
2023-04-23 11:31:58 -06:00
```py
import easymacro as app
2022-08-11 22:33:41 -05:00
@app.catch_exception
2023-12-07 19:08:49 -06:00
def test_capture_error():
2022-08-11 22:33:41 -05:00
r = 1 / 0
return
```
```
2023-12-07 19:08:49 -06:00
11/08/2022 18:44:36 - ERROR - test_capture_error
2022-08-11 22:33:41 -05:00
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
```
2023-04-23 11:31:58 -06:00
<br>
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
### **mri**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
[MRI][2] is the best extension to inspect any UNO LibreOffice object. You need to install it first so you can use it.
2022-08-11 22:33:41 -05:00
2023-04-23 11:31:58 -06:00
```py
import easymacro as app
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
def inspect_object():
2022-08-11 22:33:41 -05:00
obj = app.active
app.mri(obj)
return
```
2023-04-23 11:31:58 -06:00
<br>
### **inspect**
2022-08-11 22:33:41 -05:00
2023-12-07 19:08:49 -06:00
Inspect an object.
2023-04-23 11:31:58 -06:00
```py
import easymacro as app
2023-12-07 19:08:49 -06:00
def inspect_object():
2022-08-11 22:33:41 -05:00
doc = app.active
data = app.inspect(doc)
for p in data.properties:
app.debug(p)
for m in data.methods:
app.debug(m)
return
```
2023-12-07 19:08:49 -06:00
Send information of the object to worksheet.
2022-08-11 22:33:41 -05:00
```python
2023-12-07 19:08:49 -06:00
def inspect_object():
2022-08-11 22:33:41 -05:00
doc = app.active
app.inspect(doc, True)
return
```
[1]: https://git.cuates.net/elmau/easymacro/issues
[2]: https://github.com/hanya/MRI