Skip to content

Commit

Permalink
Refactored some new QtIfwExternalOp functions and added QtIfwExternal…
Browse files Browse the repository at this point in the history
…Op.opDataPath() vs qtIfwOpDataPath() for use with embedded installer scripts vs QtScript.
  • Loading branch information
BuvinJ committed Jan 7, 2021
1 parent 7e0335a commit 234496c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 47 deletions.
2 changes: 1 addition & 1 deletion distbuilder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
, nestQtIfwPackage \
, joinPathQtIfw \
, qtIfwDynamicValue \
, qtIfwTempDataFilePath \
, qtIfwOpDataPath \
, QT_IFW_VERBOSE_SWITCH \
, QT_IFW_DYNAMIC_VARS \
, QT_IFW_TARGET_DIR \
Expand Down
48 changes: 34 additions & 14 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def joinPathQtIfw( head, tail ): return "%s/%s" % ( head, tail )

def qtIfwDynamicValue( name ): return "@%s@" % (name,)

def qtIfwTempDataFilePath( rootFileName ):
return joinExt( joinPath( QT_IFW_SCRIPTS_DIR, rootFileName ),
def qtIfwOpDataPath( rootFileName ):
return joinExt( joinPathQtIfw( QT_IFW_SCRIPTS_DIR, rootFileName ),
_QT_IFW_TEMP_DATA_EXT )

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -5129,17 +5129,37 @@ class QtIfwExternalOp:
__SCRIPT_ROOT_NAME_TMPLT = "%s_%d"

__NOT_FOUND_EXIT_CODE = 100

__WIN_PATH_SEP = "\\"
__NIX_PATH_SEP = "/"
__NATIVE_PATH_SEP = __WIN_PATH_SEP if IS_WINDOWS else __NIX_PATH_SEP
__FOREIGN_PATH_SEP = __NIX_PATH_SEP if IS_WINDOWS else __WIN_PATH_SEP

@staticmethod
def opDataPath( rootFileName, isNative=True,
quotes=None, isDoubleBackslash=False ):
path = joinExt( joinPath( QT_IFW_SCRIPTS_DIR, rootFileName ),
_QT_IFW_TEMP_DATA_EXT )
if isNative:
path = path.replace( QtIfwExternalOp.__FOREIGN_PATH_SEP,
QtIfwExternalOp.__NATIVE_PATH_SEP )
if IS_WINDOWS and isDoubleBackslash:
path = path.replace( QtIfwExternalOp.__WIN_PATH_SEP,
QtIfwExternalOp.__WIN_PATH_SEP+
QtIfwExternalOp.__WIN_PATH_SEP )
if quotes: path = "%s%s%s" % (quotes, path, quotes)
return path

@staticmethod
def CreateTempDataFile( event, fileName, isElevated=True ):
def CreateOpFlagFile( event, fileName, isElevated=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.WriteTempDataFileScript( fileName ),
script=QtIfwExternalOp.WriteOpDataFileScript( fileName ),
isElevated=isElevated )

@staticmethod
def WriteTempDataFile( event, fileName, data, isElevated=True ):
def WriteOpDataFile( event, fileName, data, isElevated=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.WriteTempDataFileScript( fileName, data ),
script=QtIfwExternalOp.WriteOpDataFileScript( fileName, data ),
isElevated=isElevated )

@staticmethod
Expand Down Expand Up @@ -5391,16 +5411,16 @@ def __genScriptOp( event, script, uninstScript=None,

# TODO: Auto handle escape sequences?
@staticmethod
def WriteTempDataFileScript( fileName, data=None ): # TODO: Test in NIX/MAC
filePath = qtIfwTempDataFilePath( fileName )
def WriteOpDataFileScript( fileName, data=None ): # TODO: Test in NIX/MAC
filePath = QtIfwExternalOp.opDataPath( fileName )
if data is None:
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"touchTempDataFile" ), script=(
"touchOpDataFile" ), script=(
'echo. > "%s"' % (filePath,) if IS_WINDOWS else
'touch "%s"' % (filePath,) ) )
else:
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"writeTempDataFile" ), script=(
"writeOpDataFile" ), script=(
'echo %s > "%s"' % (data, filePath,) if IS_WINDOWS else
'echo "%s" > "%s"' % (data, filePath,) ) )

Expand Down Expand Up @@ -5480,7 +5500,7 @@ def __batExitIfFileMissing( fileName, isNegated=False, errorCode=0 ):
'if {negate}exist "{filePath}" exit /b {errorCode}'
]), replacements={
'negate' : ('' if isNegated else 'not ')
, 'filePath' : qtIfwTempDataFilePath( fileName )
, 'filePath' : QtIfwExternalOp.opDataPath( fileName )
, 'errorCode': errorCode
}) )

