Skip to content

Commit

Permalink
Update Develop-ref after dtcenter/MET#2251 (#1778)
Browse files Browse the repository at this point in the history
Co-authored-by: Hank Fisher <[email protected]>
Co-authored-by: George McCabe <[email protected]>
Co-authored-by: Mrinal Biswas <[email protected]>
Co-authored-by: jprestop <[email protected]>
Co-authored-by: johnhg <[email protected]>
Co-authored-by: Mrinal Biswas <[email protected]>
Co-authored-by: Julie Prestopnik <[email protected]>
Co-authored-by: j-opatz <[email protected]>
Co-authored-by: Kathryn Newman <[email protected]>
Co-authored-by: j-opatz <[email protected]>
Co-authored-by: Lisa Goodrich <[email protected]>
Co-authored-by: Julie Prestopnik <[email protected]>
Co-authored-by: Christina Kalb <[email protected]>
Co-authored-by: Christina Kalb <[email protected]>
Co-authored-by: Hank Fisher <[email protected]>
Co-authored-by: mrinalbiswas <[email protected]>
Co-authored-by: bikegeek <[email protected]>
Co-authored-by: lisagoodrich <[email protected]>
Co-authored-by: Howard Soh <[email protected]>
Co-authored-by: Molly Smith <[email protected]>
Co-authored-by: hsoh-u <[email protected]>
Co-authored-by: bikegeek <[email protected]>
  • Loading branch information
20 people authored Sep 6, 2022
1 parent 5ae03a5 commit 4e66d09
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
44 changes: 40 additions & 4 deletions metplus/util/met_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import bz2
import zipfile
import struct
import getpass
from dateutil.relativedelta import relativedelta
from pathlib import Path
from importlib import import_module
Expand Down Expand Up @@ -39,9 +40,12 @@ def pre_run_setup(config_inputs):

logger = config.logger

user_info = get_user_info()
user_string = f' as user {user_info} ' if user_info else ' '

config.set('config', 'METPLUS_VERSION', version_number)
logger.info('Running METplus v%s called with command: %s',
version_number, ' '.join(sys.argv))
logger.info('Running METplus v%s%swith command: %s',
version_number, user_string, ' '.join(sys.argv))

logger.info(f"Log file: {config.getstr('config', 'LOG_METPLUS')}")
logger.info(f"METplus Base: {config.getdir('METPLUS_BASE')}")
Expand Down Expand Up @@ -197,19 +201,51 @@ def post_run_cleanup(config, app_name, total_errors):
total_run_time = end_clock_time - start_clock_time
logger.debug(f"{app_name} took {total_run_time} to run.")

user_info = get_user_info()
user_string = f' as user {user_info}' if user_info else ''
if not total_errors:
logger.info(log_message)
logger.info(f'{app_name} has successfully finished running.')
logger.info('%s has successfully finished running%s.',
app_name, user_string)
return

error_msg = f"{app_name} has finished running but had {total_errors} error"
error_msg = (f'{app_name} has finished running{user_string} '
f'but had {total_errors} error')
if total_errors > 1:
error_msg += 's'
error_msg += '.'
logger.error(error_msg)
logger.info(log_message)
sys.exit(1)

def get_user_info():
"""! Get user information from OS. Note that some OS cannot obtain user ID
and some cannot obtain username.
@returns username(uid) if both username and user ID can be read,
username if only username can be read, uid if only user ID can be read,
or an empty string if neither can be read.
"""
try:
username = getpass.getuser()
except OSError:
username = None

try:
uid = os.getuid()
except AttributeError:
uid = None

if username and uid:
return f'{username}({uid})'

if username:
return username

if uid:
return uid

return ''

def write_all_commands(all_commands, config):
"""! Write all commands that were run to a file in the log
directory. This includes the environment variables that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ MODE_OUTPUT_DIR = {OUTPUT_BASE}/short_range/brightness_temperature/mode
# GridStat

FCST_GRID_STAT_INPUT_DIR = {MODE_OUTPUT_DIR}
FCST_GRID_STAT_INPUT_TEMPLATE = mode_{MODE_OUTPUT_PREFIX}_{lead?fmt=%HH}0000L_{valid?fmt=%Y%m%d}_{valid?fmt=%H%M%S}V_NAA_obj.nc
FCST_GRID_STAT_INPUT_TEMPLATE = mode_{MODE_OUTPUT_PREFIX}_{lead?fmt=%HH}0000L_{valid?fmt=%Y%m%d}_{valid?fmt=%H%M%S}V_000000A_obj.nc

OBS_GRID_STAT_INPUT_DIR = {FCST_GRID_STAT_INPUT_DIR}
OBS_GRID_STAT_INPUT_TEMPLATE = {FCST_GRID_STAT_INPUT_TEMPLATE}
Expand Down

0 comments on commit 4e66d09

Please sign in to comment.