Esempio n. 1
0
def do_migration():
    logger.info('Starting sha256 recovery migration')
    for version in FileVersion.find(Q('metadata.sha256', 'eq', None)):
        if not version.location:
            continue
        logger.debug('Adding sha {} to version {}'.format(version.location['object'], version._id))
        version.metadata['sha256'] = version.location['object']
        version.save()
Esempio n. 2
0
def do_migration():
    logger.info('Starting sha256 recovery migration')
    for version in FileVersion.find(Q('metadata.sha256', 'eq', None)):
        if not version.location:
            continue
        logger.debug('Adding sha {} to version {}'.format(
            version.location['object'], version._id))
        version.metadata['sha256'] = version.location['object']
        version.save()
Esempio n. 3
0
def get_usage(node):
    vids = sum([
        file_node.to_storage().get('versions', [])
        for file_node in
        OsfStorageFile.find(Q('node', 'eq', node))
    ], [])

    t_vids = sum([
        file_node.to_storage().get('versions', [])
        for file_node in
        TrashedFileNode.find(
            Q('node', 'eq', node) &
            Q('is_file', 'eq', True) &
            Q('provider', 'eq', 'osfstorage')
        )
    ], [])

    usage = sum([v.size or 0 for v in FileVersion.find(Q('_id', 'in', vids))])
    trashed_usage = sum([v.size or 0 for v in FileVersion.find(Q('_id', 'in', t_vids))])

    return map(sum, zip(*([(usage, trashed_usage)] + [get_usage(child) for child in node.nodes_primary])))  # Adds tuples together, map(sum, zip((a, b), (c, d))) -> (a+c, b+d)