[PATCH] Format the help text to properly fit to the terminal window

Chris Lumens clumens at redhat.com
Fri May 16 18:37:06 UTC 2014


> +# Help text formatting constants
> +
> +LEFT_PADDING = 8  # the help text will start after 8 spaces
> +RIGHT_PADDING = 8  # there will be 8 spaces left on the right
> +HELP_WIDTH = 80
> +
> +# try to detect the terminal window size
> +try:
> +    columns = int(os.popen('stty size', 'r').read().split()[1])
> +    # apply the right padding
> +    columns = columns - RIGHT_PADDING
> +    if columns > 0:
> +        HELP_WIDTH = columns
> +# pylint: disable=broad-except
> +except Exception as e:
> +    # detection failed, use the default
> +    # NOTE: quite a lot can go wrong with the terminal window size detection
> +    # so we try to make sure it doesn't bring down the rest of Anaconda
> +    print("anaconda argparse: terminal size detection failed, using default width")
> +    print(e)
> +
>  class AnacondaArgumentParser(ArgumentParser):
>      """
>      Subclass of ArgumentParser that also examines boot arguments.

My concern about putting code at the module-level is the potential for
it to be run every time the module is imported, which is currently three
times in anaconda the file.  If this is in fact happening, it'd be worth
guarding the try block with something to test whether or not it's
already been run.

- Chris


More information about the anaconda-patches mailing list