Skip to content

Commit

Permalink
tools/qvm-prefs: re-add --help-properties action
Browse files Browse the repository at this point in the history
Specific VM object is required to get list of properties and help on
them, so convert HelpPropertiesAction into normal action (like --get or
--set).
  • Loading branch information
marmarek committed Mar 13, 2017
1 parent 2472be9 commit 795909b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
42 changes: 0 additions & 42 deletions qubesmgmt/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,48 +105,6 @@ def __call__(self, parser, namespace, values, option_string=None):
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 '''

Expand Down
3 changes: 3 additions & 0 deletions qubesmgmt/tools/qvm_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,11 @@ def __call__(self, parser, namespace, values, option_string=None):
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
Expand Down
22 changes: 18 additions & 4 deletions qubesmgmt/tools/qvm_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 795909b

Please sign in to comment.