Expand All @@ -5492,7 +5512,7 @@ def __psExitIfFileMissing( fileName, isNegated=False, errorCode=0 ):
, '}'
]), replacements={
'negate' : ('' if isNegated else '! ')
, 'filePath' : qtIfwTempDataFilePath( fileName )
, 'filePath' : QtIfwExternalOp.opDataPath( fileName )
, 'errorCode': errorCode
}) )

Expand Down Expand Up @@ -5577,7 +5597,7 @@ def CreateWindowsAppFoundTempFileScript( appName, fileName,
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createAppFoundFile" ), extension="ps1",
script=psScriptTemplate, replacements={
"tempFilePath": qtIfwTempDataFilePath( fileName )
"tempFilePath": QtIfwExternalOp.opDataPath( fileName )
})

@staticmethod
Expand Down Expand Up @@ -5926,7 +5946,7 @@ def __shExitIfFileMissing( fileName, isNegated=False, errorCode=0 ):
'[ {negate}-f "{filePath}" ] && exit {errorCode}'
]), replacements={
'negate' : ('' if isNegated else '! ')
, 'filePath' : qtIfwTempDataFilePath( fileName )
, 'filePath' : QtIfwExternalOp.opDataPath( fileName )
, 'errorCode': errorCode
}) )

Expand Down
33 changes: 26 additions & 7 deletions docs/ConfigClasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,26 @@ object.

#### ON_INSTALL, ON_UNINSTALL, ON_BOTH, AUTO_UNDO

Event constants for convenience methods.
**Event** constants for convenience methods.

#### opDataPath

opDataPath( rootFileName, isNative=True,
quotes=None, isDoubleBackslash=False )

Dynamically resolve paths to temp data files used by the operations,
or to embed in custom scripts.

**rootFileName**: A simple ("data key") identifier (with no file extension).

**isNative**: By default, paths are returned in a native format, i.e.
with backslashes vs forward slashes as applicable.

**quotes**: Optionally, you may provide quote strings (e.g. `"` or `'`, or some
escaped version of them) to wrap the returned path in such.

**isDoubleBackslash**: Optionally, use this on Windows, to escape backslashes
doubling them up.

#### QtIfwExternalOp.RunProgram

Expand All @@ -799,13 +818,13 @@ Event constants for convenience methods.
On Windows, set `isAutoBitContext=False` if you need to execute a 64 bit
program from the installer's 32 bit context.

#### QtIfwExternalOp.CreateTempDataFile
#### QtIfwExternalOp.CreateOpFlagFile

CreateTempDataFile( event, fileName, isElevated=True )
CreateOpFlagFile( event, fileName, isElevated=True )

#### QtIfwExternalOp.WriteTempDataFile
#### QtIfwExternalOp.WriteOpDataFile

WriteTempDataFile( event, fileName, data, isElevated=True )
WriteOpDataFile( event, fileName, data, isElevated=True )

#### QtIfwExternalOp.RemoveFile

Expand Down Expand Up @@ -917,9 +936,9 @@ program from the installer's 32 bit context.
Note: Elevation is controlled via the operation executing the script
rather embedded within it.

#### QtIfwExternalOp.WriteTempDataFileScript
#### QtIfwExternalOp.WriteOpDataFileScript

WriteTempDataFileScript( fileName, data=None )
WriteOpDataFileScript( fileName, data=None )

**Windows Type**: Batch
**Mac/Linux Type**: ShellScript
Expand Down
28 changes: 13 additions & 15 deletions docs/LowLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -1447,33 +1447,31 @@ is not specified, the path is re resolved relative to `THIS_DIR`

### joinPathQtIfw

Use this to build paths which will be utilized by QtIFW scripts
(directly or indirectly) on a target machine. The paths will be
joined (and used) in a platform agnostic manner.
Use this function to build paths within QtScript building contexts
and to supply arguments for QtIFW operations.
The paths will be joined in a *platform agnostic* manner.

Note, use `joinPath` to build paths in a platform specific manner,
applicable to where a build script will be employing it to *create*
a distribution.
Note, use `joinPath` to build paths in a *platform specific* manner,
resolved at build time.

### qtIfwDynamicValue

qtIfwDynamicValue( name )

Use this function produce the resolution of dynamic substitution variables
at runtime, which are utilized by QtIFW scripts (directly or indirectly)
on a target machine.
Use this function to produce the resolution of dynamic substitution variables
at runtime, which are utilized by QtIFW operations and scripts in all contexts
(directly or indirectly) on a target machine.

These values are often paths to files or directories on the target, or
These values are *often* paths to files or directories on the target, or
embedded resources in the installer, but may in fact be used for strings
containing *any* content, which the installer knows how to resolve.

### qtIfwTempDataFilePath
### qtIfwOpDataPath

