-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added collection list extraction to juputer_test WF * fixed spacing * added type to WF input * removed token input * expanded environment naming tolerance * renamed collections to cumulus_api to avoid wrong imports * updated name * moved files to better positions * adderd tokenfile location to workflow input * some lint fix * init lint disable * lint fix * lint... * more lint * updated F401 to F0401 * updated flake8 to ignore init.py * updated workflow with new locations * - Added cmr-association-diff import and usage - Added secret usage to workflow - Added FileHandler class * removed \ * removed ./ from paths * changed test execution only if input file exists Co-authored-by: Zoltan Miskolci <zoltan.miskolci@jpl.nasa.gov>
- Loading branch information
Showing
11 changed files
with
211 additions
and
127 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[flake8] | ||
#ignore = ... | ||
max-line-length=180 | ||
per-file-ignores = __init__.py:F401 |
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
Empty file.
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,98 @@ | ||
import papermill as pm | ||
import argparse | ||
|
||
from os import path | ||
|
||
from utils import FileHandler | ||
from utils.enums import Venue | ||
|
||
|
||
def parse_args(): | ||
""" | ||
Parses the program arguments | ||
Returns | ||
------- | ||
args | ||
""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Update CMR with latest profile', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
|
||
parser.add_argument('-e', '--env', | ||
help='CMR environment used to pull results from.', | ||
required=True, | ||
choices=["uat", "ops", "ngap_uat", "ngap_ops"], | ||
metavar='uat or ops') | ||
|
||
parser.add_argument('-n', '--notebook', | ||
help='Notebook to run', | ||
required=True, | ||
metavar='') | ||
|
||
parser.add_argument('-i', '--input_file', | ||
help='File of json collections', | ||
required=True, | ||
metavar='') | ||
|
||
parser.add_argument('-o', '--output_path', | ||
help='output path for success and fails', | ||
required=False, | ||
metavar='') | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
def run(): | ||
""" | ||
Run from command line. | ||
Returns | ||
------- | ||
""" | ||
|
||
_args = parse_args() | ||
environment = _args.env | ||
notebook = _args.notebook | ||
inputFile = _args.input_file | ||
output_location = _args.output_path if _args.output_path else '.' | ||
|
||
notebook_path = path.realpath(path.dirname(notebook)) | ||
notebook_name = path.basename(notebook) | ||
|
||
success = [] | ||
fails = [] | ||
|
||
if path.exists(inputFile): | ||
venue = Venue.from_str(environment) | ||
collections = FileHandler.get_file_content_list_per_line(inputFile) | ||
for collection in collections: | ||
|
||
try: | ||
print(collection) | ||
pm.execute_notebook( | ||
notebook, | ||
f"{notebook_path}/output/{collection}_{environment}_output_{notebook_name}", | ||
parameters=dict(collection=collection, venue=venue.name) | ||
) | ||
success.append(collection) | ||
except Exception as ex: | ||
print(ex) | ||
fails.append(collection) | ||
|
||
# Create output files | ||
if output_location: | ||
success_outfile = path.realpath(f'{output_location}/{_args.env}_success.txt') | ||
fail_outfile = path.realpath(f'{output_location}/{_args.env}_fail.txt') | ||
|
||
if success: | ||
with open(success_outfile, 'w') as the_file: | ||
the_file.writelines(x + '\n' for x in success) | ||
|
||
if fails: | ||
with open(fail_outfile, 'w') as the_file: | ||
the_file.writelines(x + '\n' for x in fails) | ||
|
||
if __name__ == '__main__': | ||
run() |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
# pylint: disable=C0114 | ||
|
||
from utils.filehandler import FileHandler |
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,3 @@ | ||
# pylint: disable=C0114 | ||
|
||
from utils.enums.venue import Venue |
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,27 @@ | ||
"""A Venue or Environment enum""" | ||
|
||
from enum import Enum | ||
|
||
|
||
class Venue(Enum): | ||
""" | ||
Venue or Environment enum | ||
""" | ||
|
||
UAT = 1 | ||
OPS = 2 | ||
SIT = 3 | ||
|
||
@staticmethod | ||
def from_str(label): | ||
""" | ||
Function to convert a string to Venue enum | ||
""" | ||
|
||
if label.lower() in ["uat", "ngap_uat"]: | ||
return Venue.UAT | ||
if label.lower() in ["ops", "ngap_ops", "prod"]: | ||
return Venue.OPS | ||
if label.lower() in ["sit", "ngap_sit"]: | ||
return Venue.SIT | ||
raise NotImplementedError(f'No matching set up for env value "{label}"!') |
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,44 @@ | ||
"""Module for file handling calls""" | ||
|
||
import json | ||
|
||
from os import path | ||
|
||
|
||
class FileHandler(): | ||
""" | ||
Class for file handling calls | ||
""" | ||
|
||
def get_file_content(filename: str) -> str: | ||
""" | ||
Function to get the content of a file | ||
""" | ||
|
||
filepath = path.realpath(filename) | ||
if path.exists(filepath): | ||
result = open(filepath).read() | ||
return result | ||
else: | ||
raise FileExistsError(f"{filepath} does not exists!") | ||
|
||
def get_file_content_list_per_line(filename: str) -> list: | ||
""" | ||
Function to get the content of a file, turned into a list. | ||
Each line is a list element | ||
""" | ||
|
||
filepath = path.realpath(filename) | ||
if path.exists(filepath): | ||
with open(filepath) as fileContent: | ||
try: | ||
result = json.load(fileContent) | ||
except ValueError: | ||
result = [] | ||
fileContent.seek(0) | ||
lines = fileContent.readlines() | ||
for line in lines: | ||
result.append(line.strip()) | ||
return result | ||
else: | ||
raise FileExistsError(f"{filepath} does not exists!") |