Structured scripting within casapy (pwkit.environments.casa.scripting)¶
pwkit.environments.casa.scripting - scripted invocation of casapy.
The “casapy” program is extremely resistant to encapsulated scripting – it pops up GUI windows and child processes, leaves log files around, provides a non-vanilla Python environment, and so on. However, sometimes scripting CASA is what we need to do. This tool enables that.
We provide a single-purpose CLI tool for this functionality, so that you can write standalone scripts with a hashbang line of “#! /usr/bin/env pkcasascript” – hashbang lines support only one extra command-line argument, so if we’re using “env” we can’t take a multitool approach.
- class pwkit.environments.casa.scripting.CasapyScript(script, raise_on_error=True, **kwargs)[source]¶
Context manager for launching a script in the casapy environment. This involves creating a temporary wrapper and then using the CasaEnvironment to run it in a temporary directory.
When this context manager is entered, the script is launched and the calling process waits until it finishes. This object is returned. The with statement body is then executed so that information can be extracted from the results of the casapy invocation. When the context manager is exited, the casapy files are (usually) cleaned up.
Attributes:
- args
the arguments to passed to the script.
- env
the CasaEnvironment used to launch the casapy process.
- exitcode
the exit code of the casapy process. 0 is success. 127 indicates an intentional error exit by the script; additional diagnostics don’t need printing and the work directory doesn’t need preservation. Negative values indicate death from a signal.
- proc
the subprocess.Popen instance of casapy; inside the context manager body it’s already exited.
- rmtree
boolean; whether to delete the working tree upon context manager exit.
- script
the path to the script to be invoked.
- workdir
the working directory in which casapy was started.
- wrapped
the path to the wrapper script run inside casapy.
There is a very large overhead to running casapy scripts. The outer Python code sleeps for at least 5 seconds to allow various cleanups to happen.