Skip to content

Commit

Permalink
Add assertInternetConnected() functions to installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuvinJ committed Jan 13, 2021
1 parent 045feb7 commit 5813548
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 16 additions & 4 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,9 @@ 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( %s )"
__IS_PINGABLE_TMPL = "isPingable( %s, %d, %d )"
__ASSERT_INTERNET_TMPL = "assertInternetConnected( %s, %s )"
__IS_INTERNET_TMPL = "isInternetConnected( %s )"
__IS_PINGABLE_TMPL = "isPingable( %s, %d, %d )"

# Note, there is in fact an installer.killProcess(string absoluteFilePath)
# this custom kill takes a process name, with no specific path
Expand Down Expand Up @@ -1400,6 +1401,12 @@ def deleteFile( path, isAutoQuote=True ):
return _QtIfwScript.__DELETE_FILE_TMPL % (
_QtIfwScript._autoQuote( path, isAutoQuote ),)

@staticmethod
def assertInternetConnected( isRefresh=False, errMsg=None ):
return _QtIfwScript.__ASSERT_INTERNET_TMPL % (
_QtIfwScript.toBool( isRefresh ),
_QtIfwScript.toNull( errMsg ) )

@staticmethod
def isInternetConnected( isRefresh=False ):
return _QtIfwScript.__IS_INTERNET_TMPL % (
Expand Down Expand Up @@ -2335,7 +2342,12 @@ def _genLib( self ):
(TAB + '// The hidden feature is not yet supported on macOS!' + NEW +
TAB + 'execute( binPath, args )' + END )
) +
EBLK + NEW +
EBLK + NEW +
# TODO: Test in NIX/MAC
'function assertInternetConnected( isRefresh, errMsg ) ' + SBLK +
TAB + 'if( !isInternetConnected( isRefresh ) )' + NEW +
(2*TAB) + 'quit( errMsg ? errMsg : "An internet connection is required!" )' + END +
EBLK + NEW +
# TODO: Test in NIX/MAC
'function isInternetConnected( isRefresh ) ' + SBLK +
TAB + 'var isNet = installer.value( "' +
Expand All @@ -2344,7 +2356,7 @@ def _genLib( self ):
(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" : ' +
(2*TAB) + _QtIfwScript.log( 'isNet==="true" ? "connected to the internet" : ' +
'"NOT connected to the internet"',
isAutoQuote=False ) +
TAB + EBLK +
Expand Down
6 changes: 4 additions & 2 deletions docs/LowLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ Static Functions:
writeFile( path, content ) <path can include native env vars>
deleteFile( path ) <path can include native env vars>

assertInternetConnected( isRefresh=False, errMsg=None )
isInternetConnected( isRefresh=False )
ifInternetConnected( isRefresh=False, isNegated=False, isMultiLine=False )
Expand Down Expand Up @@ -793,8 +794,9 @@ following add-on **QT SCRIPT** functions:
writeFile( path, content ) <path can include native env vars>
deleteFile( path ) <path can include native env vars>

isInternetConnected( isRefresh=False )
isPingable( uri, pings=3, totalMaxSecs=12 )
assertInternetConnected( isRefresh[=false], errMsg[=null] )
isInternetConnected( isRefresh[=false] )
isPingable( uri, pings[=3], totalMaxSecs[=12] )

resolveDynamicVars( s, varNames ) <returns string>
replaceDynamicVarsInFile( path, varNames, isDoubleBackslash )
Expand Down

0 comments on commit 5813548

Please sign in to comment.