Go to the documentation of this file.00001 """This module has various functions for environment specific setings.
00002 """
00003 __all__ = ["is_casapy", "is_ipython", "setup_env", "get_revision",
00004 "is_asap_cli"]
00005
00006 import sys
00007 import os
00008 import shutil
00009 import platform
00010
00011 def is_casapy():
00012 """Are we running inside casapy?"""
00013 try:
00014 from taskinit import casalog
00015 return True
00016 except ImportError:
00017 return False
00018
00019 def is_ipython():
00020 """Are we running inside IPython?"""
00021 return 'IPython' in sys.modules.keys()
00022
00023 def is_asap_cli():
00024 """Are we running inside asap ipython (but not casapy)"""
00025 return is_ipython() and not is_casapy()
00026
00027 def setup_env():
00028 """Set-up environment variables for casa and initialise ~/.asap on first
00029 use.
00030 """
00031
00032 plf = None
00033 if sys.platform == "linux2":
00034 if platform.architecture()[0] == '64bit':
00035 plf = 'linux_64b'
00036 else:
00037 plf = 'linux_gnu'
00038 elif sys.platform == 'darwin':
00039 plf = 'darwin'
00040 else:
00041
00042 plf = 'linux'
00043 asapdata = os.path.split(__file__)[0]
00044
00045
00046 if os.environ.has_key("ASAPDATA"):
00047 if os.path.exists(os.environ["ASAPDATA"]):
00048 asapdata = os.environ["ASAPDATA"]
00049
00050 if not os.environ.has_key("CASAPATH") or \
00051 not os.path.exists(os.environ["CASAPATH"].split()[0]+"/data"):
00052 os.environ["CASAPATH"] = "%s %s somwhere" % ( asapdata, plf)
00053
00054 def get_revision():
00055 """Get the revision of the software. Only useful within casapy."""
00056 if not is_casapy:
00057 return ' unknown '
00058 casapath=os.environ["CASAPATH"].split()
00059 versioninfo = sys.version_info
00060 pyversion = '%s.%s'%(versioninfo[0],versioninfo[1])
00061 if os.path.isdir(casapath[0]+'/'+casapath[1]+'/python/%s/asap'%(pyversion)):
00062
00063 revinfo=casapath[0]+'/'+casapath[1]+'/python/%s/asap/svninfo.txt'%(pyversion)
00064 else:
00065
00066 if casapath[1]=='darwin':
00067 revinfo=casapath[0]+'/Resources/python/asap/svninfo.txt'
00068 else:
00069 revinfo=casapath[0]+'/lib/python%s/asap/svninfo.txt'%(pyversion)
00070 if os.path.isfile(revinfo):
00071 f = file(revinfo)
00072 f.readline()
00073 revsionno=f.readline()
00074 f.close()
00075 return revsionno.rstrip()
00076 return ' unknown '