Skip to content

Commit

Permalink
Change to use splitlines() for Windows (TriBITS #98)
Browse files Browse the repository at this point in the history
Changed from split("\n") to splitlines() to deal with newlines in MS Windows.

Jordan reports that this fixes a problem on MS Windows with the
clone_extra_repos.py script.  This also seems to be supported with Python
2.6.6 (which is what is running on the current machine).  This means that the
min version of Python required for TriBITS python support is now Python 2.6.6.

It actually took a good bit of work to adjust everything for this change as
split("\n") will always return an empty element at the end while splitlines()
will not.  It was tricky updating all of the code and tests due this simple
change.
  • Loading branch information
Roscoe A. Bartlett committed Nov 25, 2015
1 parent 3605bfe commit 2ce3206
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/ci_support/CheckinTest_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ def test_dirty_commit_1(self):
"\nBuild/Test Cases Summary\n"
#print "\nrawLogOutput:\n----------------\n", rawLogOutput, "----------------\n"
(cleanCommitMsg, numBlankLines) = getLastCommitMessageStrFromRawCommitLogStr(rawLogOutput)
#print "\ncleanCommitMsg:\n----------------\n", cleanCommitMsg, "-----------------\n"
self.assertEqual(numBlankLines, 1)
self.assertEqual(cleanCommitMsg, cleanCommitMsg_expected)
#print "\ncleanCommitMsg:\n----------------\n", cleanCommitMsg, "-----------------\n"


def test_dirty_commit_2(self):
Expand Down
2 changes: 1 addition & 1 deletion test/core/TestingFunctionMacro_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ FUNCTION(UNITTEST_TRIBITS_FIND_PYTHON_INTERP)
SET(PYTHON_EXECUTABLE_UNITTEST_VAL /dummy)
TRIBITS_FIND_PYTHON_INTERP()
UNITTEST_COMPARE_CONST(MESSAGE_WRAPPER_INPUT
"FATAL_ERROR;Error,; PythonInterp_FIND_VERSION=2.3 < 2.4; is now allowed!;-- ;PYTHON_EXECUTABLE='/dummy'")
"FATAL_ERROR;Error,; PythonInterp_FIND_VERSION=2.3 < 2.6; is now allowed!;-- ;PYTHON_EXECUTABLE='/dummy'")

ENDFUNCTION()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ Good documenation


something else