qtIfwTempDataFilePath( rootFileName )
qtIfwOpDataPath( rootFileName )

Use this function produce the resolution of dynamic temp paths
at runtime, which are utilized by QtIFW scripts (directly or indirectly)
on a target machine.
Use this function, within QtScript building contexts, to produce the resolution
of dynamic temp paths at runtime, which are utilized by installer operations.

### isParentDir

Expand Down
32 changes: 22 additions & 10 deletions examples/hello_qtifw_ops/cascading_scripts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from distbuilder import PyToBinInstallerProcess, ConfigFactory, \
QtIfwExternalOp, QtIfwPackageScript, ExecutableScript, \
joinPath, qtIfwDynamicValue, qtIfwTempDataFilePath, \
QT_IFW_DESKTOP_DIR, QT_IFW_HOME_DIR, \
IS_WINDOWS, QT_IFW_APPS_X86_DIR
QtIfwControlScript, QtIfwPackageScript, \
QtIfwExternalOp, ExecutableScript, \
qtIfwOpDataPath, qtIfwDynamicValue, \
IS_WINDOWS, QT_IFW_DESKTOP_DIR, QT_IFW_HOME_DIR, QT_IFW_APPS_X86_DIR, \
joinPath

ON_INSTALL = QtIfwExternalOp.ON_INSTALL
opDataPath = QtIfwExternalOp.opDataPath

if IS_WINDOWS:
APP_FOUND_FILENAME = "AppFound"

f = configFactory = ConfigFactory()
f.productName = "Hello Cascading Scripts Example"
Expand All @@ -25,10 +30,18 @@ def customizeFinishedPage( cfg ):
# Disable the run program check box by default, for this example.
cfg.controlScript.isRunProgChecked = False

if IS_WINDOWS:
Script = QtIfwControlScript
cfg.controlScript.finishedPageOnInstall =(
Script.log( '"App found: " + ' + Script.pathExists(
qtIfwOpDataPath( APP_FOUND_FILENAME ) ),
isAutoQuote=False )
)

# A boolean state may be represented via a file's existence,
# created (or not) during an installer operation...
def setBoolCascadeOp( fileName ):
return QtIfwExternalOp.CreateTempDataFile( ON_INSTALL, fileName )
return QtIfwExternalOp.CreateOpFlagFile( ON_INSTALL, fileName )

# A boolean state may be evaluated via a file's existence,
# during a subsequent installer operation...
Expand All @@ -42,7 +55,7 @@ def getBoolCascadeOp( fileName, destFilePath ):
, '[ -f "{srcFilePath}" ] && msg="TRUE"'
, 'echo "${msg}" > "{destFilePath}"'
]), replacements={
'srcFilePath' : qtIfwTempDataFilePath( fileName )
'srcFilePath' : opDataPath( fileName )
, 'destFilePath': destFilePath
})
return QtIfwExternalOp( script=createFileScript,
Expand All @@ -57,7 +70,7 @@ def setInstallerVaribale( pkgScript, varName ):

# An installer variable can be written to a data file...
def setVaribaleCascadeOp( fileName, varName ):
return QtIfwExternalOp.WriteTempDataFile( ON_INSTALL, fileName,
return QtIfwExternalOp.WriteOpDataFile( ON_INSTALL, fileName,
qtIfwDynamicValue( varName ) )

# Or a dynamic value may be determined in a script and then written
Expand All @@ -68,7 +81,7 @@ def setTimeCascadeViaScriptOp( fileName ):
] if IS_WINDOWS else [
'echo $(date +"%T") > "{timeFilePath}"'
]), replacements={
'timeFilePath': qtIfwTempDataFilePath( fileName )
'timeFilePath': opDataPath( fileName )
})
return QtIfwExternalOp( script=passTimeScript )

Expand All @@ -82,7 +95,7 @@ def getVaribaleCascadeOp( fileName, destFilePath ):
'msg=$(cat "{srcFilePath}")'
, 'echo "${msg}" > "{destFilePath}"'
]), replacements={
'srcFilePath' : qtIfwTempDataFilePath( fileName )
'srcFilePath' : opDataPath( fileName )
, 'destFilePath': destFilePath
})
return QtIfwExternalOp( script=createFileScript,
Expand Down Expand Up @@ -135,7 +148,6 @@ def launchAppIfFound( event, exePath, appFoundFileName ):
COMPANY_NAME = "Some Company"
EXE_NAME = "RunConditionsTest.exe"
IS_32BIT_REG = False
APP_FOUND_FILENAME = "ConveniencesAppInstalled"
EXE_PATH = joinPath( QT_IFW_APPS_X86_DIR, COMPANY_NAME, APP_NAME,
EXE_NAME )
# This demos conditionally launching an app on BOTH install and
Expand Down

0 comments on commit 234496c

Please sign in to comment.