[anaconda:rhel7/master] Add option help text for --image and --dirinstall flags (#1056791)
Vratislav Podzimek
vpodzime at redhat.com
Fri Jan 31 09:03:59 UTC 2014
On Thu, 2014-01-30 at 12:27 -0500, mulhern wrote:
> Resolves: rhbz#1056791
>
> The help text is now in a separate date file anaconda_options.txt, as
> putting it in-line would be distracting.
> It is in a text file with very simple formatting requirements because the
> more fancy data formats like configurations or JSON are kind of awkward to
> edit by hand in the way that you would like to edit help text.
>
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
> anaconda | 8 +++--
> data/Makefile.am | 3 ++
> data/anaconda_options.txt | 17 +++++++++++
> pyanaconda/anaconda_optparse.py | 66 +++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 92 insertions(+), 2 deletions(-)
> create mode 100644 data/anaconda_options.txt
>
> diff --git a/anaconda b/anaconda
> index 8ec0363..9030eb1 100755
> --- a/anaconda
> +++ b/anaconda
> @@ -200,6 +200,7 @@ def getAnacondaVersion():
>
> def parseOptions(argv=None, cmdline=None):
> from pyanaconda.anaconda_optparse import AnacondaOptionParser
> + from pyanaconda.anaconda_optparse import HelpTextParser
>
> # NOTE: for each long option (like '--repo'), AnacondaOptionParser
> # checks the boot arguments for bootarg_prefix+option ('inst.repo').
> @@ -208,6 +209,7 @@ def parseOptions(argv=None, cmdline=None):
> # See anaconda_optparse.py and BootArgs (in flags.py) for details.
> op = AnacondaOptionParser(version="%prog " + getAnacondaVersion(),
> bootarg_prefix="inst.", require_prefix=False)
> + help_parser = HelpTextParser("/usr/share/anaconda/anaconda_options.txt")
>
> # NOTE: store_false options will *not* get negated when the user does
> # "option=0" on the boot commandline (store_true options do, though).
> @@ -284,8 +286,10 @@ def parseOptions(argv=None, cmdline=None):
> op.add_option("--nomount", dest="rescue_nomount", action="store_true", default=False)
> op.add_option("--updates", dest="updateSrc", action="store", type="string")
> op.add_option("--dlabel", action="store_true", default=False)
> - op.add_option("--image", action="append", dest="images", default=[])
> - op.add_option("--dirinstall", action="store_true", default=False)
> + op.add_option("--image", action="append", dest="images", default=[],
> + metavar="IMAGE_SPEC", help=help_parser.help_text("image"))
> + op.add_option("--dirinstall", action="store_true", default=False,
> + help=help_parser.help_text("dirinstall"))
> op.add_option("--memcheck", action="store_true", default=True)
> op.add_option("--nomemcheck", action="store_false", dest="memcheck")
> op.add_option("--leavebootorder", action="store_true", default=False)
> diff --git a/data/Makefile.am b/data/Makefile.am
> index 2f66b00..b7eddfe 100644
> --- a/data/Makefile.am
> +++ b/data/Makefile.am
> @@ -27,4 +27,7 @@ dist_ks_DATA = interactive-defaults.ks
> tmuxdir = $(datadir)/$(PACKAGE_NAME)
> dist_tmux_DATA = tmux.conf
>
> +helpdir = $(datadir)/$(PACKAGE_NAME)
> +dist_help_DATA = anaconda_options.txt
> +
> MAINTAINERCLEANFILES = Makefile.in
> diff --git a/data/anaconda_options.txt b/data/anaconda_options.txt
> new file mode 100644
> index 0000000..6dc90c4
> --- /dev/null
> +++ b/data/anaconda_options.txt
> @@ -0,0 +1,17 @@
> +dirinstall
> +Use the device mounted at /mnt/sysimage as the installation
> +destination. The --dirinstall and --image options are mutually
> +exclusive.
> +
> +image
> +Specification of disk image file to be used as installation
> +destination. IMAGE_SPEC must have format <path>[:<name>] where
> +<path> specifies the path of an image file and an optional <name>
> +component is used to identify the disk during installation.
> +<path> must be a local path but it may be relative or absolute.
> +If <name> is not specified, a name is synthesized from the
> +basename of <path>. <name> may not contain a colon or a slash.
> +This option may be used multiple times to specify multiple disk
> +images. It is an error to specify the same <path> twice or to use
> +duplicate names. The --image and --dirinstall options are
> +mutually exclusive.
> diff --git a/pyanaconda/anaconda_optparse.py b/pyanaconda/anaconda_optparse.py
> index 37f4b86..b0a3688 100644
> --- a/pyanaconda/anaconda_optparse.py
> +++ b/pyanaconda/anaconda_optparse.py
> @@ -19,6 +19,9 @@
> # Authors:
> # Will Woods <wwoods at redhat.com>
>
> +import contextlib
> +import os
> +
> from flags import BootArgs
> from optparse import OptionParser, OptionConflictError
>
> @@ -124,3 +127,66 @@ class AnacondaOptionParser(OptionParser):
> values = self.get_default_values()
> v = self.parse_boot_cmdline(cmdline, values)
> return OptionParser.parse_args(self, args, v)
> +
> +class HelpTextParser(object):
> + """Class to parse help text from file and make it available to option
> + parser.
> + """
> +
> + def __init__(self, path):
> + """ Initializer
> + :param path: The absolute path to the help text file
> + """
> + # path --- the path to the file containing the help text
> + if not os.path.isabs(path):
> + raise ValueError("path %s is not an absolute path" % path)
> + self._path = path
> +
> + # _help_text --- the help text, as a dictionary of option,
> + self._help_text = None
> +
> + def read(self, lines):
> + """Reads option, help text pairs from a text file.
> +
> + Each pair is separated from the next by an empty line.
> + The option comes first, followed by any number of lines of help text.
> +
> + :param lines: a sequence of lines of text
> + """
> + if not lines:
> + return
> + expect_option = True
> + option = None
> + text = []
> + for line in (line.strip() for line in lines):
> + if line == "":
> + expect_option = True
> + elif expect_option:
> + if option:
> + yield option, " ".join(text)
> + option = line
> + text = []
> + expect_option = False
> + else:
> + text.append(line)
> + yield option, " ".join(text)
> +
> + def help_text(self, option):
> + """
> + Returns the help text corresponding to the given command-line option.
> + If no help text is available, returns the empty string.
> +
> + :param str option: The name of the option
> +
> + :rtype: str
> + """
> + if self._help_text is None:
> + self._help_text = {}
> + try:
> + with contextlib.closing(open(self._path)) as lines:
I believe the file object's __exit__ closes the file, so no need for
contextlib.closin() call here.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list