Add qubes.tools.PoolsAction

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-05-21 01:34:01 +02:00
parent 0319df25e5
commit 357e8125eb
No known key found for this signature in database
GPG Key ID: 96ED3C3BA19C3DEE

View File

@ -199,6 +199,27 @@ class VmNameAction(QubesAction):
parser.error('no such domain: {!r}'.format(vm_name))
class PoolsAction(QubesAction):
''' Action for argument parser to gather multiple pools '''
# pylint: disable=too-few-public-methods
def __call__(self, parser, namespace, values, option_string=None):
''' Set ``namespace.vmname`` to ``values`` '''
setattr(namespace, self.dest, values)
def parse_qubes_app(self, parser, namespace):
app = namespace.app
name = getattr(namespace, self.dest)
if not name:
return
try:
setattr(namespace, self.dest, app.get_pool(name))
except qubes.exc.QubesException as e:
parser.error(e.message)
sys.exit(2)
class QubesArgumentParser(argparse.ArgumentParser):
'''Parser preconfigured for use in most of the Qubes command-line tools.