cape.sysutils: System utilities for using CAPE¶
This module provides various “system” utilities such as providing a universal Python method to open a PDF file for viewing.
- cape.sysutils.get_pdf_viewer() str¶
Get the preferred PDF viewer application based on system
- Call:
>>> viewer = get_pdf_viewer()
- Outputs:
- viewer:
str Name of application to open PDF
- viewer:
- Versions:
2026-08-07
@ddalle: v1.0
- cape.sysutils.get_png_viewer() str¶
Get the preferred PNG viewer application based on system
- Call:
>>> viewer = get_png_viewer()
- Outputs:
- viewer:
str Name of application to open PNG
- viewer:
- Versions:
2026-08-31
@ddalle: v1.0
- cape.sysutils.open_img(fname: str, terminal: bool = True, dpi: int = 120, page: int = 0, width: int | str | None = None) str¶
Attempt to open any image file, preferring in-terminal viewing
- Call:
>>> open_img(fname, wait=False)
- Inputs:
- fname:
str Name of file to open
- terminal: {
True} |False Option to try showing image in terminal
- dpi: {
120} |int Resolution for converting PDFs to PNGs
- page: {
0} |int Zero-based page index of PDF to view in terminal
- width: {
None} |int|str Width, in terminal columns (or percent, e.g.
"50%"), to use when displaying image in terminal;Noneuses the original image size
- fname:
- Output:
- viewer:
str Name of viewer application (or
"terminal"or"pdf")
- viewer:
- cape.sysutils.open_pdf(fname: str, remote: str | None = None, wait: bool = False, pull: bool = False, local: bool | None = None) Popen¶
Open a PDF file if found
- Call:
>>> open_pdf(fname, wait=False)
- Inputs:
- Output:
- proc:
subprocess.Popen Subprocess handle
- proc:
- Versions:
2026-08-07
@ddalle: v1.0
- cape.sysutils.open_png(fname: str, terminal: bool = True, wait: bool = False) str¶
Open a PNG file if found
- cape.sysutils.pdftopng(fpdf: str, fpng: str | None = None, dpi: int = 120, page: int = 0) str¶
Convert one page of a PDF to a PNG image
Uses the first available system command:
pdftoppm(poppler)gs,gswin64c,gswin32c(Ghostscript)pdftocairo(poppler)magickorconvert(ImageMagick)
- Call:
>>> fpng = pdftopng(fpdf, fpng=None, dpi=200, page=0)
- Inputs:
- Outputs:
- fpng:
str Name of PNG file created
- fpng:
- Versions:
2026-08-31
@ddalle: v1.0
- cape.sysutils.post_file(pat1: str, *pats, v: bool = False) Tuple[int, list]¶
Collect file(s) in tar ball; send to RemoteHost if necessary
- cape.sysutils.terminal_image_supported() bool¶
Check if the terminal can display images
Relies on the
textual_imageandrichpackages and checks for sixel or kitty/TGP support.- Call:
>>> q = terminal_image_supported()
- Outputs:
- q:
bool Whether terminal can display images
- q:
- Versions:
2026-09-06
@ddalle: v1.0