Skip to content

Commit

Permalink
Revised QtIFW writeFile function, to so it recursively creates parent…
Browse files Browse the repository at this point in the history
… directories as need be. This notably fixes run conditions for err/out file log paths specify paths that would otherwise fail due to the directories not existing.
  • Loading branch information
BuvinJ committed Dec 21, 2020
1 parent 705abb2 commit 90a4f49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
44 changes: 28 additions & 16 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,14 +1348,10 @@ def pathExists( path, isAutoQuote=True ):
_QtIfwScript._autoQuote( path, isAutoQuote ),)

@staticmethod
def ifPathExists( path, isAutoQuote=True, isMultiLine=False ):
return 'if( %s )%s\n%s' % (
_QtIfwScript.pathExists( path, isAutoQuote ),
("{" if isMultiLine else ""), (2*_QtIfwScript.TAB) )

@staticmethod
def ifNotPathExists( path, isAutoQuote=True, isMultiLine=False ):
return 'if( ! %s )%s\n%s' % (
def ifPathExists( path, isNegated=False,
isAutoQuote=True, isMultiLine=False ):
return 'if( %s%s )%s\n%s' % (
"!" if isNegated else "",
_QtIfwScript.pathExists( path, isAutoQuote ),
("{" if isMultiLine else ""), (2*_QtIfwScript.TAB) )

Expand Down Expand Up @@ -1868,6 +1864,12 @@ def _genLib( self ):
'function getEnv( varName ) ' + SBLK +
TAB + 'return installer.environmentVariable( varName )' + END +
EBLK + NEW +
'function parentDir( path ) ' + SBLK +
TAB + 'var pathParts = Dir.fromNativeSeparator( path ).split("/")' + END +
TAB + 'if( pathParts.length <= 1 ) return null' + END +
TAB + 'return Dir.toNativeSeparator( ' +
'pathParts.slice(0, pathParts.length-1).join("/") )' + END +
EBLK + NEW +
'function fileName( filePath ) ' + SBLK +
TAB + 'var pathParts = Dir.fromNativeSeparator( filePath ).split("/")' + END +
TAB + 'return pathParts[pathParts.length-1]' + END +
Expand Down Expand Up @@ -1928,15 +1930,16 @@ def _genLib( self ):
TAB + 'return retList' + END +
EBLK + NEW +
'function makeDir( path ) ' + SBLK + # TODO: Test in NIX/MAC
TAB + 'if( path==null ) return' + END +
TAB + 'path = resolveNativePath( path )' + END +
TAB + _QtIfwScript.ifPathExists( 'path', isAutoQuote=False ) +
(2*TAB) + 'return path' + END +
TAB + 'var mkDirCmd = "' +
('echo off\\n'
'md \\"" + path + "\\"\\n'
'md \\"" + path + "\\"\\n' # implicitly recursive
'echo " + path + "\\n'
if IS_WINDOWS else
'mkdir -p \\"" + path + "\\"; '
'mkdir -p \\"" + path + "\\"; ' # -p = recursive
'echo \\"" + path + "\\"' ) + '"' + END +
TAB + 'var result = installer.execute( ' +
('"cmd.exe", ["/k"], mkDirCmd' if IS_WINDOWS else
Expand All @@ -1953,9 +1956,10 @@ def _genLib( self ):
TAB + _QtIfwScript.log( '"made dir: " + path', isAutoQuote=False ) +
TAB + 'return path' + END +
EBLK + NEW +
'function removeDir( path ) ' + SBLK + # TODO: Test in NIX/MAC
'function removeDir( path ) ' + SBLK + # TODO: Test in NIX/MAC
TAB + 'if( path==null ) return' + END +
TAB + 'path = resolveNativePath( path )' + END +
TAB + _QtIfwScript.ifNotPathExists( 'path', isAutoQuote=False ) +
TAB + _QtIfwScript.ifPathExists( 'path', isNegated=True, isAutoQuote=False ) +
(2*TAB) + 'return path' + END +
TAB + 'var rmDirCmd = "' +
('echo off\\n'
Expand Down Expand Up @@ -2072,8 +2076,12 @@ def _genLib( self ):
TAB + 'var escaped = echo' + END +
TAB + 'return " " + escaped' + END +
EBLK + NEW +
'function writeFile( path, content ) ' + SBLK +
TAB + 'path = resolveNativePath( path )' + END +
'function writeFile( path, content ) ' + SBLK +
TAB + 'if( path==null ) return' + END +
TAB + 'path = resolveNativePath( path )' + END +
TAB + 'var dirPath = parentDir( path )' + END +
TAB + _QtIfwScript.ifPathExists( 'dirPath', isNegated=True, isAutoQuote=False ) +
(2*TAB) + _QtIfwScript.makeDir( 'dirPath', isAutoQuote=False ) +
TAB + 'var lines = content.split(\"\\n\")' + END +
TAB + 'var redirect = " >"' + END +
TAB + 'var writeCmd = ""' + END +
Expand Down Expand Up @@ -2101,7 +2109,10 @@ def _genLib( self ):
TAB + 'return path' + END +
EBLK + NEW +
'function deleteFile( path ) ' + SBLK +
TAB + 'path = resolveNativePath( path )' + END +
TAB + 'if( path==null ) return' + END +
TAB + 'path = resolveNativePath( path )' + END +
TAB + _QtIfwScript.ifPathExists( 'path', isNegated=True, isAutoQuote=False ) +
'return' + END +
TAB + 'var deleteCmd = "' +
('echo off && del \\"" + path + "\\" /q\\necho " + path + "\\n"'
if IS_WINDOWS else
Expand Down Expand Up @@ -3442,7 +3453,8 @@ def __genControllerConstructorBody( self ):
TAB + _QtIfwScript.ifDryRun() + _QtIfwScript.setBoolValue(
_QtIfwScript.AUTO_PILOT_CMD_ARG, True ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.AUTO_PILOT_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.DRYRUN_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.DRYRUN_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.MAINTAIN_MODE_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.TARGET_EXISTS_OPT_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.TARGET_DIR_CMD_ARG ) +
TAB + _QtIfwScript.logValue( _QtIfwScript.START_MENU_DIR_CMD_ARG ) +
Expand Down
8 changes: 4 additions & 4 deletions docs/LowLevel.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,9 @@ Static Functions:
getEnv( varName, isAutoQuote=True )

pathExists( path, isAutoQuote=True )
ifPathExists( path, isAutoQuote=True, isMultiLine=False )
ifNotPathExists( path, isAutoQuote=True, isMultiLine=False )
ifPathExists( path, isNegated=False, sAutoQuote=True, isMultiLine=False )

makeDir( path ) <path can include native env vars>
makeDir( path ) <recursive, path can include native env vars>
removeDir( path ) <path can include native env vars>
writeFile( path, content ) <path can include native env vars>
Expand Down Expand Up @@ -762,12 +761,13 @@ following add-on **QT SCRIPT** functions:

getEnv( varName )

parentDir( path ) <null if no parent, e.g. path is root>
fileName( filePath )
rootFileName( filePath )

dirList( path, isSortedByTime ) <path can include native env vars, and wild cards>
makeDir( path )
makeDir( path ) <recursive>
removeDir( path )
writeFile( path, content ) <path can include native env vars>
Expand Down

0 comments on commit 90a4f49

Please sign in to comment.