Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejan Knezevic committed Jan 8, 2019
2 parents 588b852 + 0d0886e commit 47966b1
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
0.17.7 (2019-01-08)
==================

- Improvements:
- Fix readme rendering on PyPi

0.17.6 (2019-01-08)
==================

- Improvements:
- Added parent and preserve_folder_structure parameters and properties to imports
- Updated documentation regarding cwl

0.17.5 (2018-12-21)
==================

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.5
0.17.7
25 changes: 23 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,9 @@ Each import has the following properties:

``id`` - Import identifier.

``source`` - Source of the import, object of type ``VolumeFile``, contains info on volume and file location on the volume
``source`` - Source of the import, object of type ``VolumeFile``, contains info on volume and file location on the volume.

``destination`` - Destination of the import, object of type ``ImportDestination``, containing info on project where the file was imported to and name of the file in the project
``destination`` - Destination of the import, object of type ``ImportDestination``, containing info on project where the file was imported to and name of the file in the project.

``state`` - State of the import. Can be *PENDING*, *RUNNING*, *COMPLETED* and *FAILED*.

Expand All @@ -1019,6 +1019,27 @@ Each import has the following properties:

``finished_on`` - Contains the date and time when the import was finished.

``preserve_folder_structure`` - Whether to keep the exact source folder structure. The default value is true if the item being imported is a folder. Should not be used if you are importing a file.


VolumeFile properties
~~~~~~~~~~~~~~~~~~~~~

``volume`` - Volume ID from which to import the item.

``location`` - Volume-specific location pointing to the file or folder to import. This location should be recognizable to the underlying cloud service as a valid key or path to the item. If the item being imported is a folder, its path should end with a ``/``.


ImportDestination properties
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``project`` - The project in which to create the alias.

``parent`` - The ID of the target folder to which the item should be imported. Should not be used together with project. If parent is used, the import will take place into the specified folder, within the project to which the folder belongs. If project is used, the items will be imported to the root of the project's files.

``name`` - The name of the alias to create. This name should be unique to the project. If the name is already in use in the project, you should use the overwrite query parameter in this call to force any item with that name to be deleted before the alias is created. If name is omitted, the alias name will default to the last segment of the complete location (including the prefix) on the volume. Segments are considered to be separated with forward slashes ``/``.


Import methods
~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
description='SBG API python client bindings',
install_requires=install_requires,
long_description=io.open('README.md', 'r', encoding='utf-8').read(),
long_description_content_type='text/markdown',
platforms=['Windows', 'POSIX', 'MacOS'],
maintainer='Seven Bridges Genomics Inc.',
maintainer_email='dejan.knezevic@sbgenomics.com',
Expand Down
2 changes: 1 addition & 1 deletion sevenbridges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ssl
import logging

__version__ = "0.17.5"
__version__ = "0.17.7"

from sevenbridges.api import Api
from sevenbridges.config import Config
Expand Down
1 change: 1 addition & 0 deletions sevenbridges/models/compound/volumes/import_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ImportDestination(Resource):
imported on to SevenBridges platform or related product.
"""
project = StringField(read_only=True)
parent = StringField(read_only=True)
name = StringField(read_only=True)

def __str__(self):
Expand Down
42 changes: 34 additions & 8 deletions sevenbridges/models/storage_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Import(Resource):
href = HrefField()
id = StringField(read_only=True)
state = StringField(read_only=True)
preserve_folder_structure = BooleanField(read_only=True)
source = CompoundField(VolumeFile, read_only=True)
destination = CompoundField(ImportDestination, read_only=True)
started_on = DateTimeField(read_only=True)
Expand Down Expand Up @@ -65,9 +66,9 @@ def result(self):
return None

@classmethod
def submit_import(cls, volume, location, project, name=None,
overwrite=False, properties=None, api=None):

def submit_import(cls, volume, location, project=None, name=None,
overwrite=False, properties=None, parent=None,
preserve_folder_structure=True, api=None):
"""
Submits new import job.
:param volume: Volume identifier.
Expand All @@ -76,26 +77,50 @@ def submit_import(cls, volume, location, project, name=None,
:param name: Optional file name.
:param overwrite: If true it will overwrite file if exists.
:param properties: Properties dictionary.
:param parent: The ID of the target folder to which the item should be
imported. Should not be used together with project.
:param preserve_folder_structure: Whether to keep the exact source
folder structure. The default value is true if the item being
imported is a folder. Should not be used if you are importing
a file.
:param api: Api instance.
:return: Import object.
"""
data = {}
volume = Transform.to_volume(volume)
project = Transform.to_project(project)

if project and parent:
raise SbgError(
'Project and parent identifiers are mutually exclusive'
)
elif project:
project = Transform.to_project(project)
destination = {
'project': project
}
elif parent:
parent = Transform.to_file(parent)
destination = {
'parent': parent
}
else:
raise SbgError('Project or parent identifier is required.')

source = {
'volume': volume,
'location': location
}
destination = {
'project': project
}

if name:
destination['name'] = name

data['source'] = source
data['destination'] = destination
data['overwrite'] = overwrite

if not preserve_folder_structure:
data['preserve_folder_structure'] = preserve_folder_structure

if properties:
data['properties'] = properties

Expand All @@ -111,12 +136,13 @@ def submit_import(cls, volume, location, project, name=None,
@classmethod
def query(cls, project=None, volume=None, state=None, offset=None,
limit=None, api=None):

"""
Query (List) imports.
:param project: Optional project identifier.
:param volume: Optional volume identifier.
:param state: Optional import sate.
:param offset: Pagination offset.
:param limit: Pagination limit.
:param api: Api instance.
:return: Collection object.
"""
Expand Down
29 changes: 28 additions & 1 deletion sevenbridges/tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import faker
import pytest

generator = faker.Factory.create()
pytestmark = pytest.mark.volumes


def test_imports_query(api, given, verifier):
Expand All @@ -27,7 +29,32 @@ def test_import_submit(api, given, verifier):
given.imports.can_be_submitted(id=id)

# action
imports = api.imports.submit_import(volume, location, project)
imports = api.imports.submit_import(
volume=volume,
location=location,
project=project
)

assert imports.id == id
verifier.imports.submitted()


def test_import_to_folder_submit(api, given, verifier):
# preconditions
id = generator.uuid4()
volume = generator.name()
location = generator.name()
parent = generator.name() + "/"
given.imports.can_be_submitted(id=id)
preserve_folder_structure = False

# action
imports = api.imports.submit_import(
volume=volume,
location=location,
parent=parent,
preserve_folder_structure=preserve_folder_structure
)

assert imports.id == id
verifier.imports.submitted()
Expand Down

0 comments on commit 47966b1

Please sign in to comment.