Skip to content

Commit

Permalink
Added RunProgram conveniences to QtIfwExternalOp. Patched glitch in m…
Browse files Browse the repository at this point in the history
…ixed script types across install vs uninstall of QtIfwExternalOp. Added debugging feature for scripts in silent installer (i.e. _keeptemp env var, vs the "secret" argument of the same name for the regular installer).
  • Loading branch information
BuvinJ committed Nov 20, 2020
1 parent f12193f commit 7c8fe59
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
54 changes: 44 additions & 10 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,9 @@ def __genControllerConstructorBody( self ):
TAB + 'installer.setValue( "__lockFilePath", "" )' + END +
TAB + 'installer.setValue( "__watchDogPath", "" )' + END +
TAB + 'installer.setValue( ' +
('"%s"' % (_REMOVE_TARGET_KEY,) ) + ', "" )' + END +
('"%s"' % (_REMOVE_TARGET_KEY,) ) + ', "" )' + END +
TAB + ('if( getEnv("%s")=="true" )' % (_KEEP_TEMP_SWITCH,)) + NEW +
(2*TAB) + _QtIfwScript.setBoolValue( _KEEP_TEMP_SWITCH, True ) +
TAB + 'clearOutLog()' + END +
TAB + 'clearErrorLog()' + END +
TAB + _QtIfwScript.logValue( _QtIfwScript.AUTO_PILOT_CMD_ARG ) +
Expand Down Expand Up @@ -4119,7 +4121,8 @@ def __addExternalOperations( self ):
task.uninstScript.fileName() )
if task.uninstScript
else task.uninstExePath if task.uninstExePath
else None )
else None )
uninstScriptType=( task.uninstScript.extension if task.uninstScript else None )
if uninstExePath:
if not IS_WINDOWS: uninstExePath = uninstExePath.replace(" ", "\\\\ ")
setArgs += '%sundoPath = "%s"%s' % (TAB,uninstExePath,END)
Expand Down Expand Up @@ -4171,14 +4174,14 @@ def __addExternalOperations( self ):
if not exePath : args+=["shellPath", "shellSwitch"] # dummy install action
args+=['"UNDOEXECUTE"']
if task.uninstRetCodes: args+=["undoRetCodes"]
if scriptType=="vbs":
if uninstScriptType=="vbs":
args+=["vbsInterpreter", "vbsNologo"]
elif scriptType=="ps1":
elif uninstScriptType=="ps1":
args+=["psInterpreter", "psNologo",
"psExecPolicy", "psBypassPolicy",
"psInputFormat", "psInputNone",
"psExecScript"]
elif scriptType=="scpt":
elif uninstScriptType=="scpt":
args+=["osaInterpreter"]
else: args+=["shellPath", "shellSwitch"]
if IS_WINDOWS:
Expand Down Expand Up @@ -4659,6 +4662,13 @@ def RemoveDir( event, dirPath, isElevated=True ): # TODO: Test in NIX/MAC
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.RemoveDirScript( dirPath ),
isElevated=isElevated )

@staticmethod
def RunProgram( event, path, arguments=None, isHidden=False, # TODO: Test in NIX/MAC
isElevated=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.RunProgramScript( path, arguments, isHidden ),
isElevated=isElevated )

@staticmethod
def CreateStartupEntry( pkg=None,
Expand Down Expand Up @@ -4842,27 +4852,51 @@ def RemoveDirScript( dirPath ): # TODO: Test in NIX/MAC
"removeDir" ), script=(
'rd /q /s "{dirPath}"' if IS_WINDOWS else 'rm -r "{dirPath}"' ),
replacements={ "dirPath": dirPath } )


@staticmethod
def RunProgramScript( path, arguments=None, isHidden=False,
replacements=None ):
if arguments is None: arguments =[]
if isHidden:
if IS_WINDOWS :
argList =( (" -ArgumentList " +
",".join( ['"%s"' % (a,) for a in arguments]) )
if len(arguments) > 0 else "" )
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"runHiddenProgram" ), extension="ps1", script=(
'Start-Process -FilePath "%s" -Wait -WindowStyle Hidden%s'
% (path, argList) ), replacements=replacements )
else:
# TODO: Fill-in on NIX/MAC
util._onPlatformErr()
else :
tokens = [path] + arguments
return ExecutableScript( "runProgram", script=(
" ".join(['"%s"' % (t,) if " " in t else t for t in tokens])) )

