19.2.4 Checking the health of script files
The following table shows how to check the health of the created script file.
How to check |
Description |
---|---|
Operation-command pyflakes |
Check using a syntax checker called "pyflakes(pyflakes3k)" that is published on PyPI(Python library (public site). |
Pdb Modules |
Use the debuggers provided as a standardized library of Python to check them. You can set breakpoints and perform step execution. |
Operation-command dump script-user-program |
Obtain and check the standard error output by the resident script. |
- <Structure of this section>
(1) Checking by operation-command pyflakes
When an operation command pyflakes is executed, the syntax of the specified file is checked by pyflakes(pyflakes3k). The following illustration shows how to use pyflakes commandto perform syntax checking on sample.py files.
> pyflakes sample.py sample.py:4: invalid syntax for cnt in range(10) ^ ..1 > |
-
Indicates that there is an error at the end of for statement.
(2) Verifying with pdb Modules
If you use pdb module in the operation command python, you can use debugger commands to debug the specified file. The following illustration shows how to use pdb module to check the health of sample.py files.
# python -m pdb sample.py ..1 > /usr/home/share/sample.py(1)<module>() -> import os (Pdb) b 4 ..2 Breakpoint 1 at /usr/home/share/sample.py:4 (Pdb) r ..3 > /usr/home/share/sample.py(4)<module>() -> for cnt in range(10): (Pdb) s ..4 > /usr/home/share/sample.py(5)<module>() -> if(cnt == 9): (Pdb) cl ..5 Clear all breaks? y Deleted breakpoint 1 at /usr/home/share/sample.py:4 (Pdb) r --Return-- > /usr/home/share/sample.py(7)<module>()->None -> sys.exit() (Pdb) q ..6 # |
-
-m Optionally use pdb module to run sample.py scripting.
-
The debugger command b (reak) creates a breakpoint on the fourth line of sample.py.
-
Use the debugger command r (un) to run the scripting.
-
Step through the script with debugger commands s (tep) because the breakpoint stopped processing.
-
In the debugger command cl(ear), remove the breakpoint.
-
Exit the debugger with the debugger command q (uit).
(3) Checking by operation-command dump script-user-program
By executing the operation command dump script-user-program, you can obtain the stderr that is output by a resident script. However, standard output cannot be acquired. The following figure shows an example of checking the standard error output of a resident script.
# dump script-user-program ..1 # cd /usr/var/scriptManager ..2 # gzip -d smd_script_user.gz ..3 # cat smd_script_user ..4 [resident tag 1 info] **** 20XX/03/19 17:52:36 UTC **** Script start filename=/usr/var/script/script.file/sample1.py pid=128 **** 20XX/03/19 17:52:36 UTC **** File "/usr/var/script/script.file/sample1.py", line 1 print a ^ SyntaxError: invalid syntax **** 20XX/03/19 17:52:36 UTC **** Script end filename=/usr/var/script/script.file/sample1.py pid=128 : : : # |
-
Outputs a standard error to a file (smd_script_user.gz). This file is created under /usr/var/scriptManager/.
-
Go to /usr/var/scriptManager/.
-
Unzip the smd_script_user.gz.
-
Displays the extracted file.