def _make_render_all_properties(bases): """ Creates ``render()`` method, rendering all properties of instance. :param tuple bases: Base classes of new command class. :returns: Rendering method taking CIM instance as an argument. :rtype: function """ if util.is_abstract_method(bases, 'render', missing_is_abstract=True): def _render(_self, inst): """ Return tuple of ``(column_names, values)`` ready for output by formatter. """ column_names, values = [], [] for prop_name, value in inst.properties.items(): column_names.append(prop_name) if value is None: value = '' values.append(value) return (column_names, values) return _render
def _make_render_all_properties(bases): """ Creates ``render()`` method, rendering all properties of instance. :param tuple bases: Base classes of new command class. :returns: Rendering method taking CIM instance as an argument. :rtype: function """ if util.is_abstract_method(bases, "render", missing_is_abstract=True): def _render(_self, inst): """ Return tuple of ``(column_names, values)`` ready for output by formatter. """ column_names, values = [], [] for prop_name, value in inst.properties.items(): column_names.append(prop_name) if value is None: value = "" values.append(value) return (column_names, values) return _render
def dest_pos_args_count(cls): """ Number of positional arguments the associated function takes from command. These arguments are created by the command alone -- they do not belong to options in usage string. Function can take additional positional arguments that need to be covered by usage string. :rtype: integer """ dest = getattr(cls.execute, "dest", cls.execute) abstract = dest == cls.execute and util.is_abstract_method( cls, 'execute', True) # if the destination function is not yet defined (abstract is True) # let's assume it's not a method => 0 positional arguments needed return 1 if not abstract and inspect.ismethod(dest) else 0
def _make_execute_method(bases, dcl, func): """ Creates ``execute()`` method of a new end point command. :param tuple bases: Base classes of new command. :param dictionary dcl: Class dictionary being modified by this method. :param callable func: A callable wrapped by this new command. It's usually being referred to as *associated function*. If ``None``, no function will be created -- ``dcl`` won't be modified. """ if func is not None and util.is_abstract_method( bases, 'execute', missing_is_abstract=True): del dcl['CALLABLE'] def _execute(__self__, __connection__, *args, **kwargs): """ Invokes associated function with given arguments. """ return func(__connection__, *args, **kwargs) _execute.dest = func dcl['execute'] = _execute