source: trunk/python/env.py@ 3061

Last change on this file since 3061 was 3056, checked in by Kana Sugimoto, 9 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: new methods, get_rev_info_file, get_asap_revdate, to support git

Test Programs:

Put in Release Notes: No

Module(s):

Description: committing changes for git from Ville.


File size: 2.8 KB
RevLine 
[1858]1"""This module has various functions for environment specific setings.
2"""
[1859]3__all__ = ["is_casapy", "is_ipython", "setup_env", "get_revision",
[3056]4 "is_asap_cli", "get_asap_revdate"]
[1797]5
6import sys
7import os
8import shutil
9import platform
10
11def is_casapy():
[1858]12 """Are we running inside casapy?"""
[1797]13 try:
[1848]14 from taskinit import casalog
[1797]15 return True
16 except ImportError:
17 return False
18
19def is_ipython():
[1858]20 """Are we running inside IPython?"""
[1797]21 return 'IPython' in sys.modules.keys()
22
[1859]23def is_asap_cli():
24 """Are we running inside asap ipython (but not casapy)"""
25 return is_ipython() and not is_casapy()
26
[1797]27def setup_env():
[1858]28 """Set-up environment variables for casa and initialise ~/.asap on first
29 use.
30 """
[1797]31 # Set up CASAPATH and first time use of asap i.e. ~/.asap/*
32 plf = None
33 if sys.platform == "linux2":
34 if platform.architecture()[0] == '64bit':
35 plf = 'linux_64b'
36 else:
37 plf = 'linux_gnu'
38 elif sys.platform == 'darwin':
39 plf = 'darwin'
40 else:
41 # Shouldn't happen - default to linux
42 plf = 'linux'
43 asapdata = os.path.split(__file__)[0]
44
45 # Allow user defined data location
46 if os.environ.has_key("ASAPDATA"):
47 if os.path.exists(os.environ["ASAPDATA"]):
48 asapdata = os.environ["ASAPDATA"]
49 # use CASAPATH if defined and "data" dir present
50 if not os.environ.has_key("CASAPATH") or \
51 not os.path.exists(os.environ["CASAPATH"].split()[0]+"/data"):
52 os.environ["CASAPATH"] = "%s %s somwhere" % ( asapdata, plf)
[2499]53
[3056]54def get_revinfo_file():
[1858]55 """Get the revision of the software. Only useful within casapy."""
[1797]56 if not is_casapy:
57 return ' unknown '
58 casapath=os.environ["CASAPATH"].split()
[2090]59 versioninfo = sys.version_info
60 pyversion = '%s.%s'%(versioninfo[0],versioninfo[1])
[3056]61 revinfo = None
[2090]62 if os.path.isdir(casapath[0]+'/'+casapath[1]+'/python/%s/asap'%(pyversion)):
[1797]63 # for casa developer environment (linux or darwin)
[2090]64 revinfo=casapath[0]+'/'+casapath[1]+'/python/%s/asap/svninfo.txt'%(pyversion)
[1797]65 else:
66 # for end-user environments
67 if casapath[1]=='darwin':
68 revinfo=casapath[0]+'/Resources/python/asap/svninfo.txt'
69 else:
[2090]70 revinfo=casapath[0]+'/lib/python%s/asap/svninfo.txt'%(pyversion)
[3056]71 return revinfo
72
73def get_revision():
74 revinfo=get_revinfo_file()
[1797]75 if os.path.isfile(revinfo):
76 f = file(revinfo)
77 f.readline()
78 revsionno=f.readline()
79 f.close()
80 return revsionno.rstrip()
81 return ' unknown '
[3056]82
83
84def get_asap_revdate():
85 revinfo=get_revinfo_file()
86 if os.path.isfile(revinfo):
87 f = file(revinfo)
88 f.readline()
89 f.readline()
90 revdate=f.readline()
91 return revdate.rstrip().lstrip()
92 return 'unknown'
93
94
Note: See TracBrowser for help on using the repository browser.