Rename want_vm_* in vmname_nargs

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-05-18 17:05:25 +02:00
parent d4c74d210f
commit 910276e898
No known key found for this signature in database
GPG Key ID: 96ED3C3BA19C3DEE
8 changed files with 41 additions and 43 deletions

View File

@ -35,9 +35,7 @@ import qubes.tools
parser = qubes.tools.QubesArgumentParser(
description='Send monitor layout to one qube or to all of them',
want_app=True,
want_vm=True,
want_vm_optional=True)
want_app=True, vmname_nargs='?')
def main(args=None):

View File

@ -30,8 +30,7 @@ import qubes.exc
import qubes.tools
parser = qubes.tools.QubesArgumentParser(
description='forceful shutdown of a domain',
want_vm=True)
description='forceful shutdown of a domain', vmname_nargs='+')
def main(args=None):
@ -43,12 +42,15 @@ def main(args=None):
args = parser.parse_args(args)
try:
args.vm.force_shutdown()
except (IOError, OSError, qubes.exc.QubesException) as e:
parser.error_runtime(str(e))
exit_code = 0
for domain in args.domains:
try:
domain.force_shutdown()
except (IOError, OSError, qubes.exc.QubesException) as e:
exit_code = 1
parser.print_error(str(e))
return 0
return exit_code
if __name__ == '__main__':

View File

@ -28,9 +28,8 @@ import sys
import qubes
parser = qubes.tools.QubesArgumentParser(
want_vm=True,
description='pause a domain')
parser = qubes.tools.QubesArgumentParser(vmname_nargs='+',
description='pause a domain')
def main(args=None):
@ -41,7 +40,8 @@ def main(args=None):
'''
args = parser.parse_args(args)
args.vm.pause()
for domain in args.domains:
domain.pause()
return 0

View File

@ -36,7 +36,7 @@ import qubes.vm
parser = qubes.tools.QubesArgumentParser(
want_force_root=True,
want_vm=True)
vmname_nargs=1)
parser.add_argument('--help-properties',
action=qubes.tools.HelpPropertiesAction,
@ -63,18 +63,18 @@ def main(args=None):
args = parser.parse_args(args)
if args.property is None:
properties = args.vm.property_list()
properties = args.domain.property_list()
width = max(len(prop.__name__) for prop in properties)
for prop in sorted(properties):
try:
value = getattr(args.vm, prop.__name__)
value = getattr(args.domain, prop.__name__)
except AttributeError:
print('{name:{width}s} U'.format(
name=prop.__name__, width=width))
continue
if args.vm.property_is_default(prop):
if args.domain.property_is_default(prop):
print('{name:{width}s} D {value!s}'.format(
name=prop.__name__, width=width, value=value))
else:
@ -83,21 +83,22 @@ def main(args=None):
return 0
if args.property not in [prop.__name__ for prop in args.vm.property_list()]:
if args.property not in [prop.__name__
for prop in args.domain.property_list()]:
parser.error('no such property: {!r}'.format(args.property))
if args.value is not None:
setattr(args.vm, args.property, args.value)
setattr(args.domain, args.property, args.value)
args.app.save()
return 0
if args.delete:
delattr(args.vm, args.property)
delattr(args.domain, args.property)
args.app.save()
return 0
print(str(getattr(args.vm, args.property)))
print(str(getattr(args.domain, args.property)))
return 0

View File

@ -31,9 +31,7 @@ import qubes.exc
import qubes.tools
parser = qubes.tools.QubesArgumentParser(
want_vm=True,
want_vm_all=True)
parser = qubes.tools.QubesArgumentParser(vmname_nargs='+')
parser.add_argument('--user', '-u', metavar='USER',
help='run command in a qube as USER')
@ -84,7 +82,7 @@ def main(args=None):
if args.color_output is None and args.filter_esc:
args.color_output = '31'
if len(args.vm) > 1 and args.passio:
if len(args.domains) > 1 and args.passio:
parser.error('--passio cannot be used when more than 1 qube is chosen')
if args.localcmd and not args.passio:
parser.error('--localcmd have no effect without --pass-io')
@ -92,7 +90,7 @@ def main(args=None):
parser.error('--color-output must be used with --filter-escape-chars')
retcode = 0
for vm in args.vm:
for vm in args.domains:
if args.autostart and not vm.is_running():
vm.start()

View File

@ -25,17 +25,14 @@
from __future__ import print_function
import qubes.config
import qubes.tools
import sys
import time
import qubes.config
import qubes.tools
parser = qubes.tools.QubesArgumentParser(
description='gracefully shut down a qube',
want_vm=True,
want_vm_all=True)
description='gracefully shut down a qube', vmname_nargs='+')
parser.add_argument('--force',
action='store_true', default=False,
@ -56,14 +53,14 @@ parser.add_argument('--timeout',
def main(args=None):
args = parser.parse_args(args)
for vm in args.vm:
for vm in args.domains:
vm.shutdown(force=args.force)
if not args.wait:
return
timeout = args.timeout
current_vms = list(sorted(args.vm))
current_vms = list(sorted(args.domains))
while timeout >= 0:
current_vms = [vm for vm in current_vms
if vm.get_power_state() != 'Halted']

View File

@ -21,17 +21,19 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
'''qvm-start - Start a domain'''
# TODO notification in tray
import argparse
import sys
import qubes
class DriveAction(argparse.Action):
'''Action for argument parser that stores drive image path.'''
# pylint: disable=redefined-builtin,too-few-public-methods
def __init__(self,
option_strings,
@ -49,10 +51,8 @@ class DriveAction(argparse.Action):
setattr(namespace, self.dest, self.prefix + values)
parser = qubes.tools.QubesArgumentParser(
want_vm=True,
description='start a domain')
parser = qubes.tools.QubesArgumentParser(vmname_nargs=1,
description='start a domain')
parser_drive = parser.add_mutually_exclusive_group()
@ -98,6 +98,7 @@ parser.add_argument('--skip-if-running',
parser.set_defaults(drive=None)
def main(args=None):
'''Main routine of :program:`qvm-start`.
@ -110,7 +111,7 @@ def main(args=None):
# if options.tray:
# tray_notify_init()
vm = args.vm
vm = args.domains[0]
if args.skip_if_running and vm.is_running():
return

View File

@ -29,9 +29,10 @@ import qubes
parser = qubes.tools.QubesArgumentParser(
want_vm=True,
vmname_nargs=1,
description='unpause a domain')
def main(args=None):
'''Main routine of :program:`qvm-unpause`.
@ -40,7 +41,7 @@ def main(args=None):
'''
args = parser.parse_args(args)
args.vm.unpause()
args.domains[0].unpause()
return 0