-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from TheoChem-VU/177-add-cli-command-to-read-…
…a-calculation 177 add cli command to read a calculation
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" Module containing functions for reading and printing calculation results to the CL """ | ||
import argparse | ||
from tcutility import results | ||
from pprint import pprint | ||
|
||
|
||
def create_subparser(parent_parser: argparse.ArgumentParser): | ||
desc = "Read results from a calculation." | ||
subparser = parent_parser.add_parser('read', help=desc, description=desc) | ||
subparser.add_argument("-s", "--status", | ||
help="Shortcut to only print the status of the calculation.", | ||
default=False, | ||
action="store_true") | ||
subparser.add_argument("-p", "--properties", | ||
help="Shortcut to only print calculated properties for the calculation.", | ||
default=False, | ||
action="store_true") | ||
subparser.add_argument("workdir", | ||
type=str, | ||
help="The calculation directory to read the results from.") | ||
subparser.add_argument("keys", | ||
type=str, | ||
nargs='*', | ||
help="The keys to read from the results.") | ||
|
||
|
||
def main(args: argparse.Namespace): | ||
res = results.read(args.workdir) | ||
|
||
# if status flag was set we print the status name | ||
if args.status: | ||
print(res.status.name) | ||
return | ||
|
||
# if properties flag was set we print all properties | ||
if args.properties: | ||
pprint(res.properties) | ||
return | ||
|
||
# print specific keys | ||
if len(args.keys) > 0: | ||
ret = {k: res.get_multi_key(k) for k in args.keys} | ||
# if only one key was given we just print the value | ||
if len(ret) == 1: | ||
print(list(ret.values())[0]) | ||
return | ||
pprint(ret) | ||
return | ||
|
||
# if we did not give keys or set flags we just print everything | ||
pprint(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters