From 4e66d09167ff341c0db64a68f800a0e23d159d07 Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:36:45 -0600 Subject: [PATCH] Update Develop-ref after dtcenter/MET#2251 (#1778) Co-authored-by: Hank Fisher Co-authored-by: George McCabe <23407799+georgemccabe@users.noreply.github.com> Co-authored-by: Mrinal Biswas Co-authored-by: jprestop Co-authored-by: johnhg Co-authored-by: Mrinal Biswas Co-authored-by: Julie Prestopnik Co-authored-by: j-opatz Co-authored-by: Kathryn Newman Co-authored-by: j-opatz <59586397+j-opatz@users.noreply.github.com> Co-authored-by: Lisa Goodrich Co-authored-by: Julie Prestopnik Co-authored-by: Christina Kalb Co-authored-by: Christina Kalb Co-authored-by: Hank Fisher Co-authored-by: mrinalbiswas Co-authored-by: bikegeek <3753118+bikegeek@users.noreply.github.com> Co-authored-by: lisagoodrich <33230218+lisagoodrich@users.noreply.github.com> Co-authored-by: Howard Soh Co-authored-by: Molly Smith Co-authored-by: hsoh-u Co-authored-by: bikegeek --- metplus/util/met_util.py | 44 +++++++++++++++++-- ...DE_fcstFV3_obsGOES_BrightnessTempObjs.conf | 2 +- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/metplus/util/met_util.py b/metplus/util/met_util.py index 7b458cec9..56668be91 100644 --- a/metplus/util/met_util.py +++ b/metplus/util/met_util.py @@ -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 @@ -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')}") @@ -197,12 +201,16 @@ 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 += '.' @@ -210,6 +218,34 @@ def post_run_cleanup(config, app_name, total_errors): 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 diff --git a/parm/use_cases/model_applications/short_range/MODE_fcstFV3_obsGOES_BrightnessTempObjs.conf b/parm/use_cases/model_applications/short_range/MODE_fcstFV3_obsGOES_BrightnessTempObjs.conf index 86723c215..ff97185d2 100644 --- a/parm/use_cases/model_applications/short_range/MODE_fcstFV3_obsGOES_BrightnessTempObjs.conf +++ b/parm/use_cases/model_applications/short_range/MODE_fcstFV3_obsGOES_BrightnessTempObjs.conf @@ -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}