@@ -636,14 +636,49 @@ def _create_batch_scripts(self):
636636cmd.exe /k
637637""" )
638638
639+
640+ self .create_batch_script ('Add_or_removeLine.vbs' ,r"""
641+ 'from http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/07/
642+ ' how-can-i-remove-any-line-in-a-text-file-that-contains-a-specified-string-value.aspx
643+ If WScript.Arguments.Count <> 3 then
644+ WScript.Echo "usage: Add_or_removeLine.vbs filename word_to_find line_to_add" &_
645+ vbNewLine & "or Add_or_removeLine.vbs filename word_to_find -remove"
646+ WScript.Quit
647+ end If
648+
649+ Set colArgs = WScript.Arguments
650+ Add_or_removeLine colArgs(0), colArgs(1), colArgs(2)
651+
652+ function Add_or_removeLine(strFilename, strFind, strAction)
653+ Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename, 1)
654+ a_change = False
655+ Do Until inputFile.AtEndOfStream
656+ strLine = inputFile.ReadLine
657+ If InStr(strLine, strFind) = 0 Then
658+ result_text= result_text & strLine & vbNewLine
659+ else
660+ a_change = True
661+ if strAction <> "-remove" then result_text= result_text & strLine & vbNewLine & strAction & vbNewLine
662+ End If
663+ Loop
664+ inputFile.Close
665+
666+ if a_change then
667+ Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename,2,true)
668+ outputFile.Write result_text
669+ outputFile.Close
670+ end if
671+ end function
672+ """ )
673+
639674 self .create_batch_script ('start_with_r.bat' , r"""@echo off
640675call %~dp0env.bat
641676
642677rem ******************
643678rem R part (supposing you install it in \tools\R of winpython)
644679rem ******************
645680set tmp_Rdirectory=R
646- if not exist "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" goto r_end
681+ if not exist "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" goto r_bad
647682
648683rem R_HOME for rpy2, R_HOMEBIN for PATH
649684set R_HOME=%WINPYDIR%\..\tools\%tmp_Rdirectory%\
@@ -653,15 +688,31 @@ def _create_batch_scripts(self):
653688set PATH=%SYS_PATH%;%R_HOMEbin%
654689
655690echo "r!"
656- echo "if you want it to be on your winpython icon, update %WINPYDIR%\settings\winpython.ini with"
657- echo "PATH=%path%"
658- echo " "
659- echo to launch Ipython with R, type now "Ipython notebook"
660- rem Ipython notebook
691+ echo "We are going to update %WINPYDIR%\settings\winpython.ini with"
692+ echo "R_HOME = %R_HOME%"
693+ echo "(relaunch this batch, if you move your winpython)"
694+ pause
661695
662- :r_end
696+ %~dp0Add_or_removeLine.vbs ..\settings\winpython.ini "R_HOME = " -remove
663697
664- cmd.exe /k
698+ rem Handle case when winpython.ini is not already created
699+ if exist "..\settings\winpython.ini" goto ini_exists
700+
701+ echo [debug]>"..\settings\winpython.ini"
702+ echo state = disabled>>"..\settings\winpython.ini"
703+ echo [environment]>>"..\settings\winpython.ini"
704+
705+ :ini_exists
706+ %~dp0Add_or_removeLine.vbs ..\settings\winpython.ini "[environment]" "R_HOME = %R_HOME%"
707+ goto r_end
708+
709+ :r_bad
710+
711+ echo directory "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" not found
712+ echo please install R at "%WINPYDIR%\..\tools\%tmp_Rdirectory%"
713+ pause
714+
715+ :r_end
665716""" )
666717 # Prepare a live patch on python (shame we need it) to have mingw64ok
667718 patch_distutils = ""
0 commit comments