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:
parent
2472be9d61
commit
795909bc05
@ -105,48 +105,6 @@ class SinglePropertyAction(argparse.Action):
|
|||||||
if self.const is None else self.const
|
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):
|
class VmNameAction(QubesAction):
|
||||||
''' Action for parsing one ore multiple domains from provided VMNAMEs '''
|
''' Action for parsing one ore multiple domains from provided VMNAMEs '''
|
||||||
|
|
||||||
|
@ -451,8 +451,11 @@ class _HelpColumnsAction(argparse.Action):
|
|||||||
doc=column.__doc__ or '',
|
doc=column.__doc__ or '',
|
||||||
width=width))
|
width=width))
|
||||||
for column in sorted(Column.columns.values()))
|
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')
|
parser.exit(message=text + '\n')
|
||||||
|
|
||||||
|
|
||||||
class _HelpFormatsAction(argparse.Action):
|
class _HelpFormatsAction(argparse.Action):
|
||||||
'''Action for argument parser that displays all formats and exits.'''
|
'''Action for argument parser that displays all formats and exits.'''
|
||||||
# pylint: disable=redefined-builtin
|
# pylint: disable=redefined-builtin
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
''' Manipulate VM properties.'''
|
''' Manipulate VM properties.'''
|
||||||
# TODO list properties for all classes
|
|
||||||
# TODO list only non-default properties
|
# TODO list only non-default properties
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import textwrap
|
||||||
|
|
||||||
import qubesmgmt
|
import qubesmgmt
|
||||||
import qubesmgmt.tools
|
import qubesmgmt.tools
|
||||||
@ -37,9 +37,9 @@ def get_parser(vmname_nargs=1):
|
|||||||
parser = qubesmgmt.tools.QubesArgumentParser(
|
parser = qubesmgmt.tools.QubesArgumentParser(
|
||||||
vmname_nargs=vmname_nargs)
|
vmname_nargs=vmname_nargs)
|
||||||
|
|
||||||
# parser.add_argument('--help-properties',
|
parser.add_argument('--help-properties',
|
||||||
# action=qubesmgmt.tools.HelpPropertiesAction,
|
action='store_true',
|
||||||
# klass=qubesmgmt.vm.QubesVM)
|
help='list all available properties with short descriptions and exit')
|
||||||
|
|
||||||
parser.add_argument('--get', '-g',
|
parser.add_argument('--get', '-g',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -75,6 +75,20 @@ def process_actions(parser, args, target):
|
|||||||
:param args: arguments to handle
|
:param args: arguments to handle
|
||||||
:param target: object on which actions should be performed
|
: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:
|
if args.property is None:
|
||||||
properties = target.property_list()
|
properties = target.property_list()
|
||||||
width = max(len(prop) for prop in properties)
|
width = max(len(prop) for prop in properties)
|
||||||
|
Loading…
Reference in New Issue
Block a user