tools/qvm-prefs: re-add --help-properties action

Specific VM object is required to get list of properties and help on
them, so convert HelpPropertiesAction into normal action (like --get or
--set).
This commit is contained in:
Marek Marczykowski-Górecki 2017-03-11 01:49:04 +01:00
parent 2472be9d61
commit 795909bc05
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 21 additions and 46 deletions

View File

@ -105,48 +105,6 @@ class SinglePropertyAction(argparse.Action):
if self.const is None else self.const
# class HelpPropertiesAction(argparse.Action):
# '''Action for argument parser that displays all properties and exits.'''
# # pylint: disable=redefined-builtin,too-few-public-methods
# def __init__(self,
# option_strings,
# klass=None,
# dest=argparse.SUPPRESS,
# default=argparse.SUPPRESS,
# help='list all available properties with short descriptions'
# ' and exit'):
# super(HelpPropertiesAction, self).__init__(
# option_strings=option_strings,
# dest=dest,
# default=default,
# nargs=0,
# help=help)
#
# # late import because of circular dependency
# import qubes # pylint: disable=redefined-outer-name
# self._klass = klass if klass is not None else qubes.Qubes
#
#
# def __call__(self, parser, namespace, values, option_string=None):
# # pylint: disable=redefined-outer-name
# properties = self._klass.property_list()
# width = max(len(prop.__name__) for prop in properties)
# wrapper = textwrap.TextWrapper(width=80,
# initial_indent=' ', subsequent_indent=' ' * (width + 6))
#
# text = 'Common properties:\n' + '\n'.join(
# wrapper.fill('{name:{width}s} {doc}'.format(
# name=prop.__name__,
# doc=qubesmgmt.utils.format_doc(prop.__doc__) if prop.__doc__
# else'',
# width=width))
# for prop in sorted(properties))
# if self._klass is not qubes.Qubes:
# text += '\n\n' \
# 'There may be more properties in specific domain classes.\n'
# parser.exit(message=text)
#
class VmNameAction(QubesAction):
''' Action for parsing one ore multiple domains from provided VMNAMEs '''

View File

@ -451,8 +451,11 @@ class _HelpColumnsAction(argparse.Action):
doc=column.__doc__ or '',
width=width))
for column in sorted(Column.columns.values()))
text += '\n\nAdditionally any VM property may be used as a column, ' \
'see qvm-prefs --help-properties for available values'
parser.exit(message=text + '\n')
class _HelpFormatsAction(argparse.Action):
'''Action for argument parser that displays all formats and exits.'''
# pylint: disable=redefined-builtin

View File

@ -19,12 +19,12 @@
# with this program; if not, see <http://www.gnu.org/licenses/>.
''' Manipulate VM properties.'''
# TODO list properties for all classes
# TODO list only non-default properties
from __future__ import print_function
import sys
import textwrap
import qubesmgmt
import qubesmgmt.tools
@ -37,9 +37,9 @@ def get_parser(vmname_nargs=1):
parser = qubesmgmt.tools.QubesArgumentParser(
vmname_nargs=vmname_nargs)
# parser.add_argument('--help-properties',
# action=qubesmgmt.tools.HelpPropertiesAction,
# klass=qubesmgmt.vm.QubesVM)
parser.add_argument('--help-properties',
action='store_true',
help='list all available properties with short descriptions and exit')
parser.add_argument('--get', '-g',
action='store_true',
@ -75,6 +75,20 @@ def process_actions(parser, args, target):
:param args: arguments to handle
:param target: object on which actions should be performed
'''
if args.help_properties:
properties = target.property_list()
width = max(len(prop) for prop in properties)
wrapper = textwrap.TextWrapper(width=80,
initial_indent=' ', subsequent_indent=' ' * (width + 6))
for prop in sorted(properties):
help_text = target.property_help(prop)
print(wrapper.fill('{name:{width}s} {help_text!s}'.format(
name=prop, width=width, help_text=help_text)))
return 0
if args.property is None:
properties = target.property_list()
width = max(len(prop) for prop in properties)