Blender V5.0
bpy_cli_command.cc File Reference
#include <Python.h>
#include "BLI_utildefines.h"
#include "bpy_capi_utils.hh"
#include "BKE_blender_cli_command.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "bpy_cli_command.hh"

Go to the source code of this file.

Classes

class  BPyCommandHandler

Functions

Internal Utilities
static PyObject * py_argv_from_bytes (const int argc, const char **argv)
Internal Implementation
static int bpy_cli_command_exec (bContext *C, PyObject *py_exec_fn, const int argc, const char **argv)
static void bpy_cli_command_free (PyObject *py_exec_fn)

Variables

static const char * bpy_cli_command_capsule_name = "bpy_cli_command"
static const char * bpy_cli_command_capsule_name_invalid = "bpy_cli_command<invalid>"

Public Methods

PyMethodDef BPY_cli_command_register_def
PyMethodDef BPY_cli_command_unregister_def
 PyDoc_STRVAR (bpy_cli_command_register_doc, ".. method:: register_cli_command(id, execute)\n" "\n" " Register a command, accessible via the (``-c`` / ``--command``) command-line argument.\n" "\n" " :arg id: The command identifier (must pass an ``str.isidentifier`` check).\n" "\n" " If the ``id`` is already registered, a warning is printed and " "the command is inaccessible to prevent accidents invoking the wrong command.\n" " :type id: str\n" " :arg execute: Callback, taking a single list of strings and returns an int.\n" " The arguments are built from all command-line arguments following the command id.\n" " The return value should be 0 for success, 1 on failure " "(specific error codes from the ``os`` module can also be used).\n" " :type execute: callable\n" " :return: The command handle which can be passed to :func:`unregister_cli_command`.\n" "\n" " This uses Python's capsule type " "however the result should be considered an opaque handle only used for unregistering.\n" " :rtype: capsule\n")
static PyObject * bpy_cli_command_register (PyObject *, PyObject *args, PyObject *kw)
 PyDoc_STRVAR (bpy_cli_command_unregister_doc, ".. method:: unregister_cli_command(handle)\n" "\n" " Unregister a CLI command.\n" "\n" " :arg handle: The return value of :func:`register_cli_command`.\n" " :type handle: capsule\n")
static PyObject * bpy_cli_command_unregister (PyObject *, PyObject *value)

Detailed Description

Wrap BKE_command_cli_* to support custom CLI commands.

Definition in file bpy_cli_command.cc.

Function Documentation

◆ bpy_cli_command_exec()

int bpy_cli_command_exec ( bContext * C,
PyObject * py_exec_fn,
const int argc,
const char ** argv )
static

◆ bpy_cli_command_free()

void bpy_cli_command_free ( PyObject * py_exec_fn)
static

Definition at line 144 of file bpy_cli_command.cc.

References Py_DECREF().

Referenced by BPyCommandHandler::~BPyCommandHandler().

◆ bpy_cli_command_register()

PyObject * bpy_cli_command_register ( PyObject * ,
PyObject * args,
PyObject * kw )
static

◆ bpy_cli_command_unregister()

PyObject * bpy_cli_command_unregister ( PyObject * ,
PyObject * value )
static

◆ py_argv_from_bytes()

PyObject * py_argv_from_bytes ( const int argc,
const char ** argv )
static

Return a list of strings, compatible with the construction of Python's sys.argv.

Definition at line 33 of file bpy_cli_command.cc.

References BLI_assert, i, status, and UNLIKELY.

Referenced by bpy_cli_command_exec().

◆ PyDoc_STRVAR() [1/2]

PyDoc_STRVAR ( bpy_cli_command_register_doc ,
".. method:: register_cli_command(id, execute)\n" "\n" " Register a command,
accessible via the(``-c``/``--command``) command-line argument.\n" "\n" " :arg id:The command identifier(must pass an ``str.isidentifier`` check).\n" "\n" " If the ``id`` is already registered,
a warning is printed and " "the command is inaccessible to prevent accidents invoking the wrong command.\n" " :type id:str\n" " :arg execute:Callback ,
taking a single list of strings and returns an int.\n" " The arguments are built from all command-line arguments following the command id.\n" " The return value should be 0 for success,
1 on failure " "(specific error codes from the ``os`` module can also be used).\n" " :type execute:callable\n" " :return:The command handle which can be passed to :func:`unregister_cli_command`.\n" "\n" " This uses Python 's capsule type " "however the result should be considered an opaque handle only used for unregistering.\n" " :rtype:capsule\n"  )

◆ PyDoc_STRVAR() [2/2]

PyDoc_STRVAR ( bpy_cli_command_unregister_doc ,
".. method:: unregister_cli_command(handle)\n" "\n" " Unregister a CLI command.\n" "\n" " :arg handle: The return value of :func:`register_cli_command`.\n" " :type handle: capsule\n"  )

Variable Documentation

◆ bpy_cli_command_capsule_name

const char* bpy_cli_command_capsule_name = "bpy_cli_command"
static

Definition at line 23 of file bpy_cli_command.cc.

Referenced by bpy_cli_command_register(), and bpy_cli_command_unregister().

◆ bpy_cli_command_capsule_name_invalid

const char* bpy_cli_command_capsule_name_invalid = "bpy_cli_command<invalid>"
static

Definition at line 24 of file bpy_cli_command.cc.

Referenced by bpy_cli_command_unregister().

◆ BPY_cli_command_register_def

PyMethodDef BPY_cli_command_register_def
Initial value:
= {
"register_cli_command",
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_cli_command_register_doc,
}
static PyObject * bpy_cli_command_register(PyObject *, PyObject *args, PyObject *kw)

Definition at line 303 of file bpy_cli_command.cc.

Referenced by BPy_init_modules().

◆ BPY_cli_command_unregister_def

PyMethodDef BPY_cli_command_unregister_def
Initial value:
= {
"unregister_cli_command",
METH_STATIC | METH_O,
bpy_cli_command_unregister_doc,
}
static PyObject * bpy_cli_command_unregister(PyObject *, PyObject *value)

Definition at line 309 of file bpy_cli_command.cc.

Referenced by BPy_init_modules().