forked from NOAA-EMC/global-workflow
-
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.
Moving logic for skipping hosts in pr cases (NOAA-EMC#2573)
This PR removes the logic of skipping hosts for pr cases from `create_experiment.py` and moves it to a test in the cron bash driver using a `parse_yaml.py` python tool. The Jenkins pipeline was not effected as it uses the `get_host_case_list.py` utility to form the cases on a per host bases. Co-authored-by: Rahul Mahajan <[email protected]>
- Loading branch information
1 parent
3cd0c68
commit b5d113e
Showing
3 changed files
with
79 additions
and
15 deletions.
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
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,70 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script parses a yaml file and returns the value of a specified key. | ||
""" | ||
|
||
import os | ||
import sys | ||
from wxflow import AttrDict, parse_j2yaml | ||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
|
||
_here = os.path.dirname(__file__) | ||
_top = os.path.abspath(os.path.join(os.path.abspath(_here), '../../..')) | ||
|
||
description = """parse yaml file and return value of key""" | ||
|
||
|
||
def parse_args(): | ||
""" | ||
Parse command-line arguments. | ||
Returns: | ||
argparse.Namespace: The parsed command-line arguments. | ||
""" | ||
|
||
parser = ArgumentParser(description=description) | ||
parser.add_argument('-y', '--yaml', help='full path to yaml file to parse', type=Path, required=True) | ||
parser.add_argument('-k', '--key', help='key to return value of', type=str, required=True) | ||
parser.add_argument('-s', '--string', help='output results as strings', action="store_true", required=False) | ||
return parser.parse_args() | ||
|
||
|
||
def yq(yamlfile, key): | ||
""" | ||
Parse a yaml file and return the value of a specified key. | ||
Args: | ||
yamlfile (Path): The path to the yaml file. | ||
key (str): The key to return the value of. | ||
Returns: | ||
The value of the specified key in the yaml file. | ||
""" | ||
|
||
data = AttrDict(HOMEgfs=_top) | ||
data.update({'HOMEgfs': _top}) | ||
ydict = parse_j2yaml(path=yamlfile, data=data) | ||
if key == 'all': | ||
return ydict | ||
list_keys = key.split('.') | ||
for k in list_keys: | ||
ydict = ydict.get(k, None) | ||
if ydict is None: | ||
break | ||
return ydict | ||
|
||
|
||
if __name__ == '__main__': | ||
""" | ||
Main function. Parses command-line arguments and prints the value of the specified key in the specified yaml file. | ||
""" | ||
|
||
args = parse_args() | ||
values = yq(args.yaml, args.key) | ||
if args.string and isinstance(values, list): | ||
for value in values: | ||
print(value) | ||
else: | ||
print(values) |
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