Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1033 from dcolligan/1032_repo_slash
Browse files Browse the repository at this point in the history
Fix repo manager choking on traililng path slashes
  • Loading branch information
dcolligan committed Mar 31, 2016
2 parents 849a230 + 118a388 commit cce89bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 16 additions & 7 deletions ga4gh/repo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ def filenameWithoutExtension(filepath, extension):
(os.path.splitext(filename)[0] messes up
on filenames with more than one period)
"""
filename = os.path.basename(filepath)
filename = basename(filepath)
index = filename.index(extension)
return filename[:index]


def basename(path):
"""
Return the final component of a pathname, after normalizing
the path (os.path.basename returns a empty string when given
a path with a trailing slash)
"""
return os.path.basename(os.path.normpath(path))


def runCommandSplits(splits, silent=False):
"""
Run a shell command given the command's parsed command line
Expand Down Expand Up @@ -319,7 +328,7 @@ def addReferenceSet(self, filePath, moveMode, metadata):
self._repoPath, self.referenceSetsDirName, fileName)
self._assertPathEmpty(destPath, inRepo=True)
os.mkdir(destPath)
fileDestPath = os.path.join(destPath, os.path.basename(filePath))
fileDestPath = os.path.join(destPath, basename(filePath))
self._moveFile(filePath, fileDestPath, moveMode)

# move the index files if they exist, otherwise do indexing
Expand All @@ -333,11 +342,11 @@ def addReferenceSet(self, filePath, moveMode, metadata):
if os.path.exists(indexPathFai) and os.path.exists(indexPathGzi):
self._moveFile(
indexPathFai,
os.path.join(destPath, os.path.basename(indexPathFai)),
os.path.join(destPath, basename(indexPathFai)),
moveMode)
self._moveFile(
indexPathGzi,
os.path.join(destPath, os.path.basename(indexPathGzi)),
os.path.join(destPath, basename(indexPathGzi)),
moveMode)
else:
runCommand("samtools faidx {}".format(fileDestPath))
Expand Down Expand Up @@ -394,7 +403,7 @@ def addReadGroupSet(self, datasetName, filePath, moveMode):
self._check()
self._checkDataset(datasetName)
self._checkFile(filePath, self.bamExtension)
fileName = os.path.basename(filePath)
fileName = basename(filePath)
readGroupSetName = filenameWithoutExtension(
fileName, self.bamExtension)
destPath = os.path.join(
Expand All @@ -412,7 +421,7 @@ def addReadGroupSet(self, datasetName, filePath, moveMode):
dstDir = os.path.split(destPath)[0]
self._moveFile(
indexPath,
os.path.join(dstDir, os.path.basename(indexPath)),
os.path.join(dstDir, basename(indexPath)),
moveMode)
else:
pysam.index(destPath.encode('utf-8'))
Expand Down Expand Up @@ -447,7 +456,7 @@ def addVariantSet(self, datasetName, filePath, moveMode):
self._check()
self._checkDataset(datasetName)
self._checkFolder(filePath, self.vcfExtension)
dirName = os.path.basename(filePath)
dirName = basename(filePath)
destPath = os.path.join(
self._repoPath, self.datasetsDirName, datasetName,
self.variantsDirName, dirName)
Expand Down
4 changes: 3 additions & 1 deletion tests/end_to_end/test_repo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def testEndToEnd(self):
self._runCmd("add-referenceset", paths.faPath)
self._runCmd("add-dataset", self.datasetName)
self._runCmd("add-readgroupset", self.datasetName, paths.bamPath)
self._runCmd("add-variantset", self.datasetName, paths.vcfDirPath)
self._runCmd(
"add-variantset", self.datasetName,
paths.vcfDirPath + '/') # ensure we can handle trailing slashes
self._runCmd("check", "--skipConsistencyCheck")
self._runCmd("list")
self._runCmd(
Expand Down

0 comments on commit cce89bc

Please sign in to comment.