Skip to content

Commit

Permalink
Merge pull request tableau#138 from tableau/RestoreSetupFiles
Browse files Browse the repository at this point in the history
Add setup files which were deleted by mistake
  • Loading branch information
johng42 authored Nov 19, 2018
2 parents ea6d6ca + 855fb15 commit af0f3dc
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 0 deletions.
93 changes: 93 additions & 0 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@IF [%1]==[] (
set port=9004
) ELSE (
set port=%1
)
@SET CurrentPath="%~dp0"
@ECHO Server will be initialized using port: %port%
@SET CONDA_ENVIRONMENT=Tableau-Python-Server
@REG Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~ Looking for existing Anaconda installation ~~~~~~~~~~~~~~~~~
@ECHO.
@SET CONDACMD=""
@SET ACMD=""
@ECHO OFF
SET ANACONAREGKEY=Anaconda_*
@IF EXIST %UserProfile%\Anaconda\Scripts\conda.exe SET CONDACMD=%UserProfile%\Anaconda\Scripts
@IF %CONDACMD%=="" FOR /f %%p in ('where anaconda.bat /f') do SET CONDACMD=%%p
@IF %CONDACMD%=="" FOR /f %%z in ('REG Query HKU /k /s /f %ANACONAREGKEY%') DO IF %%z NEQ End SET ACMD=%%z
@IF %CONDACMD%=="" IF NOT %ACMD%=="" SET ACMD=%ACMD:HKEY_USERS=HKU%\InstallPath
@IF %CONDACMD%=="" IF NOT %ACMD%=="" FOR /f "tokens=1,3" %%a in ('REG Query %ACMD%') DO IF %%a==(Default) SET CONDACMD=%%b\Scripts
SET CONDACMD=%CONDACMD:\anaconda.bat=%
@IF EXIST %CONDACMD%\anaconda.bat (
@ECHO Existing Anaconda installation found.
) ELSE (
@ECHO No existing Anaconda installation found.
@ECHO Looking for a local installer...
IF EXIST "%~dp0\Anaconda-Installer.exe" (
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~ Installing Anaconda from existing installer ~~~~~~~~~~~~~~~~
@ECHO This may take a few minutes
@ECHO.
) ELSE (
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~~~~~ Downloading and installing Anaconda ~~~~~~~~~~~~~~~~~~~~
@ECHO This may take a few minutes
@ECHO.
@IF %OS%==64BIT powershell -Command "Import-Module BitsTransfer; Start-BitsTransfer https://repo.continuum.io/archive/Anaconda-2.3.0-Windows-x86_64.exe $PWD\Anaconda-Installer.exe"
@IF %OS%==32BIT powershell -Command "Import-Module BitsTransfer; Start-BitsTransfer https://repo.continuum.io/archive/Anaconda-2.3.0-Windows-x86.exe $PWD\Anaconda-Installer.exe"
@ECHO Download completed.
)
@ECHO Installing Anaconda...
@start /wait "" Anaconda-Installer.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Anaconda
IF %CONDACMD%=="" SET CONDACMD=%UserProfile%\Anaconda\Scripts
)
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~ Activating the environment ~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO.
@IF NOT EXIST "%CONDACMD%\conda.exe" (
@CD "%CONDACMD%"
@CD ..\..\..
@SET "CONDACMD=%CD%\Scripts"
@CD %CurrentPath%
)
@SET PATH=%PATH%;%CONDACMD%
@IF NOT EXIST %CONDACMD:Scripts=envs%\%CONDA_ENVIRONMENT% (
@ECHO No %CONDA_ENVIRONMENT% environment found. Creating one...
@conda create --yes --name %CONDA_ENVIRONMENT% --clone root
) ELSE (
@ECHO Found existing %CONDA_ENVIRONMENT% environment.
@ECHO %CONDACMD:Scripts=envs%\%CONDA_ENVIRONMENT%
)
@CALL %CONDACMD%\activate %CONDA_ENVIRONMENT%
@SET PYTHONPATH="%PYTHONPATH%";%CONDACMD:Scripts=envs%\%CONDA_ENVIRONMENT%\Scripts
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~ Installing dependencies ~~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO.
@CD %CurrentPath%
pip install ./tabpy-client
pip install ./tabpy-server
@SET STARTUPBAT=%CONDACMD:Scripts=envs%\%CONDA_ENVIRONMENT%\Lib\site-packages\tabpy_server\startup.bat
@SET TABPY_STATE_PATH=%CONDACMD:Scripts=envs%\%CONDA_ENVIRONMENT%\Lib\site-packages\tabpy_server
@IF EXIST %STARTUPBAT% (
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Installation complete ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO.
@ECHO.
@ECHO From now on, you can start the server by running %STARTUPBAT%
@ECHO.
@ECHO.
@CD %TABPY_STATE_PATH%
@ECHO Starting the server for the first time...
@ECHO.
@ECHO.
@IF NOT EXIST "%TABPY_STATE_PATH%\state.ini" @copy "%TABPY_STATE_PATH%\state.ini.template" "%TABPY_STATE_PATH%\state.ini"
@SET PYTHONPATH="%PYTHONPATH%";%TABPY_STATE_PATH%
@python "%TABPY_STATE_PATH%\tabpy.py" --port %port%
)
IF NOT EXIST %STARTUPBAT% (
@ECHO.
@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Installation failed ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ECHO.
)
118 changes: 118 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
CONDA_ENVIRONMENT=Tableau-Python-Server
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
CONDACMD="$(which conda)"

