1@setlocal enableextensions
2@echo off
3
4set D=%~dp0
5set PCBUILD=%D%..\..\PCbuild\
6
7set TARGETDIR=%TEMP%
8set TESTX86=
9set TESTX64=
10set TESTALLUSER=
11set TESTPERUSER=
12
13:CheckOpts
14if "%1" EQU "-h" goto Help
15if "%1" EQU "-x86" (set TESTX86=1) && shift && goto CheckOpts
16if "%1" EQU "-x64" (set TESTX64=1) && shift && goto CheckOpts
17if "%1" EQU "-t" (set TARGETDIR=%~2) && shift && shift && goto CheckOpts
18if "%1" EQU "--target" (set TARGETDIR=%~2) && shift && shift && goto CheckOpts
19if "%1" EQU "-a" (set TESTALLUSER=1) && shift && goto CheckOpts
20if "%1" EQU "--alluser" (set TESTALLUSER=1) && shift && goto CheckOpts
21if "%1" EQU "-p" (set TESTPERUSER=1) && shift && goto CheckOpts
22if "%1" EQU "--peruser" (set TESTPERUSER=1) && shift && goto CheckOpts
23
24if not defined TESTX86 if not defined TESTX64 (set TESTX86=1) && (set TESTX64=1)
25if not defined TESTALLUSER if not defined TESTPERUSER (set TESTALLUSER=1) && (set TESTPERUSER=1)
26
27
28if defined TESTX86 (
29    for %%f in ("%PCBUILD%win32\en-us\*.exe") do (
30        if defined TESTALLUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-alluser" "InstallAllUsers=1 CompileAll=1"
31        if errorlevel 1 exit /B
32        if defined TESTPERUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-peruser" "InstallAllUsers=0 CompileAll=0"
33        if errorlevel 1 exit /B
34    )
35)
36
37if defined TESTX64 (
38    for %%f in ("%PCBUILD%amd64\en-us\*.exe") do (
39        if defined TESTALLUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-alluser" "InstallAllUsers=1 CompileAll=1"
40        if errorlevel 1 exit /B
41        if defined TESTPERUSER call :test "%%~ff" "%TARGETDIR%\%%~nf-peruser" "InstallAllUsers=0 CompileAll=0"
42        if errorlevel 1 exit /B
43    )
44)
45
46exit /B 0
47
48:test
49@setlocal
50@echo on
51
52@if not exist "%~1" exit /B 1
53
54@set EXE=%~1
55@if not "%EXE:embed=%"=="%EXE%" exit /B 0
56
57@set EXITCODE=0
58@echo Installing %1 into %2
59"%~1" /passive /log "%~2\install\log.txt" TargetDir="%~2\Python" Include_debug=1 Include_symbols=1 %~3
60
61@if not errorlevel 1 (
62    @echo Printing version
63    "%~2\Python\python.exe" -c "import sys; print(sys.version)" > "%~2\version.txt" 2>&1
64)
65
66@if not errorlevel 1 (
67    @echo Capturing Start Menu
68    @dir /s/b "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs" | findstr /ic:"python" > "%~2\startmenu.txt" 2>&1
69    @dir /s/b "%APPDATA%\Microsoft\Windows\Start Menu\Programs" | findstr /ic:"python"  >> "%~2\startmenu.txt" 2>&1
70
71    @echo Capturing registry
72    @for /F "usebackq" %%f in (`reg query HKCR /s /f python /k`) do @(
73        echo %%f >> "%~2\hkcr.txt"
74        reg query "%%f" /s >> "%~2\hkcr.txt" 2>&1
75    )
76    @reg query HKCU\Software\Python /s > "%~2\hkcu.txt" 2>&1
77    @reg query HKLM\Software\Python /reg:32 /s > "%~2\hklm.txt" 2>&1
78    @reg query HKLM\Software\Python /reg:64 /s >> "%~2\hklm.txt" 2>&1
79    cmd /k exit 0
80)
81
82@if not errorlevel 1 (
83    @echo Installing package
84    "%~2\Python\python.exe" -m pip install "azure<0.10" > "%~2\pip.txt" 2>&1
85    @if not errorlevel 1 (
86        "%~2\Python\python.exe" -m pip uninstall -y azure python-dateutil six >> "%~2\pip.txt" 2>&1
87    )
88)
89@if not errorlevel 1 (
90    @echo Testing Tcl/tk
91    @set TCL_LIBRARY=%~2\Python\tcl\tcl8.6
92    "%~2\Python\python.exe" -m test -uall -v test_ttk_guionly test_tk test_idle > "%~2\tcltk.txt" 2>&1
93    @set TCL_LIBRARY=
94)
95
96@set EXITCODE=%ERRORLEVEL%
97
98@echo Result was %EXITCODE%
99@echo Removing %1
100"%~1" /passive /uninstall /log "%~2\uninstall\log.txt"
101
102@echo off
103exit /B %EXITCODE%
104
105:Help
106echo testrelease.bat [--target TARGET] [-x86] [-x64] [--alluser] [--peruser] [-h]
107echo.
108echo    --target (-t)   Specify the target directory for installs and logs
109echo    -x86            Run tests for x86 installers
110echo    -x64            Run tests for x64 installers
111echo    --alluser (-a)  Run tests for all-user installs (requires Administrator)
112echo    --peruser (-p)  Run tests for per-user installs
113echo    -h              Display this help information
114echo.
115echo If no test architecture is specified, all architectures will be tested.
116echo If no install type is selected, all install types will be tested.
117echo.
118