Skip to content

Commit

Permalink
Continued developing QtIFW isInternetConnected detection / handling a…
Browse files Browse the repository at this point in the history
…nd related mechanisms. Notably, added caching and installer value setting / lookups.
  • Loading branch information
BuvinJ committed Jan 13, 2021
1 parent d89ac90 commit 045feb7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
42 changes: 30 additions & 12 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ class _QtIfwScript:
MAINTAIN_MODE_OPT_REMOVE_ALL = "removeall"
MAINTAIN_PASSTHRU_CMD_ARG = "maintpassthru"

IS_NET_CONNECTED_KEY = "isNetConnected"

_IS_CMD_ARGS_TEMP_KEY = "__tmp_sv"
_CMD_ARGS_TEMP_PREFIX = "__tmp_"
_CMD_ARGS = {
Expand Down Expand Up @@ -833,7 +835,7 @@ class _QtIfwScript:
__IS_UNINSTALLER = "installer.isUninstaller()"

__IS_MAINTENANCE_TOOL = 'isMaintenanceTool()'

# an example for use down the line...
__LINUX_GET_DISTRIBUTION = (
"""
Expand Down Expand Up @@ -904,7 +906,7 @@ class _QtIfwScript:
__SCRIPT_FROM_B64_TMPL = '__writeScriptFromBase64( "%s", %s, %s, %s, %s, %s );\n'
__REPLACE_VARS_FILE_TMPL = 'replaceDynamicVarsInFile( %s, %s, %s );\n'

__IS_INTERNET_TMPL = "isInternetConnected()"
__IS_INTERNET_TMPL = "isInternetConnected( %s )"
__IS_PINGABLE_TMPL = "isPingable( %s, %d, %d )"

# Note, there is in fact an installer.killProcess(string absoluteFilePath)
Expand Down Expand Up @@ -1399,22 +1401,24 @@ def deleteFile( path, isAutoQuote=True ):
_QtIfwScript._autoQuote( path, isAutoQuote ),)

@staticmethod
def isInternetConnected(): return _QtIfwScript.__IS_INTERNET_TMPL
def isInternetConnected( isRefresh=False ):
return _QtIfwScript.__IS_INTERNET_TMPL % (
_QtIfwScript.toBool( isRefresh ), )

@staticmethod
def ifInternetConnected( isNegated=False, isMultiLine=False ):
def ifInternetConnected( isRefresh=False, isNegated=False, isMultiLine=False ):
return 'if( %s%s )%s\n%s' % ( "!" if isNegated else "",
_QtIfwScript.isInternetConnected(),
_QtIfwScript.isInternetConnected( isRefresh ),
("{" if isMultiLine else ""), (2*_QtIfwScript.TAB) )

@staticmethod
def isPingable( uri, pings=5, totalMaxSecs=20, isAutoQuote=True ):
def isPingable( uri, pings=3, totalMaxSecs=12, isAutoQuote=True ):
return _QtIfwScript.__IS_PINGABLE_TMPL % (
_QtIfwScript._autoQuote( uri, isAutoQuote ),
pings, totalMaxSecs )

@staticmethod
def ifPingable( uri, pings=5, totalMaxSecs=20, isAutoQuote=True,
def ifPingable( uri, pings=3, totalMaxSecs=12, isAutoQuote=True,
isNegated=False, isMultiLine=False ):
return 'if( %s%s )%s\n%s' % ( "!" if isNegated else "",
_QtIfwScript.isPingable( uri, pings, totalMaxSecs, isAutoQuote ),
Expand Down Expand Up @@ -2333,14 +2337,24 @@ def _genLib( self ):
) +
EBLK + NEW +
# TODO: Test in NIX/MAC
'function isInternetConnected() ' + SBLK +
TAB + 'return isPingable( "www.google.com", 3, 9 )' + END +
'function isInternetConnected( isRefresh ) ' + SBLK +
TAB + 'var isNet = installer.value( "' +
_QtIfwScript.IS_NET_CONNECTED_KEY + '", "" )' + END +
TAB + 'if( isRefresh || isNet === "" ) ' + SBLK +
(2*TAB) + 'isNet = "" + isPingable( "www.google.com", 1, 5 )' + END +
(2*TAB) + 'installer.setValue( "' +
_QtIfwScript.IS_NET_CONNECTED_KEY + '", isNet )' + END +
(2*TAB) + _QtIfwScript.log( 'isNet ? "connected to the internet" : ' +
'"NOT connected to the internet"',
isAutoQuote=False ) +
TAB + EBLK +
TAB + 'return isNet==="true";' + END +
EBLK + NEW +
# TODO: Test in NIX/MAC
'function isPingable( uri, pings, totalMaxSecs ) ' + SBLK +
TAB + 'if( uri==null ) return false' + END +
TAB + 'if( pings==null ) pings=5' + END +
TAB + 'if( totalMaxSecs==null ) totalMaxSecs=20' + END +
TAB + 'if( pings==null ) pings=3' + END +
TAB + 'if( totalMaxSecs==null ) totalMaxSecs=12' + END +
TAB + _QtIfwScript.log( '"Pinging: " + uri + " ..."', isAutoQuote=False ) +
TAB + 'var successOutput = "success"' + END +
TAB + 'var pingCmd = "' +
Expand All @@ -2362,7 +2376,9 @@ def _genLib( self ):
(2*TAB) + 'output = cmdOutLns[1].trim()' + END + EBLK +
TAB + CATCH + 'output = null;' + EBLK +
TAB + 'var isSuccess = output==successOutput' + END +
TAB + _QtIfwScript.log( '"Response received: " + isSuccess', isAutoQuote=False ) +
TAB + _QtIfwScript.log( 'isSuccess ? "...response received" : ' +
'"... NO response received"',
isAutoQuote=False ) +
TAB + 'return isSuccess' + END +
EBLK + NEW
)
Expand Down Expand Up @@ -3590,6 +3606,8 @@ def __genControllerConstructorBody( self ):
TAB + 'installer.setValue( "__isMaintenance", "" )' + END +
TAB + 'installer.setValue( "__lockFilePath", "" )' + END +
TAB + 'installer.setValue( "__watchDogPath", "" )' + END +
TAB + 'installer.setValue( "' +
_QtIfwScript.IS_NET_CONNECTED_KEY + '", "" )' + END +
TAB + 'installer.setValue( ' +
('"%s"' % (_REMOVE_TARGET_KEY,) ) + ', "" )' + END +
TAB + ('if( getEnv("%s")=="true" )' % (_KEEP_TEMP_SWITCH,)) + NEW +
Expand Down
14 changes: 7 additions & 7 deletions docs/LowLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ Static Constants :
MAINTAIN_MODE_OPT_ADD_REMOVE
MAINTAIN_MODE_OPT_UPDATE
MAINTAIN_MODE_OPT_REMOVE_ALL

OK
YES
NO
Expand Down Expand Up @@ -585,11 +585,11 @@ Static Functions:
writeFile( path, content ) <path can include native env vars>
deleteFile( path ) <path can include native env vars>

isInternetConnected()
ifInternetConnected( isNegated=False, isMultiLine=False )
isInternetConnected( isRefresh=False )
ifInternetConnected( isRefresh=False, isNegated=False, isMultiLine=False )
isPingable( uri, pings=5, totalMaxSecs=20, isAutoQuote=True )
ifPingable( uri, pings=5, totalMaxSecs=20, isAutoQuote=True,
isPingable( uri, pings=3, totalMaxSecs=12, isAutoQuote=True )
ifPingable( uri, pings=3, totalMaxSecs=12, isAutoQuote=True,
isNegated=False, isMultiLine=False )
killAll( exeName, isAutoQuote=True )
Expand Down Expand Up @@ -793,8 +793,8 @@ following add-on **QT SCRIPT** functions:
writeFile( path, content ) <path can include native env vars>
deleteFile( path ) <path can include native env vars>

isInternetConnected()
isPingable( uri, pings=5, totalMaxSecs=20 )
isInternetConnected( isRefresh=False )
isPingable( uri, pings=3, totalMaxSecs=12 )

resolveDynamicVars( s, varNames ) <returns string>
replaceDynamicVarsInFile( path, varNames, isDoubleBackslash )
Expand Down
21 changes: 17 additions & 4 deletions examples/hello_dynamic_finish/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def customizeReadyForInstallPage( cfg, tkPkg, cliPkg ):
QtIfwControlScript.setBoolValue( IS_TK_APP_INSTALLED_KEY,
QtIfwControlScript.isComponentSelected( tkPkg ) ) +
QtIfwControlScript.setBoolValue( IS_CLI_APP_INSTALLED_KEY,
QtIfwControlScript.isComponentSelected( cliPkg ) )
QtIfwControlScript.isComponentSelected( cliPkg ) )
)

def customizeFinishedPage( cfg, tkPkg, cliPkg ):
Expand Down Expand Up @@ -190,6 +190,9 @@ def customizeFinishedPage( cfg, tkPkg, cliPkg ):
# message displayed, and to control when the checkboxes are visible
# and checked, etc.
Script = QtIfwControlScript
SBLK = Script.START_BLOCK
EBLK = Script.END_BLOCK
ELSE = Script.ELSE
CONCAT = Script.CONCAT
MSG_LBL = Script.FINISHED_MESSAGE_LABEL
DEFAULT_MSG = Script.DEFAULT_FINISHED_MESSAGE
Expand Down Expand Up @@ -218,8 +221,14 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
varNames=False, isAutoQuote=False ) +
showIfInstalled( runTkCheckbox, tkPkg ) +
showIfInstalled( runCliCheckbox, cliPkg ) +
openOnlineManualViaOsCheckbox.setChecked( True ) +
openOnlineManualViaOsCheckbox.setVisible( True ) +
Script.ifInternetConnected( isMultiLine=True ) +
openOnlineManualViaOsCheckbox.enable( True ) +
openOnlineManualViaOsCheckbox.setChecked( True ) +
EBLK + ELSE + SBLK +
openOnlineManualViaOsCheckbox.enable( False ) +
openOnlineManualViaOsCheckbox.setChecked( False ) +
EBLK +
openOnlineManualViaOsCheckbox.setVisible( True ) +
showIfInstalled( openLicViaOsCheckbox, cliPkg ) +
showIfInstalled( openLicViaProgCheckbox, cliPkg,
isChecked=False ) +
Expand Down Expand Up @@ -263,7 +272,11 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
openPyPiPageViaOsExec = QtIfwOnFinishedDetachedExec(
"openPyPiPageViaOs", QtIfwOnFinishedDetachedExec.ON_UNINSTALL,
openViaOsPath="https://pypi.org/project/distbuilder/",
ifCondition=Script.lookupBoolValue( IS_TK_APP_INSTALLED_KEY ) )
ifCondition=Script.andList([
Script.isInternetConnected()
, Script.lookupBoolValue( IS_TK_APP_INSTALLED_KEY )
])
)

cfg.controlScript.onFinishedDetachedExecutions = [
createExampleFileExec
Expand Down

0 comments on commit 045feb7

Please sign in to comment.