# version.py
#
# ESA (C) 2000-2021
#
# This file is part of ESA's XMM-Newton Scientific Analysis System (SAS).
#
# SAS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SAS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SAS. If not, see <http://www.gnu.org/licenses/>.
#
# version.py
# pySAS version
VERSION = '2.5.2'
import subprocess, os, sys
[docs]
def get_sas_version():
"""
Function to return information about the SAS version. Runs 'sasversion' and
parses the output.
Returns
-------
dict
Dictionary of SAS version information.
"""
sas_dir = os.environ.get('SAS_DIR')
if sas_dir == None:
print('Error: SAS_DIR is undefined')
sys.exit()
SAS_RELEASE = ''
SAS_AKA = ''
SAS_COMPILATION_DATE = ''
SAS_COMPILATION_HOST = ''
SAS_COMPILATION_USER = ''
SAS_PLATFORM = ''
SAS_COMMIT_ID = ''
cmd = 'sasversion'
# Start the subprocess
process = subprocess.Popen(cmd,
bufsize=1,
shell=True,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
# Log stdout and stderr in real-time
# For non-Python SAS tasks the stout and stderr are combined
output = []
for line in process.stdout:
output.append(f"{line.strip()}")
# Wait for the process to complete and get the return code
process.wait()
for line in output:
if line.startswith('SAS release'):
SAS_RELEASE = line.split(':')[1].lstrip()
if '-' in SAS_RELEASE:
# If SAS_RELEASE uses dashes (v22>=)
SAS_AKA = SAS_RELEASE.split('-')[0]
SAS_COMMIT_ID = SAS_RELEASE.split('-')[1]
else:
# If SAS_RELEASE uses underscores (v21<=)
SAS_AKA = SAS_RELEASE.split('_')[0]
if line.startswith('Compiled on'):
SAS_COMPILATION_DATE = line.split(':', 1)[1].lstrip()
if line.startswith('Compiled by'):
temp = line.split(':')[1].lstrip()
try:
SAS_COMPILATION_USER = temp.split('@')[0]
SAS_COMPILATION_HOST = temp.split('@')[1]
except Exception:
pass
if line.startswith('Platform'):
SAS_PLATFORM = line.split(':')[1].lstrip()
return_dict = {'RELEASE' : SAS_RELEASE,
'AKA' : SAS_AKA,
'COMPILATION_DATE' : SAS_COMPILATION_DATE,
'COMPILATION_HOST' : SAS_COMPILATION_HOST,
'COMPILATION_USER' : SAS_COMPILATION_USER,
'PLATFORM' : SAS_PLATFORM,
'COMMIT_ID' : SAS_COMMIT_ID}
return return_dict
[docs]
def print_sas_version():
"""
Shows release and information about the XMM-Newton
Science Analysis System (SAS).
Raises
------
EnvironmentError
SAS_DIR is undefined.
"""
from pysas import VERSION, SAS_RELEASE, SAS_AKA, SAS_COMPILATION_DATE
from pysas import SAS_COMPILATION_USER, SAS_COMPILATION_HOST, SAS_PLATFORM
from pysas import SAS_COMMIT_ID
sas_dir = os.environ.get('SAS_DIR')
if sas_dir == None:
raise EnvironmentError('SAS_DIR is undefined.')
sas_path = os.environ.get('SAS_PATH')
sas_ccfpath = os.environ.get('SAS_CCFPATH')
sas_ccf = os.environ.get('SAS_CCF')
sas_odf = os.environ.get('SAS_ODF')
print(f'''
XMM-Newton SAS - release and build information
SAS release : {SAS_RELEASE}
SAS AKA : {SAS_AKA}
SAS commit ID: {SAS_COMMIT_ID}
Compiled on : {SAS_COMPILATION_DATE}
Compiled by : {SAS_COMPILATION_USER}@{SAS_COMPILATION_HOST}
Platform : {SAS_PLATFORM}
pySAS version: {VERSION}
SAS-related environment variables set:
''')
print(f'SAS_DIR = {sas_dir}')
print(f'SAS_PATH = {sas_path}')
print(f'SAS_CCFPATH = {sas_ccfpath}') if sas_ccfpath != None else None
print(f'SAS_CCF = {sas_ccf}') if sas_ccf != None else None
print(f'SAS_ODF = {sas_odf}') if sas_odf != None else None