if IS_WINDOWS:
# See
# https://blog.netwrix.com/2018/09/11/how-to-get-edit-create-and-delete-registry-keys-with-powershell/
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-itemproperty?view=powershell-7
@staticmethod
def CreateRegistryEntryScript( key, valueName=None,
value="", valueType="String" ):
value="", valueType="String",
replacements=None ):
valueName = "-Name '%s' " % (valueName,) if valueName else ""
if value is None: value=""
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createRegEntry" ), extension="ps1", script=(
"New-ItemProperty -Path '%s' %s-Value '%s' -PropertyType '%s'"
% (key, valueName, value, valueType) ) )
% (key, valueName, value, valueType) ),
replacements=replacements )

@staticmethod
def RemoveRegistryEntryScript( key, valueName=None ):
def RemoveRegistryEntryScript( key, valueName=None, replacements=None ):
valueName = "-Name '%s' " % (valueName,) if valueName else ""
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"removeRegEntry" ), extension="ps1", script=(
"Remove-ItemProperty -Path '%s' %s" % (key, valueName) ) )
"Remove-ItemProperty -Path '%s' %s" % (key, valueName) ),
replacements=replacements )

@staticmethod
def Script2ExeScript( srcPath, destPath, isSrcRemoved=False ):
Expand Down
40 changes: 37 additions & 3 deletions docs/ConfigClasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,17 @@ Tools defined this list will be rolled into the installer without explicitly
updating the [QtIfwPackageScript](#qtifwpackagescript) owner of this operation
object.

### QtIfwExternalOp Convenience Methods
### QtIfwExternalOp Builders

#### ON_INSTALL, ON_UNINSTALL, ON_BOTH, AUTO_UNDO

Event constants for convenience methods.

#### QtIfwExternalOp.RunProgram

RunProgram( event, path, arguments=None, isHidden=False,
isElevated=True )

#### QtIfwExternalOp.RemoveFile

RemoveFile( event, filePath, isElevated=True )
Expand All @@ -810,8 +815,37 @@ Event constants for convenience methods.

**WINDOWS ONLY**

RemoveRegistryEntry( event, key, valueName=None )
RemoveRegistryEntry( event, key, valueName=None )

### QtIfwExternalOp Convenience Scripts

#### QtIfwExternalOp.RunProgramScript

RunProgramScript( path, arguments=None, isHidden=False,
replacements=None )

#### QtIfwExternalOp.RemoveFileScript( filePath )

RemoveFileScript( filePath )

#### QtIfwExternalOp.RemoveDirScript( dirPath )

RemoveDirScript( dirPath )

### QtIfwExternalOp.CreateRegistryEntryScript

**WINDOWS ONLY**

CreateRegistryEntryScript( key, valueName=None,
value="", valueType="String",
replacements=None )
### QtIfwExternalOp.RemoveRegistryEntryScript

**WINDOWS ONLY**

RemoveRegistryEntryScript( key, valueName=None, replacements=None )
#### QtIfwExternalOp.CreateExeFromScript

**WINDOWS ONLY**
Expand Down
7 changes: 4 additions & 3 deletions docs/HighLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,10 @@ Attributes & default values:
isDesktopTarget = False
isHomeDirTarget = False

isInstallTest = False
isAutoInstallTest = False
isVerboseInstallTest = True
isInstallTest = False
isAutoInstallTest = False
isVerboseInstallTest = True
isScriptDebugInstallTest = False

"Virtual" configuration functions to override:
(Note the order shown is that in which these functions are invoked)
Expand Down
10 changes: 10 additions & 0 deletions docs/LowLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ installation like a [Silent Installer](#silent-installers), and is in fact at th
of how that works. Unlike a silent installer, GUI suppression is involved, however,
and some of the extended features are not available e.g. error return codes.

**_keeptemp=[true/false]**: DEBUGGING feature: Enable to leave scripts in a temp
directory, post any dynamic modifications, allowing them to scrutinized /
executed directly. This may also be enabled by setting an environmental variable
as `_keeptemp=true`.

### Silent Installers

"Silent installation" is the process of running a installer without any interactive prompts
Expand Down Expand Up @@ -335,6 +340,11 @@ opt to allow a reboot by including this switch.

**-d / --debug**: Enable debugging output.

**_keeptemp=true**: DEBUGGING feature: Leave scripts in a temp
directory, post any dynamic modifications, allowing them to scrutinized /
executed directly. Enabled by setting an **environmental variable**
as `_keeptemp=true`.

### Installer Variables

The following constants have been provided, which correspond to dynamic variables
Expand Down

0 comments on commit 7c8fe59

Please sign in to comment.