本文整理汇总了Python中sevenbridges.meta.transformer.Transform类的典型用法代码示例。如果您正苦于以下问题:Python Transform类的具体用法?Python Transform怎么用?Python Transform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_folder
def create_folder(cls, name, parent=None, project=None,
api=None):
"""Create a new folder
:param name: Folder name
:param parent: Parent folder
:param project: Project to create folder in
:param api: Api instance
:return: New folder
"""
api = api or cls._API
data = {
'name': name,
'type': cls.FOLDER_TYPE
}
if not parent and not project:
raise SbgError('Parent or project must be provided')
if parent and project:
raise SbgError(
'Providing both "parent" and "project" is not allowed'
)
if parent:
data['parent'] = Transform.to_file(file_=parent)
if project:
data['project'] = Transform.to_project(project=project)
response = api.post(url=cls._URL['create_folder'], data=data).json()
return cls(api=api, **response)
示例2: upload
def upload(cls, path, project=None, parent=None, file_name=None,
overwrite=False, retry=5, timeout=10,
part_size=PartSize.UPLOAD_MINIMUM_PART_SIZE, wait=True,
api=None):
"""
Uploads a file using multipart upload and returns an upload handle
if the wait parameter is set to False. If wait is set to True it
will block until the upload is completed.
:param path: File path on local disc.
:param project: Project identifier
:param parent: Parent folder identifier
:param file_name: Optional file name.
:param overwrite: If true will overwrite the file on the server.
:param retry: Number of retries if error occurs during upload.
:param timeout: Timeout for http requests.
:param part_size: Part size in bytes.
:param wait: If true will wait for upload to complete.
:param api: Api instance.
"""
api = api or cls._API
extra = {'resource': cls.__name__, 'query': {
'path': path,
'project': project,
'file_name': file_name,
'overwrite': overwrite,
'retry': retry,
'timeout': timeout,
'part_size': part_size,
'wait': wait,
}}
logger.info('Uploading file', extra=extra)
if not project and not parent:
raise SbgError('A project or parent identifier is required.')
if project and parent:
raise SbgError(
'Project and parent identifiers are mutually exclusive.'
)
if project:
project = Transform.to_project(project)
if parent:
parent = Transform.to_file(parent)
upload = Upload(
file_path=path, project=project, parent=parent,
file_name=file_name, overwrite=overwrite, retry_count=retry,
timeout=timeout, part_size=part_size, api=api
)
if wait:
upload.start()
upload.wait()
return upload
else:
return upload
示例3: submit_export
def submit_export(cls, file, volume, location, properties=None,
overwrite=False, copy_only=False, api=None):
"""
Submit new export job.
:param file: File to be exported.
:param volume: Volume identifier.
:param location: Volume location.
:param properties: Properties dictionary.
:param overwrite: If true it will overwrite file if exists
:param copy_only: If true files are kept on SevenBridges bucket.
:param api: Api Instance.
:return: Export object.
"""
data = {}
params = {}
volume = Transform.to_volume(volume)
file = Transform.to_file(file)
destination = {
'volume': volume,
'location': location
}
source = {
'file': file
}
if properties:
data['properties'] = properties
data['source'] = source
data['destination'] = destination
data['overwrite'] = overwrite
extra = {
'resource': cls.__name__,
'query': data
}
logger.info('Submitting export', extra=extra)
api = api if api else cls._API
if copy_only:
params['copy_only'] = True
_export = api.post(
cls._URL['query'], data=data, params=params).json()
else:
_export = api.post(
cls._URL['query'], data=data).json()
return Export(api=api, **_export)
示例4: create
def create(cls, name, billing_group, description=None, tags=None,
api=None):
"""
Create a project.
:param name: Project name.
:param billing_group: Project billing group.
:param description: Project description.
:param tags: Project tags.
:param api: Api instance.
:return:
"""
api = api if api else cls._API
billing_group = Transform.to_billing_group(billing_group)
if name is None:
raise SbgError('Project name is required!')
data = {
'name': name,
'billing_group': billing_group,
}
if description:
data['description'] = description
if tags:
data['tags'] = tags
project_data = api.post(url=cls._URL['query'],
data=data).json()
return Project(api=api, **project_data)
示例5: query
def query(cls, division, offset=None, limit=None, api=None):
division = Transform.to_division(division)
api = api if api else cls._API
return super(Team, cls)._query(
url=cls._URL['query'], division=division, offset=offset,
limit=limit, fields='_all', api=api
)
示例6: add_member
def add_member(self, user, permissions):
"""
Add a member to the project.
:param user: Member username
:param permissions: Permissions dictionary.
:return: Member object.
"""
user = Transform.to_user(user)
data = {'username': user, 'type': 'USER'}
if isinstance(permissions, dict):
data.update({
'permissions': permissions
})
extra = {
'resource': self.__class__.__name__,
'query': {
'id': self.id,
'data': data,
}
}
logger.info('Adding member using username', extra=extra)
response = self._api.post(
url=self._URL['members_query'].format(id=self.id), data=data)
member_data = response.json()
return Member(api=self._api, **member_data)
示例7: add_member_division
def add_member_division(self, division, permissions):
"""
Add a member (team) to a project.
:param division: Division object or division identifier.
:param permissions: Permissions dictionary.
:return: Member object.
"""
division = Transform.to_division(division)
data = {'id': division, 'type': 'DIVISION'}
if isinstance(permissions, dict):
data.update({
'permissions': permissions
})
extra = {
'resource': self.__class__.__name__,
'query': {
'id': self.id,
'data': data,
}
}
logger.info('Adding team member using division id', extra=extra)
response = self._api.post(
url=self._URL['members_query'].format(id=self.id), data=data)
member_data = response.json()
return Member(api=self._api, **member_data)
示例8: add_member_team
def add_member_team(self, team, permissions):
"""
Add a member (team) to a volume.
:param team: Team object or team identifier.
:param permissions: Permissions dictionary.
:return: Member object.
"""
team = Transform.to_team(team)
data = {'id': team, 'type': 'TEAM'}
if 'execute' in permissions:
permissions.pop('execute')
if isinstance(permissions, dict):
data.update({
'permissions': permissions
})
extra = {
'resource': self.__class__.__name__,
'query': {
'id': self.id,
'data': data,
}
}
logger.info('Adding volume team member using team id', extra=extra)
response = self._api.post(
url=self._URL['members_query'].format(id=self.id), data=data)
member_data = response.json()
return Member(api=self._api, **member_data)
示例9: create
def create(cls, file, name, position, chromosome, private=True, api=None):
"""
Create a marker on a file.
:param file: File object or identifier.
:param name: Marker name.
:param position: Marker position object.
:param chromosome: Chromosome number.
:param private: Whether the marker is private or public.
:param api: Api instance.
:return: Marker object.
"""
api = api if api else cls._API
file = Transform.to_file(file)
data = {
'file': file,
'name': name,
'position': position,
'chromosome': chromosome,
'private': private
}
extra = {
'resource': cls.__name__,
'query': data
}
logger.info('Creating marker', extra=extra)
marker_data = api.post(url=cls._URL['query'], data=data).json()
return Marker(api=api, **marker_data)
示例10: remove_member
def remove_member(self, user):
"""
Remove member from the project.
:param user: User to be removed.
"""
member = Transform.to_user(user)
self._api.delete(url=self._URL['members_get'].format(
id=self.id,
member=member))
示例11: bulk_submit
def bulk_submit(cls, exports, copy_only=False, api=None):
"""
Create exports in bulk.
:param exports: Exports to be submitted in bulk.
:param copy_only: If true files are kept on SevenBridges bucket.
:param api: Api instance.
:return: list of ExportBulkRecord objects.
"""
if not exports:
raise SbgError('Exports are required')
api = api or cls._API
items = []
for export in exports:
file_ = Transform.to_file(export.get('file'))
volume = Transform.to_volume(export.get('volume'))
location = Transform.to_location(export.get('location'))
properties = export.get('properties', {})
overwrite = export.get('overwrite', False)
item = {
'source': {
'file': file_
},
'destination': {
'volume': volume,
'location': location
},
'properties': properties,
'overwrite': overwrite
}
items.append(item)
data = {'items': items}
params = {'copy_only': copy_only}
response = api.post(
url=cls._URL['bulk_create'], params=params, data=data
)
return ExportBulkRecord.parse_records(response=response, api=api)
示例12: get_file_delete_job
def get_file_delete_job(cls, id, api=None):
"""
:param id: Async job identifier
:param api: Api instance
:return:
"""
id = Transform.to_async_job(id)
api = api if api else cls._API
async_job = api.get(
url=cls._URL['get_file_delete_job'].format(id=id)
).json()
return AsyncJob(api=api, **async_job)
示例13: bulk_get
def bulk_get(cls, exports, api=None):
"""
Retrieve exports in bulk.
:param exports: Exports to be retrieved.
:param api: Api instance.
:return: list of ExportBulkRecord objects.
"""
api = api or cls._API
export_ids = [Transform.to_export(export) for export in exports]
data = {'export_ids': export_ids}
response = api.post(url=cls._URL['bulk_get'], data=data)
return ExportBulkRecord.parse_records(response=response, api=api)
示例14: bulk_delete
def bulk_delete(cls, files, api=None):
"""
Delete files with specified ids in bulk
:param files: Files to be deleted.
:param api: Api instance.
:return: List of FileBulkRecord objects.
"""
api = api or cls._API
file_ids = [Transform.to_file(file_) for file_ in files]
data = {'file_ids': file_ids}
logger.info('Deleting files in bulk.')
response = api.post(url=cls._URL['bulk_delete'], data=data)
return FileBulkRecord.parse_records(response=response, api=api)
示例15: remove_member
def remove_member(self, member, api=None):
"""Remove member from a dataset
:param member: Member username
:param api: Api instance
:return: None
"""
api = api or self._API
username = Transform.to_member(member)
api.delete(
url=self._URL['member'].format(
id=self.id,
username=username
)
)