Commit 056be1cd authored by Jesse Mapel's avatar Jesse Mapel Committed by jlaura
Browse files

Added C-Shell variable setup (#3173)

* Added C-Shell variable setup

* Fixed history

* Made a bit more pythonic
parent d3b4d2e6
Loading
Loading
Loading
Loading
+53 −23
Original line number Diff line number Diff line
#!/usr/bin/env python
"""This program builds shell scripts that define ISIS3 environment variables during conda environment activation and deactivation, and creates some directories."""
"""
This program builds shell scripts that define ISIS3 environment variables during
conda environment activation and deactivation, and creates some directories.
"""

import argparse
import os
@@ -37,14 +40,17 @@ import sys
#       Description: Streamlined the program, improved documentation, and made the directory and
#                    file creation more `pythonic' rather than using system calls.
#
#       Author:  Jesse Mapel
#       Date:    2019-03-25
#       Description: Added C-Shell support.
#
#
##########################################################################################################

# There are still a lot of Python 2 installations out there, and if people don't have
# their conda environment set up properly, the error message they'll get will be hard
# to decipher.  This might help:
assert( sys.version_info >= (3,2) ) # Must be using Python 3.2 or later, is conda set up?

assert( sys.version_info >= (3,2) ) # Must be using Python 3.2 or later

# This just wraps and reports on the directory creation:
def mkdir( p ):
@@ -79,19 +85,43 @@ mkdir( activate_dir )
mkdir( deactivate_dir )

# Write the files that manage the ISIS3 environments:
activate_vars   =   activate_dir+'/env_vars.sh'
deactivate_vars = deactivate_dir+'/env_vars.sh'

with open( activate_vars, mode='w' ) as a:
    a.write('#!/bin/sh\n')
    a.write('export ISISROOT='+      os.environ['CONDA_PREFIX']+'\n')
    a.write('export ISIS3DATA='+     args.data_dir +'\n')
    a.write('export ISIS3TESTDATA='+ args.test_dir +'\n')
print( 'Wrote '+activate_vars )

with open( deactivate_vars, mode='w' ) as d:
    d.write('#!/bin/sh\n')
    d.write('unset ISISROOT\n')
    d.write('unset ISIS3DATA\n')
    d.write('unset ISIS3TESTDATA\n')
print( 'Wrote '+deactivate_vars )
activate_vars_sh   =   activate_dir+'/env_vars.sh'
deactivate_vars_sh = deactivate_dir+'/env_vars.sh'
activate_vars_csh   =   activate_dir+'/env_vars.csh'
deactivate_vars_csh = deactivate_dir+'/env_vars.csh'

with open( activate_vars_sh, mode='w' ) as a:
    script = """#!/bin/sh
export ISISROOT={}
export ISIS3DATA={}
export ISIS3TESTDATA={}
""".format(os.environ['CONDA_PREFIX'], args.data_dir, args.test_dir)
    a.write(script)
print( 'Wrote '+activate_vars_sh )

with open( deactivate_vars_sh, mode='w' ) as d:
    script = """#!/bin/sh
unset ISISROOT
unset ISIS3DATA
unset ISIS3TESTDATA
"""
    d.write(script)
print( 'Wrote '+deactivate_vars_sh )

with open( activate_vars_csh, mode='w' ) as a:
    script = """#!/bin/csh
setenv ISISROOT {}
setenv ISIS3DATA {}
setenv ISIS3TESTDATA {}
""".format(os.environ['CONDA_PREFIX'], args.data_dir, args.test_dir)
    a.write(script)
print( 'Wrote '+activate_vars_csh )

with open( deactivate_vars_csh, mode='w' ) as d:
    script = """#!/bin/sh
unsetenv ISISROOT
unsetenv ISIS3DATA
unsetenv ISIS3TESTDATA
"""
    d.write(script)
print( 'Wrote '+deactivate_vars_csh )