euporie.core.convert.utils

Utility functions for format converters.

Functions

call_subproc(data, cmd[, use_tempfile, suffix])

Call the command as a subprocess and return it's output as bytes.

commands_exist(*cmds)

Verify a list of external commands exist on the system.

convert(data, from_, to[, cols, rows, fg, ...])

Convert between formats.

data_pixel_size(data, format_[, fg, bg])

Get the dimensions of an image.

get_app()

Get the current active (running) Application.

have_modules(*modules)

Verify a list of python modules are importable.

import_module(name[, package])

Import a module.

pixels_to_cell_size([px, py])

Get the cell width and aspect ration of a pixel dimension.

reduce(function, iterable[, initial])

Apply a function of two arguments cumulatively to the items of a sequence or iterable, from left to right, so as to reduce the iterable to a single value.

to_filter(bool_or_filter)

Accept both booleans and Filters as input and turn it into a Filter.

which(cmd[, mode, path])

Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file.

Classes

Condition(func)

Turn any callable into a Filter.

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

async euporie.core.convert.utils.call_subproc(data: str | bytes, cmd: list[Any], use_tempfile: bool = False, suffix: str = '') bytes

Call the command as a subprocess and return it’s output as bytes.

Parameters
  • data – The data to pass to the subprocess

  • cmd – The command and arguments to call

  • use_tempfile – If True, the command saves its output to a file, not stdout

  • suffix – Suffix for the temporary file name

Returns

The data printed to standard out by the subprocess.

euporie.core.convert.utils.commands_exist(*cmds: str) Filter

Verify a list of external commands exist on the system.

euporie.core.convert.utils.data_pixel_size(data: Any, format_: str, fg: str | None = None, bg: str | None = None) tuple[int | None, int | None]

Get the dimensions of an image.

Foreground and background color are set at this point if they are available, as data conversion outputs are cached and re-used.

Parameters
  • data – The data to check the dimensions of

  • format – The current format of the data

  • fg – The desired foreground color of the data

  • bg – The desired background color of the data

Returns

A tuple of the data’s width in terminal columns and its aspect ratio, when

converted to a image.

euporie.core.convert.utils.have_modules(*modules: str) Filter

Verify a list of python modules are importable.

euporie.core.convert.utils.pixels_to_cell_size(px: int | None = None, py: int | None = None) tuple[int, float]

Get the cell width and aspect ration of a pixel dimension.

Parameters
  • px – The desired pixel width of the data if known

  • py – The pixel height of the data if known

Returns

A tuple of the data’s width in terminal columns and its aspect ratio, when

converted to a image.