Blender V4.3
bpy_cli_command.cc File Reference

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" " :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()

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

Definition at line 63 of file bpy_cli_command.cc.

References bpy_context_clear(), bpy_context_set(), and py_argv_from_bytes().

Referenced by BPyCommandHandler::exec().

◆ bpy_cli_command_free()

static void bpy_cli_command_free ( PyObject * py_exec_fn)
static

Definition at line 147 of file bpy_cli_command.cc.

Referenced by BPyCommandHandler::~BPyCommandHandler().

◆ bpy_cli_command_register()

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

◆ bpy_cli_command_unregister()

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

◆ py_argv_from_bytes()

static 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 36 of file bpy_cli_command.cc.

References BLI_assert, 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" " :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 26 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 27 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 298 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 304 of file bpy_cli_command.cc.

Referenced by BPy_init_modules().