[cura-tools] master: added jewerly belonging to lmi meta-command (135c538)
by miminar@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
>---------------------------------------------------------------
commit 135c538f4a0b29cb0f45e6293b3e3c196a003413
Author: Michal Minar <miminar(a)redhat.com>
Date: Fri Jan 3 12:11:24 2014 +0100
added jewerly belonging to lmi meta-command
Adds:
* bash completion
* man page
* sample configuration file
This is one patch in a series merging lmi meta-command into
openlmi-tools from original upstream on github.
Related to trac ticket #187
>---------------------------------------------------------------
cli/completion/lmi-bash-completion/commands/_help | 9 +
.../lmi-bash-completion/print_possible_commands.sh | 11 +
cli/completion/lmi.bash | 65 +++++++
cli/config/lmi.conf | 58 ++++++
cli/man/Makefile | 14 ++
cli/man/generate.sh | 199 +++++++++++++++++++
cli/man/lmi.1 | 201 ++++++++++++++++++++
7 files changed, 557 insertions(+), 0 deletions(-)
diff --git a/cli/completion/lmi-bash-completion/commands/_help b/cli/completion/lmi-bash-completion/commands/_help
new file mode 100755
index 0000000..ae3ed8b
--- /dev/null
+++ b/cli/completion/lmi-bash-completion/commands/_help
@@ -0,0 +1,9 @@
+#!/bin/bash
+if (( $# > 1 )); then
+ exit
+fi
+helpers_path=lmi-bash-completion
+if ! [[ -e $helpers_path ]]; then
+ helpers_path="/usr/libexec/$helpers_path"
+fi
+compgen "-W $($helpers_path/print_possible_commands.sh)" -- "$1"
diff --git a/cli/completion/lmi-bash-completion/print_possible_commands.sh b/cli/completion/lmi-bash-completion/print_possible_commands.sh
new file mode 100755
index 0000000..ba29a4a
--- /dev/null
+++ b/cli/completion/lmi-bash-completion/print_possible_commands.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# prints possible commands
+# one per line
+# parse lmi help
+re_command="^[[:blank:]]*([[:alnum:]]+)[[:blank:]]*-"
+while IFS= read line; do
+ if [[ $line =~ $re_command ]]; then
+ printf '%s\n' "${BASH_REMATCH[1]}"
+ fi
+done < <(lmi help 2>/dev/null)
diff --git a/cli/completion/lmi.bash b/cli/completion/lmi.bash
new file mode 100644
index 0000000..0aa174b
--- /dev/null
+++ b/cli/completion/lmi.bash
@@ -0,0 +1,65 @@
+#
+# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus(a)redhat.com>
+#
+# Bash completion for LMI commands
+
+_lmi() {
+ local helpers_path="lmi-bash-completion"
+ if ! [[ -e "$helpers_path" ]]; then
+ helpers_path="/usr/libexec/$helpers_path"
+ fi
+ local options=(-c --config-file -h --host --hosts-file --user -v --trace -q --quiet -n --noverify --same-credentials --help --version)
+ local current="${COMP_WORDS[$COMP_CWORD]}"
+ local previous="${COMP_WORDS[COMP_CWORD-1]}"
+ local commands=( $($helpers_path/print_possible_commands.sh) )
+ local used_command=
+
+ for (( i=1; i < ${#COMP_WORDS[@]} - 1 && i < $COMP_CWORD; i++ )); do
+ for (( ci=0; ci < ${#commands[@]}; ci++ )); do
+ if [[ ${COMP_WORDS[$i]} == ${commands[$ci]} ]]; then
+ used_command=${commands[$ci]}
+ break 2;
+ fi
+ done
+ done
+
+ if [[ $used_command ]]; then
+ # Check if we have completion executable for command
+ if [[ -x $helpers_path/commands/"_$used_command" ]] ; then
+ # pass the rest of words typed as parameters
+ COMPREPLY=( $($helpers_path/commands/_$used_command "${COMP_WORDS[@]:$((i+1))}") )
+ else
+ # commands without completion - filename completion
+ COMPREPLY=( $(compgen -f -- "$current") )
+ fi
+ else
+ case $current in
+ -*) COMPREPLY=( $(compgen "-W ${options[*]}" -- "$current" ) );;
+ *) case $previous in
+ -c|--config-file|--hosts-file) COMPREPLY=( $(compgen -f -- "$current" ) );;
+ -h|--host) COMPREPLY=( $(compgen -A hostname -- "$current" ) );;
+ --user) COMPREPLY=( $(compgen -u -- "$current" ) );;
+ --help|--version) ;;
+ *) COMPREPLY=( $(compgen "-W ${commands[*]}" -- "$current" ) );;
+ esac
+ esac
+ fi
+}
+
+complete -F _lmi lmi
diff --git a/cli/config/lmi.conf b/cli/config/lmi.conf
new file mode 100644
index 0000000..ee2998e
--- /dev/null
+++ b/cli/config/lmi.conf
@@ -0,0 +1,58 @@
+# Sample configuration file for OpenLMI script metacommand.
+
+[Main]
+# Python namespace, where command entry points will be searched for.
+#CommandNamespace = lmi.scripts.cmd
+
+# Whether the exceptions should be logged with tracebacks.
+#Trace = False
+
+# An integer from -1 to 2 saying, how verbosive the output to console shall
+# be. This differs from [Log] Level, which controls the logging messages being
+# logged to file. If logging to console is enabled it sets the minimum
+# severity level. -1 Supresses all messages except for critical ones. 0 shows
+# warnings, 1 info messages and 2 enables debug messages. This option also
+# affects the verbosity of commands, making them print more information to
+# stdout.
+#Verbosity = 0
+
+[CIM]
+# To override default CIM namespace, uncomment the line below.
+#namespace = root/cimv2
+
+[SSL]
+# Whether to verify server-side certificate, when making secured connection
+# over ssl.
+#VerifyServerCertificate = True
+
+[Format]
+# Whether to print values in human readable forms (e.g. with units).
+#HumanFriendly = False
+
+# What format to use, when listing tabular data. Possible values are:
+# {csv, table}. The former allows for easy machine parsing, the latter
+# is more human friendly.
+#ListerFormat = table
+
+# Whether to suppress headings (column names) when printing tables.
+#NoHeadings = False
+
+[Log]
+# Level can be set to following values:
+# DEBUG, INFO, WARNING, ERROR, CRITICAL
+# Affects only logging to a file.
+#Level = ERROR
+
+# Format string used, when logging to a console. For details visit:
+# http://docs.python.org/2/library/logging.html#logrecord-attributes
+#ConsoleFormat = %(levelname)s: %(message)s
+
+# Whether the logging to console is enabled.
+#LogToConsole = True
+
+# Format string used, when logging to a file.
+#FileFormat = %(asctime)s:%(levelname)-8s:%(name)s:%(lineno)d - %(message)s
+
+# Allows to set a path to file, where messages will be logged. No log
+# file is written at default.
+#OutputFile =
diff --git a/cli/man/Makefile b/cli/man/Makefile
new file mode 100644
index 0000000..47a3f18
--- /dev/null
+++ b/cli/man/Makefile
@@ -0,0 +1,14 @@
+BUILDDIR ?= .
+MANPAGE := lmi.1
+TARGET := $(BUILDDIR)/$(notdir $(MANPAGE)).gz
+
+.PHONY: clean
+
+$(TARGET): $(MANPAGE)
+ cat $? | gzip > $@
+
+$(MANPAGE): generate.sh ../config/lmi.conf ../lmi/scripts/_metacommand/toplevel.py
+ ./generate.sh $@
+
+clean:
+ rm -f $(TARGET)
diff --git a/cli/man/generate.sh b/cli/man/generate.sh
new file mode 100755
index 0000000..a8a8e8d
--- /dev/null
+++ b/cli/man/generate.sh
@@ -0,0 +1,199 @@
+#!/bin/bash
+# This script needs to be run from openlmi-scripts/man directory. It creates a
+# man page in current directory for lmi meta-command. It's generated from lmi's
+# help message and from the configuration file.
+# Requirements:
+# * lmi meta-command needs to be installed and on PATH.
+
+dest=${1:-lmi.1}
+usage_file=`mktemp`
+options_file=`mktemp`
+configuration_file=`mktemp`
+
+# states:
+# desc - parse description
+# wusg - wait for usage
+# pusg - parse usage
+# wopt - wait for options
+# popt - parse options
+state="desc"
+re_option="^([[:blank:]]+)((-[-[:alpha:]_]+)"
+re_option+="(\ [][:alpha:]<>_()[|-]+)*)(\ \ +(.*))?"
+DESCRIPTION=
+
+if ! which "lmi" >/dev/null 2>&1; then
+ echo "Please install lmi meta-command first!" >&2
+ exit 1
+fi
+
+while IFS= read line; do
+ case "$state" in
+ "desc")
+ if [[ "$line" =~ ^[[:blank:]]*$ ]] && [ -n "$DESCRIPTION" ]; then
+ state="wusg"
+ else
+ [ -n "$DESCRIPTION" ] && DESCRIPTION+=" "
+ DESCRIPTION+="$line"
+ fi
+ ;;
+
+ "wusg")
+ if [[ "$line" =~ ^[Uu]sage: ]]; then
+ state="pusg0"
+ printf ".nf\n" >$usage_file
+ fi
+ ;;
+
+ pusg*)
+ if [[ "$line" =~ ^[[:blank:]]*$ ]]; then
+ state="wopt"
+ printf ".fi\n" >>$usage_file
+ else
+ usg_count=`echo $state | sed 's/^pusg\([[:digit:]]\+\)/\1/'`
+ if [ "$usg_count" = 0 ]; then
+ spaces=`echo "$line" | sed 's/^\(\s\+\).*/\1/' | wc -c`
+ elif [ $spaces -lt `echo "$line" | sed 's/^\(\s\+\).*/\1/' | wc -c` ];
+ then
+ indented=true
+ printf ".RS\n" >>$usage_file
+ elif $indented; then
+ indented=false
+ printf ".RE\n" >>$usage_file
+ fi
+ printf ".B " >>$usage_file
+ echo "$line" >>$usage_file
+ #echo "$line" | sed -e 's/^\s\+//' -e 's/\s\+$//' >>$usage_file
+ state="pusg$((usg_count+1))"
+ fi
+ ;;
+
+ "wopt")
+ if [[ "$line" =~ ^[Oo]ption ]]; then
+ state="popt0"
+ fi
+ ;;
+
+ popt*)
+ if [[ "$line" =~ ^[[:blank:]]*$ ]]; then
+ printf "\n"
+ break
+ elif [[ "$line" =~ $re_option ]]; then
+ opt_count=`echo $state | sed 's/^popt\([[:digit:]]\+\)/\1/'`
+ [ "$opt_count" -gt 0 ] && printf '\n'
+ printf ".TP\n.I ${BASH_REMATCH[2]}\n"
+ printf -- "${BASH_REMATCH[5]}" | sed -e 's/^\s\+//' -e 's/\s\+$//'
+ state="popt$((opt_count+1))"
+ else
+ printf " "
+ printf "$line" | sed -e 's/^\s\+//' -e 's/\s\+$//'
+ fi
+ ;;
+
+ *) break
+ ;;
+
+ esac
+done < <( lmi --help ) >$options_file;
+
+# states:
+# wsct - wait for the first section
+# psct - parsing the section
+# pdsc - parsing description of section
+state="wsct"
+re_sct_start="^\[([[:alpha:]]+)\]"
+re_opt_desc="^#(\s+(.*)|$)"
+re_opt_value="^#?([[:alpha:]]+)\s*=\s*(.*)"
+while IFS= read line; do
+ case $state in
+ "wsct")
+ if [[ "$line" =~ $re_sct_start ]]; then
+ state="psct"
+ printf ".TP\n.B ${BASH_REMATCH[1]} Section\n"
+ fi
+ ;;
+
+ "psct")
+ if [[ "$line" =~ $re_opt_desc ]]; then
+ state="pdsc"
+ DESCRIPTION="${BASH_REMATCH[2]}"
+ elif [[ "$line" =~ $re_sct_start ]]; then
+ printf ".TP\n.B ${BASH_REMATCH[1]} Section\n"
+ fi
+ ;;
+
+ "pdsc")
+ if [[ "$line" =~ $re_opt_value ]]; then
+ state="psct"
+ #DESCRIPTION="${DESCRIPTION} ${BASH_REMATCH[2]}"
+ printf ".RS 4\n.TP 4\n.B ${BASH_REMATCH[1]}\n"
+ if [ -n "${BASH_REMATCH[2]}" ]; then
+ echo "Default:"
+ echo ".B ${BASH_REMATCH[2]}"
+ printf ".IP\n"
+ fi
+ echo "${DESCRIPTION}"
+ printf ".RE\n"
+ elif [[ "$line" =~ $re_opt_desc ]]; then
+ DESCRIPTION="${DESCRIPTION} ${BASH_REMATCH[2]}"
+ elif [[ $line =~ ^$ ]]; then
+ state="psct"
+ fi
+ ;;
+
+ esac
+done < ../config/lmi.conf >$configuration_file
+
+DATE=`LC_ALL="en_US.utf8" date '+%B %Y'`
+VERSION=`lmi --version`
+
+cat >$dest <<EOF
+.TH lmi 1 "${DATE}" "openlmi-scripts ${VERSION}" "User Commands"
+
+.SH NAME
+lmi \- meta-command for managing systems with OpenLMI providers
+.SH SYNOPSIS
+EOF
+
+cat $usage_file >>$dest
+rm $usage_file
+
+cat >>$dest << EOF
+.SH DESCRIPTION
+${DESCRIPTION}
+.SH OPTIONS
+EOF
+
+cat $options_file >>$dest
+rm $options_file
+
+cat >>$dest <<EOF
+.SH CONFIGURATION
+There is a system-wide configuration file located at
+\`/etc/openlmi/lmi.conf\` and user configuration file searched at \`~/.lmirc\`.
+File path of the later can also be specified with
+.B --config-file
+option. Options in user configuration overrides system-wide.
+
+The configuration consists of sections, led by a
+.B [section]
+header and followed by
+.B name: value
+entries. Comments are prefixed with
+.B #
+or
+.B ;
+.PP
+Please refer to
+.B RFC 822
+for more details on this format. Follows a list of possible configuration
+options with leading section names.
+EOF
+
+cat $configuration_file >>$dest
+rm $configuration_file
+
+cat >>$dest <<EOF
+.SH AUTHORS
+.LP
+Michal Minar <miminar(a)redhat.com>
+EOF
diff --git a/cli/man/lmi.1 b/cli/man/lmi.1
new file mode 100644
index 0000000..d402bf5
--- /dev/null
+++ b/cli/man/lmi.1
@@ -0,0 +1,201 @@
+.TH lmi 1 "October 2013" "openlmi-scripts 0.2.2" "User Commands"
+
+.SH NAME
+lmi \- meta-command for managing systems with OpenLMI providers
+.SH SYNOPSIS
+.nf
+.B lmi [options] [(--trace | --notrace)] [-v]... [-h <host>]...
+.RS
+.B <command> [<args> ...]
+.RE
+.B lmi [options] [(--trace | --notrace)] [-v]... [-h <host>]...
+.B lmi (--help | --version)
+.fi
+.SH DESCRIPTION
+Allows to set a path to file, where messages will be logged. No log file is written at default.
+.SH OPTIONS
+.TP
+.I -c --config-file <config>
+Path to a user configuration file. Options specified here override any settings of global configuration file.
+.TP
+.I -h --host <host>
+Hostname of target system.
+.TP
+.I --hosts-file <hosts>
+Path to a file containing target hostnames. Each hostname must be listed on a single line.
+.TP
+.I --user <user>
+Username used in connection to any target host.
+.TP
+.I --same-credentials
+Use the first credentials given for all hosts.
+.TP
+.I -n --noverify
+Do not verify cimom's ssl certificate.
+.TP
+.I -v
+Increase verbosity of output.
+.TP
+.I --trace
+Show tracebacks on errors.
+.TP
+.I --notrace
+Suppress tracebacks for exceptions.
+.TP
+.I -q --quiet
+Supress output except for errors.
+.TP
+.I --log-file <log_file>
+Output file for logging messages.
+.TP
+.I --namespace <namespace>
+Default CIM namespace to use.
+.TP
+.I -N --no-headings
+Don't print table headings.
+.TP
+.I -H --human-friendly
+Print large values in human friendly units (i.e. MB, GB, TB etc.)
+.TP
+.I -L --lister-format (table | csv)
+ Print output of lister commands in CSV or table format. CSV format is more suitable for machine processing. Defaults to table.
+.TP
+.I --help
+Show this text and quit.
+.TP
+.I --version
+Print version of 'lmi' in use and quit.
+.SH CONFIGURATION
+There is a system-wide configuration file located at
+`/etc/openlmi/lmi.conf` and user configuration file searched at `~/.lmirc`.
+File path of the later can also be specified with
+.B --config-file
+option. Options in user configuration overrides system-wide.
+
+The configuration consists of sections, led by a
+.B [section]
+header and followed by
+.B name: value
+entries. Comments are prefixed with
+.B #
+or
+.B ;
+.PP
+Please refer to
+.B RFC 822
+for more details on this format. Follows a list of possible configuration
+options with leading section names.
+.TP
+.B Main Section
+.RS 4
+.TP 4
+.B CommandNamespace
+Default:
+.B lmi.scripts.cmd
+.IP
+Python namespace, where command entry points will be searched for.
+.RE
+.RS 4
+.TP 4
+.B Trace
+Default:
+.B False
+.IP
+Whether the exceptions should be logged with tracebacks.
+.RE
+.RS 4
+.TP 4
+.B Verbosity
+Default:
+.B 0
+.IP
+An integer from -1 to 2 saying, how verbosive the output to console shall be. This differs from [Log] Level, which controls the logging messages being logged to file. If logging to console is enabled it sets the minimum severity level. -1 Supresses all messages except for critical ones. 0 shows warnings, 1 info messages and 2 enables debug messages. This option also affects the verbosity of commands, making them print more information to stdout.
+.RE
+.TP
+.B CIM Section
+.RS 4
+.TP 4
+.B namespace
+Default:
+.B root/cimv2
+.IP
+To override default CIM namespace, uncomment the line below.
+.RE
+.TP
+.B SSL Section
+.RS 4
+.TP 4
+.B VerifyServerCertificate
+Default:
+.B True
+.IP
+Whether to verify server-side certificate, when making secured connection over ssl.
+.RE
+.TP
+.B Format Section
+.RS 4
+.TP 4
+.B HumanFriendly
+Default:
+.B False
+.IP
+Whether to print values in human readable forms (e.g. with units).
+.RE
+.RS 4
+.TP 4
+.B ListerFormat
+Default:
+.B table
+.IP
+What format to use, when listing tabular data. Possible values are: {csv, table}. The former allows for easy machine parsing, the latter is more human friendly.
+.RE
+.RS 4
+.TP 4
+.B NoHeadings
+Default:
+.B False
+.IP
+Whether to suppress headings (column names) when printing tables.
+.RE
+.TP
+.B Log Section
+.RS 4
+.TP 4
+.B Level
+Default:
+.B ERROR
+.IP
+Level can be set to following values: DEBUG, INFO, WARNING, ERROR, CRITICAL Affects only logging to a file.
+.RE
+.RS 4
+.TP 4
+.B ConsoleFormat
+Default:
+.B %(levelname)s: %(message)s
+.IP
+Format string used, when logging to a console. For details visit: http://docs.python.org/2/library/logging.html#logrecord-attributes
+.RE
+.RS 4
+.TP 4
+.B LogToConsole
+Default:
+.B True
+.IP
+Whether the logging to console is enabled.
+.RE
+.RS 4
+.TP 4
+.B FileFormat
+Default:
+.B %(asctime)s:%(levelname)-8s:%(name)s:%(lineno)d - %(message)s
+.IP
+Format string used, when logging to a file.
+.RE
+.RS 4
+.TP 4
+.B OutputFile
+Allows to set a path to file, where messages will be logged. No log file is written at default.
+.RE
+.SH AUTHORS
+.LP
+Michal Minar <miminar(a)redhat.com>