python check in installer

Robert Olson olson at mcs.anl.gov
Mon Mar 22 13:33:34 CST 2004


in the InitializeSetup code here is the stuff for python version finding.
--bob
-------------- next part --------------

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!


[Setup]
AppName=AG Shared Rasmol
;
; Version hardcoded in the path below; be careful to change there too.
;
AppVerName=AG Shared Rasmol 1.00
AppPublisher=Futures Lab
AppPublisherURL=http://www.mcs.anl.gov/fl
AppSupportURL=http://www.mcs.anl.gov/fl
AppUpdatesURL=http://www.mcs.anl.gov/fl
DefaultDirName={pf}\Access Grid Toolkit Applications\Shared Rasmol
DefaultGroupName=AG Shared Rasmol

OutputBaseFilename=sharedrasmol-setup-1.00
AppID={6DA1459A-6043-4DB1-8445-B0DFF5563F75}
[Tasks]


[Files]
Source: RasmolComm.py; DestDir: {app}; Flags: ignoreversion
Source: sharedrasmol.app; DestDir: {app}; Flags: ignoreversion
Source: SharedRasmol.py; DestDir: {app}; Flags: ignoreversion
Source: ..\RasMol\Release\rasmol.exe; DestDir: {app}; Flags: ignoreversion
Source: ..\Grid\RasMol_2.7.1.1\data\*.pdb; DestDir: {app}\data; Flags: ignoreversion

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

Source: {tmp}\RegisterApp.bat; DestDir: {app}; Flags: external
Source: {tmp}\UnregisterApp.bat; DestDir: {app}; Flags: external

Source: {tmp}\sharedrasmol.bat; DestDir: {app}; Flags: external

[Icons]



Name: {group}\Rasmol; Filename: {app}\rasmol.exe; WorkingDir: {app}
[UninstallDelete]
Type: files; Name: {app}\*.pyc

[Run]

Filename: {code:GetPythonDir}\python.exe; Parameters: {code:GetPythonDir}\Lib\compileall.py {app}; Description: Compile Python .py files to .pyc; Flags: postinstall
Filename: {app}\RegisterApp.bat; Check: RegisterAppCheck

[_ISTool]
Use7zip=false
[UninstallRun]
Filename: {app}\UnregisterApp.bat; Check: RegisterAppCheck
[Code]
var
  AGVersions : TArrayOfString;
  AGVersion, AGInstallPath : String;
  PythonPath : String;
  PythonPathVals: TArrayOfString;
  MultiplePythonInstalls: Boolean;
  RegisterApp : Boolean;

#include "registry.iss"



function RegisterAppCheck(): Boolean;
begin
	result := RegisterApp;
end;

function GetPythonDir(Default: String): String;
begin
	result := PythonPath;
end;

function InitializeSetup(): Boolean;
var
	numAG, i : Integer;
	mbret: Integer;
	agKey : String;
