Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextflow fixes #19

Merged
merged 4 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/tesk_core/filer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import requests
from tesk_core.exception import UnknownProtocol, FileProtocolDisabled
import shutil
from glob import glob
from tesk_core.path import containerPath, getPath, fileEnabled

try:
Expand Down Expand Up @@ -157,6 +158,21 @@ def copyDir(src, dst):

shutil.copytree(src, dst)

def copyFile(src, dst):
'''
Limitations of shutil.copy:

It does not interpret * as a glob, but as a character.
'''

# If there is any * in 'dst', use only the dirname (base path)
p = re.compile('.*\*.*')
if p.match(dst):
dst=os.path.dirname(dst)

for file in glob(src):
shutil.copy(file, dst)


class FileTransput(Transput):
def __init__(self, path, url, ftype):
Expand All @@ -172,7 +188,7 @@ def transfer(self, copyFn, src, dst):

def download_file(self): self.transfer(shutil.copy , self.urlContainerPath , self.path)
def download_dir(self): self.transfer(copyDir , self.urlContainerPath , self.path)
def upload_file(self): self.transfer(shutil.copy , self.path , self.urlContainerPath)
def upload_file(self): self.transfer(copyFile , self.path , self.urlContainerPath)
def upload_dir(self): self.transfer(copyDir , self.path , self.urlContainerPath)


Expand Down Expand Up @@ -454,8 +470,8 @@ def process_file(ttype, filedata):

scheme = urlparse(filedata['url']).scheme
if scheme == '':
logging.error('Could not determine protocol for url: "%s"', filedata['url'])
return 1
logging.info('Could not determine protocol for url: "%s", assuming "file"', filedata['url'])
scheme='file'

trans = newTransput(scheme)

Expand Down
32 changes: 28 additions & 4 deletions tests/test_filer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from tesk_core.filer import newTransput, FTPTransput, HTTPTransput, FileTransput,\
process_file, logConfig, getPath, copyDir
process_file, logConfig, getPath, copyDir, copyFile
from tesk_core.exception import UnknownProtocol, InvalidHostPath,\
FileProtocolDisabled
from tesk_core.path import containerPath
Expand Down Expand Up @@ -94,8 +94,8 @@ def test_upload_dir(self, copyMock, copyDirMock):
, '/transfer/tmphrtip1o8')

@patch('tesk_core.filer.copyDir')
@patch('tesk_core.filer.shutil.copy')
def test_upload_file(self, copyMock, copyDirMock):
@patch('tesk_core.filer.copyFile')
def test_upload_file(self, copyFileMock, copyDirMock):

filedata = {
"url": "file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5",
Expand All @@ -108,10 +108,29 @@ def test_upload_file(self, copyMock, copyDirMock):

copyDirMock.assert_not_called()

copyMock.assert_called_once_with( '/TclSZU/md5'
copyFileMock.assert_called_once_with( '/TclSZU/md5'
, '/transfer/tmphrtip1o8/md5')


@patch('tesk_core.filer.copyDir')
@patch('tesk_core.filer.copyFile')
def test_upload_file_glob(self, copyFileMock, copyDirMock):

filedata = {
"url": "file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5*",
"path": "/TclSZU/md5*",
"type": "FILE",
"name": "stdout"
}

process_file('outputs', filedata)

copyDirMock.assert_not_called()

copyFileMock.assert_called_once_with( '/TclSZU/md5*'
, '/transfer/tmphrtip1o8/md5*')


def test_copyDir(self):

def rmDir(d):
Expand Down Expand Up @@ -170,6 +189,11 @@ def test_getPath(self):
self.assertEquals( getPath('file:///home/tfga/workspace/cwl-tes/tmphrtip1o8/md5')
, '/home/tfga/workspace/cwl-tes/tmphrtip1o8/md5')

def test_getPathNoScheme(self):

self.assertEquals( getPath('/home/tfga/workspace/cwl-tes/tmphrtip1o8/md5')
, '/home/tfga/workspace/cwl-tes/tmphrtip1o8/md5')


def test_containerPath(self):

Expand Down