示例#1
0
def files_match(filepath, node):
    node_md5 = _get_md5(node)
    if node_md5 is None:
        # check against size
        updated = parse_date(node['modifiedDate'])
        return os.stat(filepath).st_mtime < updated.timestamp()
    else:
        return commands.md5(filepath) == node_md5
示例#2
0
def files_match(filepath, node):
    node_md5 = _get_md5(node)
    if node_md5 is None:
        # check against size
        updated = parse_date(node['modifiedDate'])
        return os.stat(filepath).st_mtime < updated.timestamp()
    else:
        return commands.md5(filepath) == node_md5
示例#3
0
def _handle_file(folder_node, filepath, filename, update_frequency):
    return_with = None
    try:
        if filename in folder_node['children']:
            node = folder_node['children'][filename]
            if files_match(filepath, node):
                return IGNORED
            updated = parse_date(node['modifiedDate'])
            if os.stat(filepath).st_mtime > (updated.timestamp() +
                                             update_frequency):
                return IGNORED
            # before we try, check if it was processing, can't do anything on it if it is...
            if _node_processing(node):
                existing = api.call('nodes/' + node['id'], 'metadata',
                                    'GET').json()
                if _node_processing(existing):
                    # we recheck to see if we can update yet...
                    return IGNORED
            result = overwrite_file(filepath, folder_node, node['id'])
            return_with = UPLOADED
        else:
            md5 = commands.md5(filepath)
            # we don't have file in index, check if it is already uploaded first
            result = api.call('nodes?filters=contentProperties.md5:%s' % md5,
                              endpoint_type='metadata').json()
            found = False
            if len(result['data']) > 0:
                for node in result['data']:
                    if node['parents'][0] == folder_node['id']:
                        result = node
                        found = True
                        break

            if not found:
                result = upload_file(filepath, folder_node)
                return_with = UPLOADED
                _id = _get_id(result)
                if result.get('code') == 'NAME_ALREADY_EXISTS':
                    existing = api.call('nodes/' + _id, 'metadata',
                                        'GET').json()
                    if _get_md5(existing) == md5:
                        return_with = IGNORED
                        result = existing
                    else:
                        if _node_processing(existing):
                            # check if it is processing first. We aren't allowed to update...
                            result = existing
                        else:
                            result = overwrite_file(filepath, folder_node,
                                                    _get_id(result))
    except:
        logger.error('Unknown error uploading file', exc_info=True)
        result = {}
    if _get_id(result) is None:
        db.update()
        root = db.get()
        if 'errored' not in root:
            root['errored'] = PersistentList()
        root['errored'].append(filepath)
        root['errored'] = root['errored'][-20:]
        transaction.commit()
        return ERRORED
    db.update()
    folder_node['children'][filename] = result
    transaction.commit()
    return return_with
示例#4
0
def _handle_file(folder_node, filepath, filename, update_frequency):
    return_with = None
    try:
        if filename in folder_node['children']:
            node = folder_node['children'][filename]
            if files_match(filepath, node):
                return IGNORED
            updated = parse_date(node['modifiedDate'])
            if os.stat(filepath).st_mtime > (updated.timestamp() + update_frequency):
                return IGNORED
            # before we try, check if it was processing, can't do anything on it if it is...
            if _node_processing(node):
                existing = api.call('nodes/' + node['id'], 'metadata', 'GET').json()
                if _node_processing(existing):
                    # we recheck to see if we can update yet...
                    return IGNORED
            result = overwrite_file(filepath, folder_node, node['id'])
            return_with = UPLOADED
        else:
            md5 = commands.md5(filepath)
            # we don't have file in index, check if it is already uploaded first
            result = api.call('nodes?filters=contentProperties.md5:%s' % md5,
                              endpoint_type='metadata').json()
            found = False
            if len(result['data']) > 0:
                for node in result['data']:
                    if node['parents'][0] == folder_node['id']:
                        result = node
                        found = True
                        break

            if not found:
                result = upload_file(filepath, folder_node)
                return_with = UPLOADED
                _id = _get_id(result)
                if result.get('code') == 'NAME_ALREADY_EXISTS':
                    existing = api.call('nodes/' + _id, 'metadata', 'GET').json()
                    if _get_md5(existing) == md5:
                        return_with = IGNORED
                        result = existing
                    else:
                        if _node_processing(existing):
                            # check if it is processing first. We aren't allowed to update...
                            result = existing
                        else:
                            result = overwrite_file(filepath, folder_node,
                                                    _get_id(result))
    except:
        logger.error('Unknown error uploading file', exc_info=True)
        result = {}
    if _get_id(result) is None:
        db.update()
        root = db.get()
        if 'errored' not in root:
            root['errored'] = PersistentList()
        root['errored'].append(filepath)
        root['errored'] = root['errored'][-20:]
        transaction.commit()
        return ERRORED
    db.update()
    folder_node['children'][filename] = result
    transaction.commit()
    return return_with