if [ "$#" -ne 1 ] ; then
PORT=9004
else
PORT=$1
fi

function download_file {
# detect wget
echo "Downloading $2 from $1 ..."
# if it is a file
download_file_result=0
if [ -e $1 ] ; then
cp $1 $2
return
fi
if [ -z `which wget` ] ; then
if [ -z `which curl` ] ; then
echo "Unable to find either curl or wget! Cannot proceed with
automatic install."
exit 1
fi
# -f makes it fail on no status code
curl -f $1 -o $2 || download_file_result=$?
else
wget $1 -O $2 || download_file_result=$?
fi
# wget leaves stuff lying around even if the download failed
if [ $download_file_result -ne 0 ]; then
rm -f $2
fi
} # end of download file

echo "~~~~~~~~~~~~~~~ Downloading and installing Anaconda ~~~~~~~~~~~~~~~"

# install anaconda if not already available
if [ -z `which conda` ] ; then
conda_download=""
if [[ $OSTYPE == linux* ]]; then
echo "Linux detected"
conda_download="repo.continuum.io/archive/Anaconda-2.3.0-Linux-x86_64.sh"
conda_ext=".sh"
elif [[ $OSTYPE == darwin* ]]; then
echo "Mac detected"
conda_download="repo.continuum.io/archive/Anaconda-2.3.0-MacOSX-x86_64.sh"
conda_ext=".sh"
else
echo "Unsupported Operating System"
exit 1
fi

conda_download="https://$conda_download"

if [[ ! -e "anaconda$conda_ext" ]]; then
echo "Trying to download anaconda"
download_file $conda_download "anaconda$conda_ext"
if [ $download_file_result -ne 0 ]; then
echo "Unable to download anaconda installation"
exit 1
fi
else
echo "Existing Anaconda installer found. Installing…"
fi
bash anaconda.sh -p $HOME/anaconda -b
CONDACMD=$HOME/anaconda/bin/conda
CONDAFOLDER="$( dirname "$CONDACMD" )"
export PATH=$CONDACMD:$PATH
else
echo "Anaconda installed already."
fi

# Make sure we're using conda in root environment since we assume that directory structure
cd "$CONDAFOLDER"
source activate root
CONDAFOLDER="$( dirname "$(which conda)" )"
cd "$CONDAFOLDER"
cd ".."

echo "~~~~~~~~~~~~~~~ Activating the environment ~~~~~~~~~~~~~~~"

if [ ! -e "$PWD/envs/$CONDA_ENVIRONMENT" ]; then
echo "Conda env '$CONDA_ENVIRONMENT' doesn't exist, creating now."
$CONDACMD create --yes -n $CONDA_ENVIRONMENT --clone root
else
echo "Conda env '$CONDA_ENVIRONMENT' already exists."
fi

# activate that environment
export ANACONDA_ENVS=$PWD/envs
export CONDA_DEFAULT_ENV=$CONDA_ENVIRONMENT
export CONDA_ENV_PATH=$PWD/envs
export PATH=$PWD/envs/$CONDA_ENVIRONMENT:$PATH
source activate $CONDA_ENVIRONMENT

# We need this for Python to find other .py files in the server folder
export PYTHONPATH=$PYTHONPATH:$SCRIPT_DIR

echo "~~~~~~~~~~~~~~~ Installing dependencies ~~~~~~~~~~~~~~~"

pip install "$SCRIPT_DIR"/tabpy-client
pip install "$SCRIPT_DIR"/tabpy-server

STARTUPPATH="$PWD/envs/$CONDA_ENVIRONMENT/lib/python2.7/site-packages/tabpy_server"

if [ ! -f "$STARTUPPATH/startup.sh" ]; then
echo "~~~~~~~~~~~~~~~~~ Installation failed ~~~~~~~~~~~~~~~~"
else
echo "~~~~~~~~~~~~~~~ Installation completed ~~~~~~~~~~~~~~~"
echo
echo "From now on, you can start the server by running $STARTUPPATH/startup.sh"
echo
echo
echo "Starting the server for the first time..."
bash "$STARTUPPATH/startup.sh" $PORT
fi

0 comments on commit af0f3dc

Please sign in to comment.