Пример #1
0
def post_file(request):
    files = File.objects(Q(source=request.parameters['source']) &
                         Q(collection=request.parameters['collection']) &
                         Q(filename=request.parameters['name'])).all()
    if len(files) == 0:
        file = File()
        file.collection = request.parameters['collection']
        file.filename = request.parameters['name']
        file.encoding = Encoding(**DEFAULT_ENCODING)
        hubs = Hub.objects(cumulus_id=request.parameters['source'])
        if len(hubs) == 0:
            raise ObjectDoesNotExist('Source does not exist')
        elif len(hubs) == 1:
            hub = hubs[0]
        else:
            raise MultipleObjectsFound('Multiple files found for source')
        file.source = hub
    elif len(files) == 1:
        file = files[0]
    else:
        raise MultipleObjectsFound('Multiple objects found for the search query')

    with file as f:
        f.write(request.data)

    return FileSerializer(file).data
Пример #2
0
filename2 = 'learningreact1.pdf'
with open(os.path.join('tmp', filename2), 'rb') as f:
    file_content2 = f.read()

hub = Hub.objects.first()
if hub is None:
    hub = Hub(reference='HUB-' + uuid.uuid4().hex)
    hub.save()

start = time.perf_counter()

file = File()
file.source = hub
file.collection = 'nextcloud'
file.filename = filename1
file.encoding = Encoding(name='liberasurecode_rs_vand', k=2, m=3)

with file as f:
    f.write(file_content1)

for t_hub in Hub.objects:
    if t_hub.cumulus_id != hub.cumulus_id:
        t_hub.delete()

orphan_count = OrphanedFragment.objects.count()
fragments = set([f.uuid for f in file.fragments])

try:
    with file as f:
        f.write(file_content2)