Skip to content

Commit

Permalink
Merge branch 'feature/import-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Pleshko committed Sep 30, 2020
2 parents 93ebc64 + 49b60c1 commit 3e0a6c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 4 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ For user management in divisions and teams, the following are available:
# All teams in division
teams_all = api.teams.query(division='<division_slug>', list_all=True)
For disabling users
For disabling users:

.. code:: python
.. code-block:: python
user = api.users.get('<username>')
user.disable()
Expand Down Expand Up @@ -1117,6 +1117,8 @@ Each import has the following properties:

``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.

``autorename`` - Whether to automatically rename the item (by prefixing its name with an underscore and number) if another one with the same name already exists at the destination.


VolumeFile properties
~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion sevenbridges/models/storage_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def bulk_get(cls, exports, api=None):
def bulk_submit(cls, exports, copy_only=False, api=None):
"""
Create exports in bulk.
:param exports: Exports to be submitted in bulk.
:param exports: List of dicts describing a wanted export.
:param copy_only: If true files are kept on SevenBridges bucket.
:param api: Api instance.
:return: list of ExportBulkRecord objects.
Expand Down
29 changes: 24 additions & 5 deletions sevenbridges/models/storage_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Import(Resource):
id = StringField(read_only=True)
state = StringField(read_only=True)
preserve_folder_structure = BooleanField(read_only=True)
autorename = 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 @@ -68,7 +69,8 @@ def result(self):
@classmethod
def submit_import(cls, volume, location, project=None, name=None,
overwrite=False, properties=None, parent=None,
preserve_folder_structure=True, api=None):
preserve_folder_structure=True, autorename=False,
api=None):
"""
Submits new import job.
:param volume: Volume identifier.
Expand All @@ -83,6 +85,9 @@ def submit_import(cls, volume, location, project=None, name=None,
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 autorename: Whether to automatically rename the item
(by prefixing its name with an underscore and number) if
another one with the same name already exists at the destination.
:param api: Api instance.
:return: Import object.
"""
Expand Down Expand Up @@ -121,6 +126,9 @@ def submit_import(cls, volume, location, project=None, name=None,
if not preserve_folder_structure:
data['preserve_folder_structure'] = preserve_folder_structure

if autorename:
data['autorename'] = autorename

if properties:
data['properties'] = properties

Expand Down Expand Up @@ -177,7 +185,7 @@ def bulk_get(cls, imports, api=None):
def bulk_submit(cls, imports, api=None):
"""
Submit imports in bulk
:param imports: Imports to be retrieved.
:param imports: List of dicts describing a wanted import.
:param api: Api instance.
:return: List of ImportBulkRecord objects.
"""
Expand Down Expand Up @@ -210,18 +218,29 @@ def bulk_submit(cls, imports, api=None):
location = Transform.to_location(import_.get('location'))
name = import_.get('name', None)
overwrite = import_.get('overwrite', False)
autorename = import_.get('autorename', None)
preserve_folder_structure = import_.get(
'preserve_folder_structure', None
)

if name:
destination['name'] = name

items.append({
import_config = {
'source': {
'volume': volume,
'location': location
},
'destination': destination,
'overwrite': overwrite
})
'overwrite': overwrite,
}
if autorename is not None:
import_config['autorename'] = autorename
if preserve_folder_structure is not None:
import_config['preserve_folder_structure'] = (
preserve_folder_structure
)
items.append(import_config)

data = {'items': items}
response = api.post(url=cls._URL['bulk_create'], data=data)
Expand Down

0 comments on commit 3e0a6c5

Please sign in to comment.