### Telemetry shutdown hook
from casa_shutdown import add_shutdown_hook
from telemetry import telemetry
if (casa['state']['telemetry-enabled'] == True):
casalog.poststat("Stop CASA")
casa['state']['telemetry-enabled'] = ${TELEMETRY_DEFAULT}
casa_util = __casac__.utils.utils()
rcTelemetryFlag = str.upper(casa_util.getrc("EnableTelemetry"))
# Use the value from casarc file if it is set, otherwise leave it as is
if (rcTelemetryFlag == 'TRUE'):
casa['state']['telemetry-enabled'] = True
if (rcTelemetryFlag == 'FALSE'):
casa['state']['telemetry-enabled'] = False
# Use and environment variable if it is set
if (os.environ.has_key('CASA_ENABLE_TELEMETRY')):
if (os.environ['CASA_ENABLE_TELEMETRY'].upper( ) == 'TRUE'):
casa['state']['telemetry-enabled'] = True
if (os.environ['CASA_ENABLE_TELEMETRY'].upper( ) == 'FALSE'):
casa['state']['telemetry-enabled'] = False
# Command line telemetry flag is only used to enable telemetry temporarily
if (casa['flags'].telemetry == True):
casa['state']['telemetry-enabled'] = True
if (casa['state']['telemetry-enabled'] == True):
atexit.register(logShutdown)
casatelemetry = telemetry(casa)