begin

	AGVersions := RegKeyNamesArray(HKLM, 'Software\Access Grid Toolkit');

	numAG := GetArrayLength(AGVersions);

	// Verify that the AG softwareis in fact installed.
	if numAG = 0 then begin
		MsgBox('No AG installation was found. The installer will not be able ' + #13 + 'to register this application with the venue client.', mbError, MB_OK);
		RegisterApp := false;
	end else begin

		AGVersion := AGVersions[numAG - 1];


		// Handle the case where we might have more than one version of
		// the AG software installed; pick the last one in the registry.
		if numAG > 1 then begin
			MsgBox('Multiple versions of the AG software were detected ' + #13 + 'We will use version ' + AGVersion + '.', mbInformation, MB_OK);
		end;

		// Determine the Python installation path that this AG installation uses.

		agKey := 'Software\Access Grid Toolkit\' + AGVersion;
		RegQueryStringValue(HKLM, agKey, 'InstallPath', AGInstallPath);

		if not RegQueryStringValue(HKLM, agKey, 'PythonInstallPath', PythonPath) then begin
			// Registry key was not set. This is probably a pre-2.1.3 AG installation.
			// Pick the defaults that that installer used:
			// {reg:HKLM\Software\Python\PythonCore\2.2\InstallPath,|C:\Python22}\pythonw.exe
			if not RegQueryStringValue(HKLM, 'Software\Python\PythonCore\2.2\InstallPath', '', PythonPath) then begin
				PythonPath := 'C:\Python22';
			end;
		end;

		RegisterApp := true;
	end;

	{ Check for the existence of Windows Media Player 9 }
	{ Do this by looking for a registration of the IWMPPlayer4 interface GUID }

	Result := true;

	if not RegKeyExists(HKEY_CLASSES_ROOT, 'Interface\{6C497D62-8919-413C-82DB-E935FB3EC584}') then begin
		mbret := MsgBox('You do not appear to have Windows Media Player version 9 installed.' + #13 +
				'This application will not work until that version (or a later version) is installed.' + #13 +
				'It can be downloaded from http://www.microsoft.com/windowsmedia/.' + #13+ #13 +
				'Continue with installation?',
				mbInformation, MB_YESNO);
		if mbret = IDYES then begin
			Result := true;
		end else begin
			Result := false;
		end;
	end;

end;

// Create the script that will start the client.
procedure GenerateRunScript();
var
	appDir, tmpDir, scriptPath: String;
begin
	appDir := ExpandConstant('{app}');
	tmpDir := ExpandConstant('{tmp}');
	scriptPath := tmpDir + '\sharedrasmol.bat'
	SaveStringToFile(scriptPath, 'cd ' + appDir + #13 + #10, false);
	SaveStringToFile(scriptPath, pythonPath + '\python.exe SharedRasmol.py %1 %2 %3 %4 %5 %6 %7 %8 %9' + #13 + #10, true);
end;

// Create the script that will register the app with the AG client.
procedure GenerateRegisterScript();
var
	appDir, tmpDir, scriptPath, registerCmd: String;
begin
	appDir := ExpandConstant('{app}');
	tmpDir := ExpandConstant('{tmp}');

	scriptPath := tmpDir + '\RegisterApp.bat';
	SaveStringToFile(scriptPath, 'cd ' + appDir + #13 + #10, false);
	if RegisterApp then begin
		registerCmd := PythonPath + '\python.exe "' + AGInstallPath + '\bin\agpm.py"';
	end else begin
		registerCmd := 'agpm.py';
		SaveStringToFile(scriptPath, 'rem' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem Installer did not find AG installation directory. Replace' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem agpm.py below with full path to that program.' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem' + #13 + #10, true);
	end;
	SaveStringToFile(scriptPath, registerCmd + ' -f sharedrasmol.app' + #13 + #10, true);
end;

// Create the script that will unregister the app with the AG client.
// This is just a copy/paste of the above function with a -u added.
//
procedure GenerateUnregisterScript();
var
	appDir, tmpDir, scriptPath, registerCmd: String;
begin
	appDir := ExpandConstant('{app}');
	tmpDir := ExpandConstant('{tmp}');

	scriptPath := tmpDir + '\UnregisterApp.bat';
	SaveStringToFile(scriptPath, 'cd ' + appDir + #13 + #10, false);
	if RegisterApp then begin
		registerCmd := PythonPath + '\python.exe "' + AGInstallPath + '\bin\agpm.py"';
	end else begin
		registerCmd := 'agpm.py';
		SaveStringToFile(scriptPath, 'rem' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem Installer did not find AG installation directory. Replace' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem agpm.py below with full path to that program.' + #13 + #10, true);
		SaveStringToFile(scriptPath, 'rem' + #13 + #10, true);
	end;
	SaveStringToFile(scriptPath, registerCmd + ' -u -f sharedrasmol.app' + #13 + #10, true);
end;

function NextButtonClick(CurPage: Integer): Boolean;
begin
	if CurPage = wpReady then begin
		GenerateRunScript()
		GenerateRegisterScript()
		GenerateUnregisterScript()
	end;
	Result := true;
end;





More information about the ag-dev mailing list