9 changes: 4 additions & 5 deletions test/python_utils/extract_rst_cmake_doc_UnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_withparenth_open(self):
# @MACRO: SOME_MACRO_NAME1()
#
# Good documenation
#
#
MACRO(SOME_MACRO_NAME1 ...)
some other stuff
...
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_withparenth_open(self):
# SOME_FUNC_NAME2(blah
# goat
# )
#
#
FUNCTION(SOME_FUNC_NAME2 ...)
some other stuff
...
Expand Down Expand Up @@ -423,7 +423,6 @@ def test_too_many_spaces_before_block_identifier(self):
something else
"""


Expand Down Expand Up @@ -462,8 +461,8 @@ def test_too_many_spaces_before_block_identifier(self):


def lineByLineCompareAssert(testObj, text, textExpected):
textArray = text.split("\n")
textExpectedArray = textExpected.split("\n")
textArray = text.splitlines()
textExpectedArray = textExpected.splitlines()

for i in range(0,min(len(textArray), len(textExpectedArray))):
testObj.assertEqual(textArray[i], textExpectedArray[i],
Expand Down
14 changes: 8 additions & 6 deletions tribits/ci_support/CheckinTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def setupAndAssertEgGitVersions(inOptions):
setattr(inOptions, "eg", "eg")

egVersionOuput = getCmndOutput(inOptions.eg+" --version", True, False)
egVersionsList = egVersionOuput.split('\n')
egVersionsList = egVersionOuput.splitlines()

if inOptions.enableEgGitVersionCheck:
assertEgGitVersionHelper(egVersionsList[0], "eg version "+g_officialEgVersion)
Expand Down Expand Up @@ -710,7 +710,7 @@ def readAndAppendCMakeOptions(

def getCurrentBranchName(inOptions, baseTestDir):
branchesStr = getCmndOutput(inOptions.eg+" branch", workingDir=inOptions.srcDir)
for branchName in branchesStr.split('\n'):
for branchName in branchesStr.splitlines():
#print "branchName =", branchName
if branchName[0] == '*':
currentBranch = branchName.split(' ')[1]
Expand Down Expand Up @@ -754,7 +754,7 @@ def extractPackageEnablesFromChangeStatus(changedFileDiffOutputStr, inOptions_in
projectDependenciesLocal = getDefaultProjectDependenices()

modifiedFilesList = extractFilesListMatchingPattern(
changedFileDiffOutputStr.split('\n'), reModifiedFiles )
changedFileDiffOutputStr.splitlines(), reModifiedFiles )

for modifiedFileFullPath in modifiedFilesList:

Expand Down Expand Up @@ -1710,7 +1710,7 @@ def getLastCommitMessageStrFromRawCommitLogStr(rawLogOutput):
numBlankLines = 0
lastNumBlankLines = 0
foundStatusHeader = False
for line in rawLogOutput.split('\n'):
for line in rawLogOutput.splitlines():
#print "\nline = '"+line+"'\n"
if pastHeader:
origLogStrList.append(line)
Expand All @@ -1734,10 +1734,12 @@ def getLastCommitMessageStrFromRawCommitLogStr(rawLogOutput):
" build/test summary block! This is a corrupted commit message. Please" \
" use 'git commit --amend' and manually remove the 'Build/test Cases Summary' block.")
origLogStrList = origLogStrList[0:-lastNumBlankLines]
lastCommitMessageStr = '\n'.join(origLogStrList)
else:
lastCommitMessageStr = ('\n'.join(origLogStrList))+'\n'
lastNumBlankLines = -1 # Flag we did not find status header

return ('\n'.join(origLogStrList), lastNumBlankLines)
return (lastCommitMessageStr, lastNumBlankLines)


def getLastCommitMessageStr(inOptions, gitRepo):
Expand Down Expand Up @@ -1801,7 +1803,7 @@ def getLocalCommitsSHA1ListStr(inOptions, gitRepo):

if rawLocalCommitsStr:
return ("Other local commits for this build/test group: "
+ (", ".join(rawLocalCommitsStr.split("\n")))) + "\n"
+ (", ".join(rawLocalCommitsStr.splitlines()))) + "\n"

return ""

Expand Down
4 changes: 2 additions & 2 deletions tribits/ci_support/clone_extra_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def getHeaderOutputAndExtraReposDictList(rawOutputFromCmakefile):
headerOuput = ""
pythonDictListStr = ""
processingPythonDict = False
for line in rawOutputFromCmakefile.split("\n"):
for line in rawOutputFromCmakefile.splitlines():
if line == "*** Extra Repositories Python Dictionary":
processingPythonDict=True
continue
Expand Down Expand Up @@ -304,7 +304,7 @@ def getExtraReposDictListFromCmakefile(projectDir, extraReposFile, withCmake,
# repos.
def parseRawSshGitoliteRootInfoOutput(rawSshGitoliteRootInfoOutput, verbose=False):

rawSshGitoliteRootInfoOutputList = rawSshGitoliteRootInfoOutput.split("\n")
rawSshGitoliteRootInfoOutputList = rawSshGitoliteRootInfoOutput.splitlines()

gitoliteSshHeader = rawSshGitoliteRootInfoOutputList[0]
if verbose:
Expand Down
2 changes: 1 addition & 1 deletion tribits/ci_support/get-tribits-packages-from-files-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
if not options.filesListFile:
raise Exception("Error, the option --files-list-file=FILENAME must be set!")

filesList = readStrFromFile(options.filesListFile).split('\n')
filesList = readStrFromFile(options.filesListFile).splitlines()

trilinosDependencies = getProjectDependenciesFromXmlFile(options.depsXmlFile)

Expand Down
2 changes: 1 addition & 1 deletion tribits/devtools_install/install_devtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def getToolsSelectedArray(toolsSelectedStr, validToolsArray):
#
def substituteStrings(inputStr, subPairArray):
outputStr = ""
inputStrArray = inputStr.split("\n")
inputStrArray = inputStr.splitlines()
if inputStrArray[-1] == "": inputStrArray = inputStrArray[0:-1]
for line in inputStrArray:
#print "line = '"+line+"'"
Expand Down
4 changes: 2 additions & 2 deletions tribits/python_utils/GeneralScriptSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def extractLinesAfterRegex(string_in, regex_in):
reMatch = re.compile(regex_in)
linesExtracted = ""
foundRegex = False
for line in string_in.strip().split("\n"):
for line in string_in.strip().splitlines():
#print "line = '" + line + "'"
if not foundRegex:
matchObj = reMatch.match(line)
Expand Down Expand Up @@ -248,7 +248,7 @@ def clear(self):
self.__allowExtraCmnds = True

def readCommandsFromStr(self, cmndsStr):
lines = cmndsStr.split('\n')
lines = cmndsStr.splitlines()
for line in lines:
#print "line: '"+line+"'"
if line == "":
Expand Down
2 changes: 1 addition & 1 deletion tribits/python_utils/SnapshotDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def getGitRepoUrl(gitDir):
#print "remoteReposListStr =", remoteReposListStr

# Loop through looking for remoteRepoName
for remoteRepo in remoteReposListStr.split("\n"):
for remoteRepo in remoteReposListStr.splitlines():

#print "remoteRepo = '"+remoteRepo+"'"
if remoteRepo == "":
Expand Down
4 changes: 2 additions & 2 deletions tribits/python_utils/extract_rst_cmake_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def extractRstDocBlocksFromText(rawText, rstBlockTypes, fileName, traceExtractio
currentRstBlockBody = ""

line_i = 0
for line in rawText.split("\n"):
for line in rawText.splitlines():
#print "\nline = '"+line+"'"

line_i += 1
Expand Down Expand Up @@ -365,7 +365,7 @@ def replaceWithRstDocBlocksInText(textToReplace, rstBlockTypes, rstDocBlocks, fi

replacedText = ""

textToReplaceLines = textToReplace.split("\n")
textToReplaceLines = textToReplace.splitlines()
numTextToReplaceLines = len(textToReplaceLines)

line_i = 0
Expand Down
14 changes: 9 additions & 5 deletions tribits/python_utils/gitdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,11 @@ def requoteCmndLineArgsIntoArray(inArgs):

# Get a data-structure for a set of repos from a string
def getRepoVersionDictFromRepoVersionFileString(repoVersionFileStr):
repoVersionFileStrList = repoVersionFileStr.split("\n")
repoVersionFileStrList = repoVersionFileStr.splitlines()
repoVersionDict = {}
len_repoVersionFileStrList = len(repoVersionFileStrList)
i = 0
while i < len(repoVersionFileStrList):
while i < len_repoVersionFileStrList:
#print "i = ", i
repoDirLine = repoVersionFileStrList[i]
#print "repoDirLine = '"+repoDirLine+"'"
Expand All @@ -655,7 +656,10 @@ def getRepoVersionDictFromRepoVersionFileString(repoVersionFileStr):
repoVersionDict.update({repoDir : repoSha1})
else:
break
if repoVersionFileStrList[i+2][0:3] == "***":
nextRepoNoSummary_i = i+2
if nextRepoNoSummary_i >= len_repoVersionFileStrList:
break
if repoVersionFileStrList[nextRepoNoSummary_i][0:3] == "***":
# Has no summary line
i = i + 2
else:
Expand Down Expand Up @@ -765,7 +769,7 @@ def getNumCommitsWrtTrackingBranch(options, trackingBranch):
numCommits = 0
summaryLines = summaryLines.strip()
if summaryLines:
for summaryLine in summaryLines.split("\n"):
for summaryLine in summaryLines.splitlines():
#print "summaryLine = '"+summaryLine+"'"
numAuthorCommits = int(summaryLine.strip().split()[0].strip())
#print "numAuthorCommits =", numAuthorCommits
Expand All @@ -785,7 +789,7 @@ def getNumModifiedAndUntracked(options):
if rtnCode == 0:
numModified = 0
numUntracked = 0
for line in rawStatusOutput.split("\n"):
for line in rawStatusOutput.splitlines():
if line.find(" M ") == 0 or line.find("M ") == 0:
numModified += 1
elif line.find(" D ") == 0 or line.find("D ") == 0:
Expand Down
4 changes: 2 additions & 2 deletions tribits/python_utils/mockprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
sys.exit(1)

mockprogramInout = open('.mockprogram_inout.txt', 'r').read()
mockprogramInoutArray = mockprogramInout.split("\n")
if mockprogramInoutArray[-1] == "":
mockprogramInoutArray = mockprogramInout.splitlines()
if len(mockprogramInoutArray) and mockprogramInoutArray[-1] == "":
mockprogramInoutArray = mockprogramInoutArray[:-1]

if len(mockprogramInoutArray) < 3:
Expand Down

0 comments on commit 2ce3206

Please sign in to comment.