Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Configure Implementation #24

Merged
merged 9 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions fre/fre.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def function(context, uppercase):
@click.pass_context
def configure(context, y):
""" - Execute fre pp configure """
context.forward(pp.frepp.configure)
context.forward(pp.frepp.configureYAML)

@frePP.command()
@click.option("-e",
Expand All @@ -230,6 +230,70 @@ def checkout(context, experiment, platform, target):
""" - Execute fre pp checkout """
context.forward(pp.frepp.checkout)

@frePP.command()
@click.option('-x',
'--xml',
required=True,
help="Required. The Bronx XML")
@click.option('-p',
'--platform',
required=True,
help="Required. The Bronx XML Platform")
@click.option('-t',
'--target',
required=True,
help="Required. The Bronx XML Target")
@click.option('-e',
'--experiment',
required=True,
help="Required. The Bronx XML Experiment")
@click.option('--do_analysis',
is_flag=True,
default=False,
help="Optional. Runs the analysis scripts.")
@click.option('--historydir',
help="Optional. History directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--refinedir',
help="Optional. History refineDiag directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--ppdir',
help="Optional. Postprocessing directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--do_refinediag',
is_flag=True,
default=False,
help="Optional. Process refineDiag scripts")
@click.option('--pp_start',
help="Optional. Starting year of postprocessing. " \
"If not specified, a default value of '0000' " \
"will be set and must be changed in rose-suite.conf")
@click.option('--pp_stop',
help="Optional. Ending year of postprocessing. " \
"If not specified, a default value of '0000' " \
"will be set and must be changed in rose-suite.conf")
@click.option('--validate',
is_flag=True,
help="Optional. Run the Cylc validator " \
"immediately after conversion")
@click.option('-v',
'--verbose',
is_flag=True,
help="Optional. Display detailed output")
@click.option('-q',
'--quiet',
is_flag=True,
help="Optional. Display only serious messages and/or errors")
@click.option('--dual',
is_flag=True,
help="Optional. Append '_canopy' to pp, analysis, and refinediag dirs")
@click.pass_context
def convert(context, xml, platform, target, experiment, do_analysis, historydir, refinedir, ppdir, do_refinediag, pp_start, pp_stop, validate, verbose, quiet, dual):
"""
Converts a Bronx XML to a Canopy rose-suite.conf
"""
context.forward(pp.frepp.configureXML)

#############################################

"""
Expand Down Expand Up @@ -288,4 +352,4 @@ def testfunction(context, uppercase):
#############################################

if __name__ == '__main__':
fre()
fre()
4 changes: 2 additions & 2 deletions fre/pp/checkoutScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
required=True)
def checkoutTemplate(experiment, platform, target):
"""
# Checkout the template file
Checkout the template file
"""
# Create the directory if it doesn't exist
directory = os.path.expanduser("~/cylc-src")
os.makedirs(directory, exist_ok=False)
os.makedirs(directory, exist_ok=True)

# Change the current working directory
os.chdir(directory)
Expand Down
14 changes: 14 additions & 0 deletions fre/pp/configureScriptXML2.py → fre/pp/configureScriptXML.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,22 @@ def convert(xml, platform, target, experiment, do_analysis, historydir, refinedi
Converts a Bronx XML to a Canopy rose-suite.conf
"""

# Set the name of the directory
name = f"{experiment}__{platform}__{target}"

# Create the directory if it doesn't exist
cylcDir = os.path.expanduser("~/cylc-src")
newDir = os.path.join(cylcDir, name)
os.makedirs(newDir, exist_ok=True)

# Change the current working directory
os.chdir(newDir)

cylc_loaded = False

##########################################################################


##########################################################################
# Check the OS environment. Exit if FRE has not been loaded or Cylc has
# not been loaded (if using the --validate option).
Expand Down
File renamed without changes.
71 changes: 69 additions & 2 deletions fre/pp/frepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import click

from fre.pp.configureScript import *
from fre.pp.configureScriptYAML import *
from fre.pp.checkoutScript import *
from fre.pp.configureScriptXML import *

#############################################

Expand All @@ -22,7 +23,7 @@ def pp():
help="YAML file to be used for parsing",
required=True)
@click.pass_context
def configure(context, y):
def configureYAML(context, y):
"""
Takes a YAML file, parses it, and creates an output
"""
Expand Down Expand Up @@ -55,5 +56,71 @@ def checkout(context, experiment, platform, target):

#############################################

@pp.command()
@click.option('-x',
'--xml',
required=True,
help="Required. The Bronx XML")
@click.option('-p',
'--platform',
required=True,
help="Required. The Bronx XML Platform")
@click.option('-t',
'--target',
required=True,
help="Required. The Bronx XML Target")
@click.option('-e',
'--experiment',
required=True,
help="Required. The Bronx XML Experiment")
@click.option('--do_analysis',
is_flag=True,
default=False,
help="Optional. Runs the analysis scripts.")
@click.option('--historydir',
help="Optional. History directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--refinedir',
help="Optional. History refineDiag directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--ppdir',
help="Optional. Postprocessing directory to reference. " \
"If not specified, the XML's default will be used.")
@click.option('--do_refinediag',
is_flag=True,
default=False,
help="Optional. Process refineDiag scripts")
@click.option('--pp_start',
help="Optional. Starting year of postprocessing. " \
"If not specified, a default value of '0000' " \
"will be set and must be changed in rose-suite.conf")
@click.option('--pp_stop',
help="Optional. Ending year of postprocessing. " \
"If not specified, a default value of '0000' " \
"will be set and must be changed in rose-suite.conf")
@click.option('--validate',
is_flag=True,
help="Optional. Run the Cylc validator " \
"immediately after conversion")
@click.option('-v',
'--verbose',
is_flag=True,
help="Optional. Display detailed output")
@click.option('-q',
'--quiet',
is_flag=True,
help="Optional. Display only serious messages and/or errors")
@click.option('--dual',
is_flag=True,
help="Optional. Append '_canopy' to pp, analysis, and refinediag dirs")
@click.pass_context
def configureXML(context, xml, platform, target, experiment, do_analysis, historydir, refinedir, ppdir, do_refinediag, pp_start, pp_stop, validate, verbose, quiet, dual):
"""
Converts a Bronx XML to a Canopy rose-suite.conf
"""
context.forward(convert)

#############################################=

if __name__ == "__main__":
pp()
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
include_package_data=True,
install_requires=[
'Click',
'pyyaml',
'jsonschema',
],
entry_points={
'console_scripts': [
Expand Down
Loading