-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from mskcc/feature/copy_files
Copy files
- Loading branch information
Showing
6 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .copy_service import CopyService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import logging | ||
from shutil import copyfile | ||
from django.conf import settings | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CopyService(object): | ||
|
||
@staticmethod | ||
def copy(path_from, path_to): | ||
logger.info('Copy path from {path_from} to {path_to}'.format(path_from=path_from, | ||
path_to=path_to)) | ||
dirname = os.path.dirname(path_to) | ||
if not os.path.exists(dirname): | ||
os.makedirs(dirname) | ||
copyfile(path_from, path_to) | ||
|
||
@staticmethod | ||
def remap(path, mapping=settings.DEFAULT_MAPPING): | ||
for prefix, dst in mapping.items(): | ||
if path.startswith(prefix): | ||
path = path.replace(prefix, dst) | ||
logger.info('New path {path}'.format(path=path)) | ||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.test import TestCase | ||
from beagle_etl.copy_service import CopyService | ||
from django.conf import settings | ||
from django.test.utils import override_settings | ||
from unittest.mock import patch | ||
|
||
|
||
class JobViewTest(TestCase): | ||
|
||
def setUp(self): | ||
self.mapping = dict() | ||
self.mapping['/path/to'] = '/new/path/to' | ||
patch.dict('os.environ', {'BEAGLE_COPY_MAPPING': "{'/path/to':'/default/path/to'}"}) | ||
|
||
def test_remap(self): | ||
old_path = '/path/to/file/file1.fastq' | ||
new_path = CopyService.remap(old_path, self.mapping) | ||
self.assertEqual(new_path, '/new/path/to/file/file1.fastq') | ||
|
||
def test_remap_no_mapping(self): | ||
old_path = '/some/other/path/to/file/file1.fastq' | ||
new_path = CopyService.remap(old_path, self.mapping) | ||
self.assertEqual(new_path, old_path) |