Skip to content

Commit

Permalink
KCore: default to notifications in terminal window
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentcasseau committed Aug 1, 2024
1 parent b8e9892 commit b8bb881
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 24 deletions.
8 changes: 8 additions & 0 deletions Cassiopee/KCore/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion Cassiopee/KCore/installLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions Cassiopee/KCore/test/notifyCheckout
Original file line number Diff line number Diff line change
@@ -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
27 changes: 18 additions & 9 deletions Cassiopee/KCore/test/notifyCheckout.py
Original file line number Diff line number Diff line change
@@ -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='[email protected] [email protected]'
# 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='[email protected] [email protected]'
import sys
from time import strptime, strftime

Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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:
Expand All @@ -63,6 +69,9 @@ def parseArgs():
'please contact the maintainers:\n[email protected], '\
'[email protected]'

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))
10 changes: 10 additions & 0 deletions Cassiopee/KCore/test/notifyInstall
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions Cassiopee/KCore/test/notifyInstall.py
Original file line number Diff line number Diff line change
@@ -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='[email protected] [email protected]'
# 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='[email protected] [email protected]'
import sys
from time import strptime, strftime

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:\n[email protected], '\
'[email protected]'

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))
10 changes: 10 additions & 0 deletions Cassiopee/KCore/test/notifyValid
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions Cassiopee/KCore/test/notifyValid.py
Original file line number Diff line number Diff line change
@@ -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='[email protected] [email protected]'
# 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='[email protected] [email protected]'
import sys
from time import strptime, strftime

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:\n[email protected], '\
'[email protected]'

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))

0 comments on commit b8bb881

Please sign in to comment.