forked from dnanexus/dx-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment
98 lines (82 loc) · 3.66 KB
/
environment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- Mode: shell-script -*-
#
# Copyright (C) 2013-2016 DNAnexus, Inc.
#
# This file is part of dx-toolkit (DNAnexus platform client libraries).
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#
# Source this file in a bash shell to initialize DNAnexus environment
# variables:
# $ source environment
# This line is compatible with bash, zsh and csh/tcsh. If running in csh, it sources the file "environment.csh" and quits.
test ! -z "$version" && echo "$shell" | grep -q csh && set SOURCE=`echo $_ | cut -f 2 -d " "` && set SOURCE=`dirname "$SOURCE"` && source "$SOURCE/environment.csh" && exit
# Resolve the location of this file
if [ -n "$ZSH_VERSION" ]; then
SOURCE="$0"
# While we're doing ZSH specifics, also turn on autocomplete compatibility
autoload bashcompinit
bashcompinit
elif [ -n "$BASH_VERSION" ]; then
SOURCE="${BASH_SOURCE[0]}"
fi
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
# Get RHEL version
if [ -e /etc/redhat-release ] ; then
RHEL_MAJOR_VERSION=$(grep -o "Red Hat Enterprise Linux .* release [0-9]\+" /etc/redhat-release | sed -e "s/Red Hat Enterprise Linux .* release //")
fi
export DNANEXUS_HOME="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
PYTHON_VERSION_NUMBER="$(python -c 'import sys; print("{}.{}".format(sys.version_info[0], sys.version_info[1]))')"
PYTHON_VERSION="python${PYTHON_VERSION_NUMBER}"
# Detect system installation of dx-toolkit
if [ "$DNANEXUS_HOME" = "/etc/profile.d" ]; then
ARGCOMPLETE_REGISTER_PATH="/usr/bin/register-python-argcomplete"
export DNANEXUS_HOME="/usr/share/dnanexus"
# Private Python packages. We really ought not pollute PYTHONPATH with these though.
export PYTHONPATH="/usr/share/dnanexus/lib/${PYTHON_VERSION}/site-packages:$PYTHONPATH"
export CLASSPATH="/usr/share/java/dnanexus-api-0.1.0.jar:${CLASSPATH}"
else
ARGCOMPLETE_REGISTER_PATH="${DNANEXUS_HOME}/bin/register-python-argcomplete"
export PATH="${DNANEXUS_HOME}/bin:$PATH"
export CLASSPATH="${DNANEXUS_HOME}/lib/java/*:${CLASSPATH}"
if [ "$RHEL_MAJOR_VERSION" = "7" ]; then
export PYTHONPATH="${DNANEXUS_HOME}/share/dnanexus/lib64/${PYTHON_VERSION}/site-packages:$PYTHONPATH"
else
export PYTHONPATH="${DNANEXUS_HOME}/share/dnanexus/lib/${PYTHON_VERSION}/site-packages:$PYTHONPATH"
fi
fi
# Note: The default I/O stream encoding in Python 2.7 (as configured on ubuntu) is ascii, not UTF-8 or the system locale
# encoding. We reset it here to avoid having to set it for every I/O operation explicitly.
export PYTHONIOENCODING=UTF-8
if [ -e ${ARGCOMPLETE_REGISTER_PATH} ]; then
eval "$(${ARGCOMPLETE_REGISTER_PATH} dx|sed 's/-o default//')"
fi
# Clean up old session files
(
if [ -n "$BASH_VERSION" ]; then
shopt -s nullglob
elif [ -n "$ZSH_VERSION" ]; then
setopt null_glob
fi
if [[ $HOME != "" ]]; then
for session_dir in "${HOME}/.dnanexus_config/sessions/"*; do
if ! ps -p $(basename "$session_dir") &> /dev/null; then
rm -rf "$session_dir"
fi
done
fi
)
if [[ -z "$DX_SECURITY_CONTEXT" && -n "$DX_AUTH_TOKEN" ]]; then
export DX_SECURITY_CONTEXT="{\"auth_token_type\":\"Bearer\",\"auth_token\":\"$DX_AUTH_TOKEN\"}"
fi