def renderer_doc(*args): ''' .. versionadded:: Lithium Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json ''' renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for fun in renderers_.keys(): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs) for module in args: for fun in renderers_.keys(): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs)
def returner_doc(*args): ''' Return the docstrings for all returners. Optionally, specify a returner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple returners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.returner_doc salt '*' sys.returner_doc sqlite3 salt '*' sys.returner_doc sqlite3.get_fun salt '*' sys.returner_doc sqlite3.get_fun etcd.get_fun Returner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.returner_doc 'sqlite3.get_*' ''' returners_ = salt.loader.returners(__opts__, []) docs = {} if not args: for fun in returners_: docs[fun] = returners_[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if '*' in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' if _use_fnmatch: for fun in returners_: if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ else: for fun in six.iterkeys(returners_): if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ return _strip_rst(docs)
def returner_doc(*args): """ Return the docstrings for all returners. Optionally, specify a returner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple returners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.returner_doc salt '*' sys.returner_doc sqlite3 salt '*' sys.returner_doc sqlite3.get_fun salt '*' sys.returner_doc sqlite3.get_fun etcd.get_fun Returner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.returner_doc 'sqlite3.get_*' """ returners_ = salt.loader.returners(__opts__, []) docs = {} if not args: for fun in returners_: docs[fun] = returners_[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in returners_: if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ else: for fun in six.iterkeys(returners_): if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ return _strip_rst(docs)
def runner_doc(*args): """ Return the docstrings for all runners. Optionally, specify a runner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple runners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.runner_doc salt '*' sys.runner_doc cache salt '*' sys.runner_doc cache.grains salt '*' sys.runner_doc cache.grains mine.get Runner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.runner_doc 'cache.clear_*' """ run_ = salt.runner.Runner(__opts__) docs = {} if not args: for fun in run_.functions: docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in fnmatch.filter(run_.functions, target_mod): docs[fun] = run_.functions[fun].__doc__ else: for fun in run_.functions: if fun == module or fun.startswith(target_mod): docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs)
def runner_doc(*args): ''' Return the docstrings for all runners. Optionally, specify a runner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple runners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.runner_doc salt '*' sys.runner_doc cache salt '*' sys.runner_doc cache.grains salt '*' sys.runner_doc cache.grains mine.get Runner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.runner_doc 'cache.clear_*' ''' run_ = salt.runner.Runner(__opts__) docs = {} if not args: for fun in run_.functions: docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if '*' in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' if _use_fnmatch: for fun in fnmatch.filter(run_.functions, target_mod): docs[fun] = run_.functions[fun].__doc__ else: for fun in run_.functions: if fun == module or fun.startswith(target_mod): docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs)
def doc(*args): ''' Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.doc salt '*' sys.doc sys salt '*' sys.doc sys.doc salt '*' sys.doc network.traceroute user.info Modules can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.doc 'sys.*' salt '*' sys.doc 'sys.list_*' ''' docs = {} if not args: for fun in __salt__: docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if '*' in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' if _use_fnmatch: for fun in fnmatch.filter(__salt__.keys(), target_mod): # pylint: disable=incompatible-py3-code docs[fun] = __salt__[ fun].__doc__ # There's no problem feeding fnmatch.filter() else: # with a Py3's dict_keys() instance for fun in __salt__: if fun == module or fun.startswith(target_mod): docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs)
def doc(*args): """ Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.doc salt '*' sys.doc sys salt '*' sys.doc sys.doc salt '*' sys.doc network.traceroute user.info Modules can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.doc 'sys.*' salt '*' sys.doc 'sys.list_*' """ docs = {} if not args: for fun in __salt__: docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in fnmatch.filter(__salt__, target_mod): docs[fun] = __salt__[fun].__doc__ else: for fun in __salt__: if fun == module or fun.startswith(target_mod): docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs)
def doc(*args): """ Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.doc salt '*' sys.doc sys salt '*' sys.doc sys.doc salt '*' sys.doc network.traceroute user.info Modules can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.doc 'sys.*' salt '*' sys.doc 'sys.list_*' """ docs = {} if not args: for fun in __salt__: docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in fnmatch.filter(__salt__.keys(), target_mod): # pylint: disable=incompatible-py3-code docs[fun] = __salt__[fun].__doc__ # There's no problem feeding fnmatch.filter() else: # with a Py3's dict_keys() instance for fun in __salt__: if fun == module or fun.startswith(target_mod): docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs)
def doc(*args): ''' Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.doc salt '*' sys.doc sys salt '*' sys.doc sys.doc salt '*' sys.doc network.traceroute user.info Modules can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.doc 'sys.*' salt '*' sys.doc 'sys.list_*' ''' docs = {} if not args: for fun in __salt__: docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if '*' in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' if _use_fnmatch: for fun in fnmatch.filter(__salt__.keys(), target_mod): docs[fun] = __salt__[fun].__doc__ else: for fun in __salt__: if fun == module or fun.startswith(target_mod): docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs)
def state_doc(*args): ''' .. versionadded:: 2014.7.0 Return the docstrings for all states. Optionally, specify a state or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple states/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.state_doc salt '*' sys.state_doc service salt '*' sys.state_doc service.running salt '*' sys.state_doc service.running ipables.append ''' st_ = salt.state.State(__opts__) docs = {} if not args: for fun in st_.states: state = fun.split('.')[0] if state not in docs: if hasattr(st_.states[fun], '__globals__'): docs[state] = st_.states[fun].__globals__['__doc__'] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs) for module in args: if module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' for fun in st_.states: if fun == module or fun.startswith(target_mod): state = module.split('.')[0] if state not in docs: if hasattr(st_.states[fun], '__globals__'): docs[state] = st_.states[fun].__globals__['__doc__'] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs)
def _parse_module_docs(module_path, mod_name=None): """ Gather module docstrings or module.function doc string if requested """ ret = {} with salt.utils.files.fopen(module_path, "r", encoding="utf8") as cur_file: tree = ast.parse(cur_file.read()) module_name = _get_module_name(tree, module_path) if not mod_name or "." not in mod_name: # Return top level docs for the module if a function is not requested ret[module_name] = ast.get_docstring(tree) fun_aliases = _get_func_aliases(tree) functions = [ node for node in tree.body if isinstance(node, ast.FunctionDef) ] for fn in functions: doc_string = ast.get_docstring(fn) if not fn.name.startswith("_"): function_name = fn.name if fun_aliases: # Translate name to __func_alias__ version for k, v in fun_aliases.items(): if fn.name == k: function_name = v if mod_name and "." in mod_name: if function_name == mod_name.split(".")[1]: ret["{}.{}".format(module_name, function_name)] = doc_string else: ret["{}.{}".format(module_name, function_name)] = doc_string return _strip_rst(ret)
def utils_doc(*args): ''' .. versionadded:: Neon Return the docstrings for all utils modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.utils_doc salt '*' sys.utils_doc data stringutils salt '*' sys.utils_doc stringutils.to_unicode salt '*' sys.utils_doc data.encode data.decode ''' docs = {} if not args: for fun in __utils__: docs[fun] = __utils__[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if '*' in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' if _use_fnmatch: for fun in fnmatch.filter(__utils__, target_mod): docs[fun] = __utils__[fun].__doc__ else: for fun in __utils__: if fun == module or fun.startswith(target_mod): docs[fun] = __utils__[fun].__doc__ return _strip_rst(docs)
def renderer_doc(*args): ''' Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json Renderer names can be specified as globs. .. code-block:: bash salt '*' sys.renderer_doc 'c*' 'j*' ''' renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for fun in six.iterkeys(renderers_): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs) for module in args: if '*' in module: for fun in fnmatch.filter(renderers_.keys(), module): # pylint: disable=incompatible-py3-code docs[fun] = renderers_[ fun].__doc__ # There's no problem feeding fnmatch.filter() # with a Py3's dict_keys() instance else: for fun in six.iterkeys(renderers_): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs)
def renderer_doc(*args): ''' Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json Renderer names can be specified as globs. .. code-block:: bash salt '*' sys.renderer_doc 'c*' 'j*' ''' renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for func in six.iterkeys(renderers_): docs[func] = renderers_[func].__doc__ return _strip_rst(docs) for module in args: if '*' in module or '.' in module: for func in fnmatch.filter(renderers_, module): docs[func] = renderers_[func].__doc__ else: moduledot = module + '.' for func in six.iterkeys(renderers_): if func.startswith(moduledot): docs[func] = renderers_[func].__doc__ return _strip_rst(docs)
def renderer_doc(*args): """ Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json Renderer names can be specified as globs. .. code-block:: bash salt '*' sys.renderer_doc 'c*' 'j*' """ renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for func in six.iterkeys(renderers_): docs[func] = renderers_[func].__doc__ return _strip_rst(docs) for module in args: if "*" in module or "." in module: for func in fnmatch.filter(renderers_, module): docs[func] = renderers_[func].__doc__ else: moduledot = module + "." for func in six.iterkeys(renderers_): if func.startswith(moduledot): docs[func] = renderers_[func].__doc__ return _strip_rst(docs)
def renderer_doc(*args): """ Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json Renderer names can be specified as globs. .. code-block:: bash salt '*' sys.renderer_doc 'c*' 'j*' """ renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for fun in six.iterkeys(renderers_): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs) for module in args: if "*" in module: for fun in fnmatch.filter(renderers_.keys(), module): # pylint: disable=incompatible-py3-code docs[fun] = renderers_[fun].__doc__ # There's no problem feeding fnmatch.filter() # with a Py3's dict_keys() instance else: for fun in six.iterkeys(renderers_): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs)
def renderer_doc(*args): ''' .. versionadded:: Lithium Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. CLI Example: .. code-block:: bash salt '*' sys.renderer_doc salt '*' sys.renderer_doc cheetah salt '*' sys.renderer_doc jinja json .. versionadded:: Lithium Renderer names can be specified as globs. salt '*' sys.renderer_doc 'c*' 'j*' ''' renderers_ = salt.loader.render(__opts__, []) docs = {} if not args: for fun in renderers_.keys(): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs) for module in args: if '*' in module: for fun in fnmatch.filter(list(renderers_.keys()), module): docs[fun] = renderers_[fun].__doc__ else: for fun in renderers_.keys(): docs[fun] = renderers_[fun].__doc__ return _strip_rst(docs)
def runner_doc(*args): ''' .. versionadded:: Helium Return the docstrings for all runners. Optionally, specify a runner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple runners/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.runner_doc salt '*' sys.runner_doc cache salt '*' sys.runner_doc cache.grains salt '*' sys.runner_doc cache.grains mine.get ''' run_ = salt.runner.Runner(__opts__) docs = {} if not args: for fun in run_.functions: docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs) for module in args: if module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' for fun in run_.functions: if fun == module or fun.startswith(target_mod): docs[fun] = run_.functions[fun].__doc__ return _strip_rst(docs)
def returner_doc(*args): ''' .. versionadded:: Helium Return the docstrings for all returners. Optionally, specify a returner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple returners/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.returner_doc salt '*' sys.returner_doc sqlite3 salt '*' sys.returner_doc sqlite3.get_fun salt '*' sys.returner_doc sqlite3.get_fun etcd.get_fun ''' returners_ = salt.loader.returners(__opts__, []) docs = {} if not args: for fun in returners_.keys(): docs[fun] = returners_[fun].__doc__ return _strip_rst(docs) for module in args: if module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' for fun in returners_.keys(): if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ return _strip_rst(docs)
def returner_doc(*args): ''' .. versionadded:: 2014.7.0 Return the docstrings for all returners. Optionally, specify a returner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple returners/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.returner_doc salt '*' sys.returner_doc sqlite3 salt '*' sys.returner_doc sqlite3.get_fun salt '*' sys.returner_doc sqlite3.get_fun etcd.get_fun ''' returners_ = salt.loader.returners(__opts__, []) docs = {} if not args: for fun in returners_: docs[fun] = returners_[fun].__doc__ return _strip_rst(docs) for module in args: if module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' for fun in returners_: if fun == module or fun.startswith(target_mod): docs[fun] = returners_[fun].__doc__ return _strip_rst(docs)
def get_docs(self, arg=None): ''' Return a dictionary of functions and the inline documentation for each ''' if arg: target_mod = arg + '.' if not arg.endswith('.') else arg docs = [(fun, self.functions[fun].__doc__) for fun in sorted(self.functions) if fun == arg or fun.startswith(target_mod)] else: docs = [(fun, self.functions[fun].__doc__) for fun in sorted(self.functions)] docs = dict(docs) return _strip_rst(docs)
def doc(*args): ''' Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.doc salt '*' sys.doc sys salt '*' sys.doc sys.doc salt '*' sys.doc network.traceroute user.info ''' docs = {} if not args: for fun in __salt__: docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs) for module in args: if module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + '.' if not module.endswith('.') else module else: target_mod = '' for fun in __salt__: if fun == module or fun.startswith(target_mod): docs[fun] = __salt__[fun].__doc__ return _strip_rst(docs)
def state_doc(*args): """ Return the docstrings for all states. Optionally, specify a state or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple states/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.state_doc salt '*' sys.state_doc service salt '*' sys.state_doc service.running salt '*' sys.state_doc service.running ipables.append State names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.state_doc 'service.*' 'iptables.*' """ st_ = salt.state.State(__opts__) docs = {} if not args: for fun in st_.states: state = fun.split(".")[0] if state not in docs: if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__["__doc__"] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in fnmatch.filter(st_.states, target_mod): state = fun.split(".")[0] if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__["__doc__"] docs[fun] = st_.states[fun].__doc__ else: for fun in st_.states: if fun == module or fun.startswith(target_mod): state = module.split(".")[0] if state not in docs: if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__["__doc__"] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs)
def state_doc(*args): """ Return the docstrings for all states. Optionally, specify a state or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple states/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.state_doc salt '*' sys.state_doc service salt '*' sys.state_doc service.running salt '*' sys.state_doc service.running ipables.append State names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.state_doc 'service.*' 'iptables.*' """ st_ = salt.state.State(__opts__) docs = {} if not args: for fun in st_.states: state = fun.split(".")[0] if state not in docs: if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__["__doc__"] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs) for module in args: _use_fnmatch = False if "*" in module: target_mod = module _use_fnmatch = True elif module: # allow both "sys" and "sys." to match sys, without also matching # sysctl target_mod = module + "." if not module.endswith(".") else module else: target_mod = "" if _use_fnmatch: for fun in fnmatch.filter(st_.states, target_mod): state = fun.split(".")[0] if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__["__doc__"] docs[fun] = st_.states[fun].__doc__ else: for fun in st_.states: if fun == module or fun.startswith(target_mod): state = module.split(".")[0] if state not in docs: if hasattr(st_.states[fun], "__globals__"): docs[state] = st_.states[fun].__globals__[ "__doc__"] docs[fun] = st_.states[fun].__doc__ return _strip_rst(docs)