forked from gramineproject/gramine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgramine-manifest
executable file
·33 lines (28 loc) · 1.05 KB
/
gramine-manifest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (c) 2021 Intel Corporation
# Borys Popławski <[email protected]>
import click
from graminelibos import Manifest
def validate_define(_ctx, _param, values):
ret = {}
for value in values:
try:
k, v = value.split('=', 1)
except ValueError:
k, v = value, True
ret[k] = v
return ret
@click.command()
@click.option('--string', '-c')
@click.option('--define', '-D', multiple=True, callback=validate_define)
@click.argument('infile', type=click.File('r'), required=False)
@click.argument('outfile', type=click.File('w'), default='-')
def main(string, define, infile, outfile):
if not bool(string) ^ bool(infile):
click.get_current_context().fail('specify exactly one of (infile, -c)')
template = infile.read() if infile else string
manifest = Manifest.from_template(template, define)
manifest.dump(outfile)
if __name__ == '__main__':
main() # pylint: disable=no-value-for-parameter