Skip to content
Snippets Groups Projects
Commit 7820b39f authored by Alan De Smet's avatar Alan De Smet
Browse files

Refactoring

parent c89af7a3
Branches
No related tags found
No related merge requests found
......@@ -6,30 +6,22 @@ import datetime as dt
import tempfile
sys.path.append(os.path.abspath('..'))
from csppfetch import DownloadStatistics
import aitfancil
from conlog import add_console_logging
import aitf.ancil
from aitf.conlog import add_console_logging
# Environment variable that can hold the path to the cache
CACHE_ENV="CSPP_GEO_AITF_CACHE"
def parse_datetime_from_gfs_filename(filename):
return dt.datetime.strptime( filename[:-2], "%Y/%m/%d/gfs.t%Hz.pgrbf")
def parse_args():
import argparsetools
from argparsetools import arg_duration, arg_datetime
from aitf.argparsetools import add_cache_dir_arg, add_verbose_quiet_args, \
process_verbosity, SmartFormatter, arg_duration, arg_datetime
""" Parse arguments. Returns a namespace as returned by argparse.ArgumentParser.parse_args(). """
import argparse
# Special case for -x/--expert, which shows help including normally hidden options
#expert_only = argparsetools.process_expert()
default_expiration_days = 7
......@@ -44,10 +36,10 @@ def parse_args():
is recommended. The form "20210581450000" (YYYYjjjHHMMSSt) is also
understood.
""",
formatter_class = argparsetools.SmartFormatter
formatter_class = SmartFormatter
)
argparsetools.add_cache_dir_arg(ap)
add_cache_dir_arg(ap)
ap.add_argument('--keep-old', dest='keep_old', action='store_true',
help='keep old files; do not remove them')
......@@ -71,15 +63,14 @@ def parse_args():
metavar='DURATION',
help='how far before --newest to download files (default: %(default)s)')
argparsetools.add_verbose_quiet_args(ap)
#argparsetools.add_expert_arg(ap)
add_verbose_quiet_args(ap)
args = ap.parse_args()
if args.oldest is None:
args.oldest = args.newest - args.download_window
argparsetools.process_verbosity(args)
process_verbosity(args)
return args
......@@ -93,7 +84,7 @@ def main():
args = parse_args()
sststats = DownloadStatistics()
aitfancil.SST.update_cache(args.dir,
aitf.ancil.SST.update_cache(args.dir,
start_time=args.oldest,
end_time=args.newest,
download_stats = sststats,
......@@ -101,7 +92,7 @@ def main():
print_download_report("SST Download Summary", sststats)
gfsstats = DownloadStatistics()
aitfancil.GFS.update_cache(args.dir,
aitf.ancil.GFS.update_cache(args.dir,
start_time=args.oldest,
end_time=args.newest,
download_stats = gfsstats,
......
File moved
# python3
import argparse
def expert_only_show(x): return x
def expert_only_hide(x): return argparse.SUPPRESS
def handle():
# Special case for -x/--expert, which shows help including normally hidden options
expert_opts = ["-x", "--expert"]
expert_help = False
for o in expert_opts:
if o in sys.argv:
expert_help = True
idx = sys.argv.index(o)
sys.argv[idx] = '--help'
break
if expert_help:
return expert_only_show
return expert_only_hide
def add_argument(parser):
# --expert will never be found, as we handle it before argparse is running!
# We still want it for documentation, though.
parser.add_argument('--expert', '-x', dest='expert', action='store_true',
help='show all help, including advanced options, and exit'
)
......@@ -11,23 +11,6 @@ CACHE_ENV="CSPP_GEO_AITF_CACHE"
def argerror(msg):
raise argparse.ArgumentTypeError(msg)
def expert_only_show(x): return x
def expert_only_hide(x): return argparse.SUPPRESS
def process_expert():
# Special case for -x/--expert, which shows help including normally hidden options
expert_opts = ["-x", "--expert"]
expert_help = False
for o in expert_opts:
if o in sys.argv:
expert_help = True
idx = sys.argv.index(o)
sys.argv[idx] = '--help'
break
if expert_help:
return expert_only_show
return expert_only_hide
def add_verbose_quiet_args(parser):
g = parser.add_mutually_exclusive_group()
g.add_argument('--verbose', '-v', dest='verbosity', action='count',
......@@ -50,14 +33,6 @@ def process_verbosity(args):
logging.getLogger().setLevel(args.log_level)
def add_expert_arg(parser):
# --expert will never be found, as we handle it before argparse is running!
# We still want it for documentation, though.
parser.add_argument('--expert', '-x', dest='expert', action='store_true',
help='show all help, including advanced options, and exit'
)
CACHE_INVALID = "not specified"
def add_cache_dir_arg(parser):
CACHE_DEFAULT = os.environ.get(CACHE_ENV,CACHE_INVALID)
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment