-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathfre.py
More file actions
82 lines (69 loc) · 3.47 KB
/
fre.py
File metadata and controls
82 lines (69 loc) · 3.47 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
authored by Bennett.Chang@noaa.gov | bcc2761
principal click group for main/fre allows for subgroup functions to be called via this
script, with 'fre' as the entry point
"""
import logging
import click
from . import version, FORMAT
from .lazy_group import LazyGroup
fre_logger = logging.getLogger(__name__)
@click.version_option(
package_name = "fre-cli",
version = version
)
# click and lazy group loading
@click.group(
cls = LazyGroup,
lazy_subcommands = {"workflow": ".workflow.freworkflow.workflow_cli",
"pp": ".pp.frepp.pp_cli",
"catalog": ".catalog.frecatalog.catalog_cli",
"list": ".list_.frelist.list_cli",
"check": ".check.frecheck.check_cli",
"run": ".run.frerun.run_cli",
"yamltools": ".yamltools.freyamltools.yamltools_cli",
"make": ".make.fremake.make_cli",
"app": ".app.freapp.app_cli",
"cmor": ".cmor.frecmor.cmor_cli",
"analysis": ".analysis.freanalysis.analysis_cli"},
help = click.style(
"'fre' is the main CLI click group. It houses the other tool groups as lazy subcommands.",
fg = 'cyan')
)
@click.option( '-v', '--verbose', default = 0, required = False, count = True, type = int,
help = "Increment logging verbosity from default (logging.WARNING) to logging.INFO. " + \
"use -vv for logging.DEBUG. will be overridden by -q/--quiet" )
@click.option( '-q', '--quiet', default = False, required = False, is_flag = True, type = bool,
help = "Set logging verbosity from default (logging.WARNING) to logging.ERROR, printing " + \
"less output to screen. overrides -v[v]/--verbose" )
@click.option( '-l', '--log_file', default = None, required = False, type = str,
help = 'Path to log file for all fre calls, the output to screen will still print with the ' + \
'path specified. If the log file already exists, it is appended to.' )
def fre(verbose = 0, quiet = False, log_file = None):
'''
entry point function to subgroup functions, setting global verbosity/logging formats that all
other routines will utilize
'''
log_level = logging.WARNING # default
if verbose == 1:
log_level = logging.INFO # -v, more verbose than default
elif verbose == 2:
log_level = logging.DEBUG # -vv most verbose
if quiet:
log_level = logging.ERROR # least verbose
base_fre_logger=fre_logger.parent
base_fre_logger.setLevel(level = log_level)
fre_logger.debug('root fre_logger level set')
# check if log_file arg was used
if log_file is not None:
fre_logger.debug('creating fre_file_handler for fre_logger')
fre_file_handler=logging.FileHandler(log_file,
mode='a',encoding='utf-8',
delay=False) # perhaps should revisit the delay=False bit
fre_logger.debug('setting fre_file_handler logging format:')
fre_log_file_formatter=logging.Formatter(fmt=FORMAT)
fre_file_handler.setFormatter(fre_log_file_formatter)
base_fre_logger.addHandler(fre_file_handler)
# first message that will appear in the log file if used
fre_logger.info('fre_file_handler added to base_fre_logger')
fre_logger.debug('click entry-point function call done.')