[rhinstaller/blivet/pulls/160 master] Deprecate some little-used device lookup methods

dwlehman installerbot-noreply at redhat.com
Fri Jun 26 19:27:54 UTC 2015


> @@ -637,3 +643,105 @@ def eintr_retry_call(func, *args):
>              if e.errno == errno.EINTR:
>                  continue
>              raise
> +
> +#
> +# Deprecation decorator.
> +#
> +_DEPRECATION_MESSAGE = "will be removed in a future version."
> +def _default_deprecation_msg(func):
> +    return "%s %s" % (func.__name__, _DEPRECATION_MESSAGE)
> +
> +def indent(text, spaces=4):
> +    """ Indent text by a specified number of spaces.
> +
> +        :param str text: the text to indent
> +        :keyword int spaces: the number of spaces to indent text
> +    """
> +    if not text or not text.strip():
> +        return text
> +
> +    indentation = " " * spaces
> +    indented = []
> +    for line in text.splitlines():
> +        indented.append("%s%s" % (indentation, line))
> +
> +    return "\n".join(indented)
> +
> +_SPHINX_DEPRECATE = """.. deprecated:: %(version)s
> +    %(message)s
> +"""
> +def _add_deprecation_doc_text(func, version=None, message=None):
> +    """ Add sphinx 'deprecated' markup to a function's docstring.
> +
> +        :param :class:`function` func: the function
> +        :param str version: version in which the deprecation is effective
> +        :param str message: message suggesting a preferred alternative
> +
> +        If your doctext is indented with something other than spaces the added
> +        doctext's indentation will probably not match. That'd be your fault.
> +    """
> +    base_text = func.__doc__
> +    if base_text is None:
> +        base_text = " " # They contain leading and trailing spaces. *shrug*
> +    else:
> +        base_text = base_text[:-1] # Trim the trailing space.
> +
> +    if ".. deprecated::" in base_text:
> +        # Don't add multiple deprecation directives.
> +        return
> +
> +    # Figure out the number of spaces to indent docstring text.
> +    indent_spaces = None

I had myself turned around at some point, clearly, thinking that would prevent it from ever getting set to a non-default value. I'll change it.

-- 
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/160#discussion_r33387762


More information about the anaconda-patches mailing list