本文整理汇总了Python中invenio_files_rest.models.FileInstance.get_by_uri方法的典型用法代码示例。如果您正苦于以下问题:Python FileInstance.get_by_uri方法的具体用法?Python FileInstance.get_by_uri怎么用?Python FileInstance.get_by_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_files_rest.models.FileInstance
的用法示例。
在下文中一共展示了FileInstance.get_by_uri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fileinstance_get_by_uri
# 需要导入模块: from invenio_files_rest.models import FileInstance [as 别名]
# 或者: from invenio_files_rest.models.FileInstance import get_by_uri [as 别名]
def test_fileinstance_get_by_uri(app, db, dummy_location):
"""Test file get by uri."""
f = FileInstance.create()
f.uri = "LICENSE"
db.session.commit()
assert FileInstance.get_by_uri("LICENSE") is not None
FileInstance.get_by_uri("NOTVALID") is None
pytest.raises(AssertionError, FileInstance.get_by_uri, None)
示例2: create_b2safe_file
# 需要导入模块: from invenio_files_rest.models import FileInstance [as 别名]
# 或者: from invenio_files_rest.models.FileInstance import get_by_uri [as 别名]
def create_b2safe_file(external_pids, bucket):
"""Create a FileInstance which contains a PID in its uri."""
validate_schema(external_pids, {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'ePIC_PID': {'type': 'string'},
'key': {'type': 'string'}
},
'additionalProperties': False,
'required': ['ePIC_PID', 'key']
}
})
keys_list = [e['key'] for e in external_pids]
keys_set = set(keys_list)
if len(keys_list) != len(keys_set):
raise InvalidDepositError([FieldError('external_pids',
'Field external_pids contains duplicate keys.')])
for external_pid in external_pids:
if not external_pid['ePIC_PID'].startswith('http://hdl.handle.net/'):
external_pid['ePIC_PID'] = 'http://hdl.handle.net/' + \
external_pid['ePIC_PID']
if external_pid['key'].startswith('/'):
raise InvalidDepositError(
[FieldError('external_pids',
'File key cannot start with a "/".')])
try:
# Create the file instance if it does not already exist
file_instance = FileInstance.get_by_uri(external_pid['ePIC_PID'])
if file_instance is None:
file_instance = FileInstance.create()
file_instance.set_uri(
external_pid['ePIC_PID'], 1, 0, storage_class='B')
assert file_instance.storage_class == 'B'
# Add the file to the bucket if it is not already in it
current_version = ObjectVersion.get(bucket, external_pid['key'])
if not current_version or \
current_version.file_id != file_instance.id:
ObjectVersion.create(bucket, external_pid['key'],
file_instance.id)
except IntegrityError as e:
raise InvalidDepositError(
[FieldError('external_pids', 'File URI already exists.')])