From b8bb881184fb03c2a5c89160aeefdaddddd29543 Mon Sep 17 00:00:00 2001 From: vincentcasseau Date: Thu, 1 Aug 2024 15:50:09 +0200 Subject: [PATCH] KCore: default to notifications in terminal window --- Cassiopee/KCore/install | 8 ++++++++ Cassiopee/KCore/installLib.py | 1 - Cassiopee/KCore/test/notifyCheckout | 10 ++++++++++ Cassiopee/KCore/test/notifyCheckout.py | 27 +++++++++++++++++--------- Cassiopee/KCore/test/notifyInstall | 10 ++++++++++ Cassiopee/KCore/test/notifyInstall.py | 22 ++++++++++++++------- Cassiopee/KCore/test/notifyValid | 10 ++++++++++ Cassiopee/KCore/test/notifyValid.py | 22 ++++++++++++++------- 8 files changed, 86 insertions(+), 24 deletions(-) create mode 100755 Cassiopee/KCore/test/notifyCheckout create mode 100755 Cassiopee/KCore/test/notifyInstall create mode 100755 Cassiopee/KCore/test/notifyValid diff --git a/Cassiopee/KCore/install b/Cassiopee/KCore/install index e7c092f82..849be45b4 100755 --- a/Cassiopee/KCore/install +++ b/Cassiopee/KCore/install @@ -81,5 +81,13 @@ fi # Install libkcore python installLib.py +# Copie les scripts de notification d'installation et validation +cp test/notifyCheckout.py "$INSTALLPATH" +cp test/notifyCheckout "$INSTALLPATH" +cp test/notifyInstall.py "$INSTALLPATH" +cp test/notifyInstall "$INSTALLPATH" +cp test/notifyValid.py "$INSTALLPATH" +cp test/notifyValid "$INSTALLPATH" + # Check installation python test/t1.py diff --git a/Cassiopee/KCore/installLib.py b/Cassiopee/KCore/installLib.py index d40af1239..27ea8ba8f 100644 --- a/Cassiopee/KCore/installLib.py +++ b/Cassiopee/KCore/installLib.py @@ -42,7 +42,6 @@ shutil.copyfile("installPath.py", installPath+"/installPath.py") shutil.copyfile("installBase.py", installPath+"/installBase.py") shutil.copyfile("test/notify.py", installPath+"/notify.py") -shutil.copyfile("test/notifyInstall.py", installPath+"/notifyInstall.py") # Ecrit les infos d'install Dist.writeBuildInfo() diff --git a/Cassiopee/KCore/test/notifyCheckout b/Cassiopee/KCore/test/notifyCheckout new file mode 100755 index 000000000..9100472b2 --- /dev/null +++ b/Cassiopee/KCore/test/notifyCheckout @@ -0,0 +1,10 @@ +#! /bin/sh +if [ "$PYTHONEXE" != "" ]; then + alias python=$PYTHONEXE +fi +if test -e "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyCheckout.py" +then + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyCheckout.py" "$@" +else + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyCheckout.pyc" "$@" +fi diff --git a/Cassiopee/KCore/test/notifyCheckout.py b/Cassiopee/KCore/test/notifyCheckout.py index 1a19a4841..3dc069fb1 100644 --- a/Cassiopee/KCore/test/notifyCheckout.py +++ b/Cassiopee/KCore/test/notifyCheckout.py @@ -1,6 +1,8 @@ -# Send a notification by email to a list of recipients about the checkout -# status of different prods. Please set the environment variable CASSIOPEE_EMAIL -# Usage: python notifyCheckout.py --recipients='a.b@onera.fr c.d@onera.fr' +# Notify a user about the checkout status of different prods, either in the +# terminal window (default) or by email (set the environment variable +# CASSIOPEE_EMAIL and run on localhost) +# Usage: python notifyCheckout.py +# python notifyCheckout.py --email --recipients='a.b@onera.fr c.d@onera.fr' import sys from time import strptime, strftime @@ -9,6 +11,8 @@ def parseArgs(): import argparse # Create argument parser parser = argparse.ArgumentParser() + parser.add_argument("-e", "--email", action="store_true", + help="Email results. Default: print in terminal") parser.add_argument("-r", "--recipients", type=str, default='', help="Single-quoted space-separated list of recipients") # Parse arguments @@ -35,7 +39,9 @@ def parseArgs(): log_entries.sort(key=lambda x: x[1], reverse=True) # Do not send a notification when everything is OK - if not any('FAILED' in log_machine for log_machine in log_entries): sys.exit() + if not any('FAILED' in log_machine for log_machine in log_entries): + if script_args.email: sys.exit() + else: print("[Checkout Cassiopee] State: OK") # Get git info cassiopeeIncDir = '/stck/cassiope/git/Cassiopee/Cassiopee' @@ -45,9 +51,9 @@ def parseArgs(): gitInfo = "Git origin: {}\nGit branch: {}\nCommit hash: {}".format( gitOrigin, gitBranch, gitHash) - baseState = 'FAILED' + messageSubject = "[Checkout Cassiopee] State: FAILED" messageText = "Pulling updates for Cassiopee, Fast and all "\ - "PModules:\n{}\n\n{}\n\n\n".format(52*'-', gitInfo) + "PModules:\n{}\n\n{}\n\n".format(52*'-', gitInfo) messageText += '{:^20} | {:^15} | {:^30} | {:^10}\n{}\n'.format( "PROD.", "PCKG.", "DATE", "STATUS", 85*'-') for log_machine in log_entries: @@ -63,6 +69,9 @@ def parseArgs(): 'please contact the maintainers:\nchristophe.benoit@onera.fr, '\ 'vincent.casseau@onera.fr' - notify(recipients=recipients, - messageSubject="[Checkout Cassiopee] State: {}".format(baseState), - messageText=messageText) + if script_args.email: + notify(recipients=recipients, + messageSubject=messageSubject, + messageText=messageText) + else: + print("{0}\n|{1:^65}|\n{0}\n{2}".format(67*'-', messageSubject, messageText)) diff --git a/Cassiopee/KCore/test/notifyInstall b/Cassiopee/KCore/test/notifyInstall new file mode 100755 index 000000000..14d9b07f4 --- /dev/null +++ b/Cassiopee/KCore/test/notifyInstall @@ -0,0 +1,10 @@ +#! /bin/sh +if [ "$PYTHONEXE" != "" ]; then + alias python=$PYTHONEXE +fi +if test -e "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyInstall.py" +then + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyInstall.py" "$@" +else + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyInstall.pyc" "$@" +fi diff --git a/Cassiopee/KCore/test/notifyInstall.py b/Cassiopee/KCore/test/notifyInstall.py index 3d1842577..31c030985 100644 --- a/Cassiopee/KCore/test/notifyInstall.py +++ b/Cassiopee/KCore/test/notifyInstall.py @@ -1,6 +1,8 @@ -# Send a notification by email to a list of recipients about the installation -# status of different prods. Please set the environment variable CASSIOPEE_EMAIL -# Usage: python notifyInstall.py --recipients='a.b@onera.fr c.d@onera.fr' +# Notify a user about the installation status of different prods, either in the +# terminal window (default) or by email (set the environment variable +# CASSIOPEE_EMAIL and run on localhost) +# Usage: python notifyInstall.py +# python notifyInstall.py --email --recipients='a.b@onera.fr c.d@onera.fr' import sys from time import strptime, strftime @@ -9,6 +11,8 @@ def parseArgs(): import argparse # Create argument parser parser = argparse.ArgumentParser() + parser.add_argument("-e", "--email", action="store_true", + help="Email results. Default: print in terminal") parser.add_argument("-r", "--recipients", type=str, default='', help="Single-quoted space-separated list of recipients") # Parse arguments @@ -44,7 +48,7 @@ def parseArgs(): baseState = 'OK' messageText = "Installation of Cassiopee, Fast and all "\ - "PModules:\n{}\n\n{}\n\n\n".format(48*'-', gitInfo) + "PModules:\n{}\n\n{}\n\n".format(48*'-', gitInfo) messageText += '{:^20} | {:^30} | {:^10}\n{}\n'.format( "PROD.", "DATE", "STATUS", 67*'-') for log_machine in log_entries: @@ -55,11 +59,15 @@ def parseArgs(): messageText += '{:^20} | {:^30} | {:^10}\n'.format(prod, date, status) if 'FAILED' in log_machine: baseState = 'FAILED' + messageSubject = "[Install Cassiopee] State: {}".format(baseState) if baseState == 'FAILED': messageText += '\n\nIf the prod. you wish to use is marked as FAILED, '\ 'please contact the maintainers:\nchristophe.benoit@onera.fr, '\ 'vincent.casseau@onera.fr' - notify(recipients=recipients, - messageSubject="[Install Cassiopee] State: {}".format(baseState), - messageText=messageText) + if script_args.email: + notify(recipients=recipients, + messageSubject=messageSubject, + messageText=messageText) + else: + print("{0}\n|{1:^65}|\n{0}\n{2}".format(67*'-', messageSubject, messageText)) diff --git a/Cassiopee/KCore/test/notifyValid b/Cassiopee/KCore/test/notifyValid new file mode 100755 index 000000000..c17056f8d --- /dev/null +++ b/Cassiopee/KCore/test/notifyValid @@ -0,0 +1,10 @@ +#! /bin/sh +if [ "$PYTHONEXE" != "" ]; then + alias python=$PYTHONEXE +fi +if test -e "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyValid.py" +then + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyValid.py" "$@" +else + python "$CASSIOPEE/Dist/bin/$ELSAPROD/notifyValid.pyc" "$@" +fi diff --git a/Cassiopee/KCore/test/notifyValid.py b/Cassiopee/KCore/test/notifyValid.py index 1661d80b5..4fa53bdc9 100644 --- a/Cassiopee/KCore/test/notifyValid.py +++ b/Cassiopee/KCore/test/notifyValid.py @@ -1,6 +1,8 @@ -# Send a notification by email to a list of recipients about the validation -# status of different prods. Please set the environment variable CASSIOPEE_EMAIL -# Usage: python notifyValid.py --recipients='a.b@onera.fr c.d@onera.fr' +# Notify a user about the validation status of different prods, either in the +# terminal window (default) or by email (set the environment variable +# CASSIOPEE_EMAIL and run on localhost) +# Usage: python notifyValid.py +# python notifyValid.py --email --recipients='a.b@onera.fr c.d@onera.fr' import sys from time import strptime, strftime @@ -9,6 +11,8 @@ def parseArgs(): import argparse # Create argument parser parser = argparse.ArgumentParser() + parser.add_argument("-e", "--email", action="store_true", + help="Email results. Default: print in terminal") parser.add_argument("-r", "--recipients", type=str, default='', help="Single-quoted space-separated list of recipients") # Parse arguments @@ -44,7 +48,7 @@ def parseArgs(): vnvState = 'OK' messageText = "Non-regression testing of Cassiopee, Fast and all "\ - "PModules:\n{}\n\n{}\n\n\n".format(58*'-', gitInfo) + "PModules:\n{}\n\n{}\n\n".format(58*'-', gitInfo) messageText += '{:^20} | {:^30} | {:^10}\n{}\n'.format( "PROD.", "DATE", "STATUS", 67*'-') for log_machine in log_entries: @@ -55,11 +59,15 @@ def parseArgs(): messageText += '{:^20} | {:^30} | {:^10}\n'.format(prod, date, status) if 'FAILED' in log_machine: vnvState = 'FAILED' + messageSubject = "[V&V Cassiopee] State: {}".format(vnvState) if vnvState == 'FAILED': messageText += '\n\nIf the prod. you wish to use is marked as FAILED, '\ 'please contact the maintainers:\nchristophe.benoit@onera.fr, '\ 'vincent.casseau@onera.fr' - notify(recipients=recipients, - messageSubject="[V&V Cassiopee] State: {}".format(vnvState), - messageText=messageText) + if script_args.email: + notify(recipients=recipients, + messageSubject=messageSubject, + messageText=messageText) + else: + print("{0}\n|{1:^65}|\n{0}\n{2}".format(67*'-', messageSubject, messageText))