-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.py
62 lines (49 loc) · 1.55 KB
/
cli.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Command line interface (cli) for aiida_aurora.
Register new commands either via the "console_scripts" entry point or plug them
directly into the 'verdi' command by using AiiDA-specific entry points like
"aiida.cmdline.data" (both in the setup.json file).
"""
import sys
import click
from aiida.cmdline.commands.cmd_data import verdi_data
from aiida.cmdline.params.types import DataParamType
from aiida.cmdline.utils import decorators
from aiida.orm import QueryBuilder
from aiida.plugins import DataFactory
# See aiida.cmdline.data entry point in setup.json
@verdi_data.group("aurora")
def data_cli():
"""Command line interface for aiida-aurora"""
@data_cli.command("list")
@decorators.with_dbenv()
def list_(): # pylint: disable=redefined-builtin
"""
Display all DiffParameters nodes
"""
DiffParameters = DataFactory("aurora")
qb = QueryBuilder()
qb.append(DiffParameters)
results = qb.all()
s = ""
for result in results:
obj = result[0]
s += f"{str(obj)}, pk: {obj.pk}\n"
sys.stdout.write(s)
@data_cli.command("export")
@click.argument("node", metavar="IDENTIFIER", type=DataParamType())
@click.option(
"--outfile",
"-o",
type=click.Path(dir_okay=False),
help="Write output to file (default: print to stdout).",
)
@decorators.with_dbenv()
def export(node, outfile):
"""Export a DiffParameters node (identified by PK, UUID or label) to plain text."""
string = str(node)
if outfile:
with open(outfile, "w") as f:
f.write(string)
else:
click.echo(string)