Ejemplo n.º 1
0
def inc_get_metas(request, args, handle=None):
    pages, keys, _ = metatable_parseargs(request, args, get_all_keys=True)

    current = dict()
    for page in pages:
        request.page = Page(request, page)
        # metatable_parseargs checks read permissions, no need to do it again
        metas = get_metas(request, page, keys, checkAccess=False)

        current[page] = dict()
        for key in keys:
            values = set(metas[key])
            current[page][key] = values

    cachedir = os.path.join(request.cfg.cache_dir, "getmetas")
    if not os.path.exists(cachedir):
        os.makedirs(cachedir)

    lock = WriteLock(cachedir, timeout=60.0)
    success = lock.acquire()

    path = os.path.join(cachedir, request.cfg.siteid + ".shelve")
    db = shelve.open(path)

    incremental = True
    try:
        if not handle or handle not in db:
            incremental = False
            handle = create_new_handle(db)
        previous = db.get(handle, dict())
        db[handle] = current
    finally:
        db.close()

    if lock.isLocked():
        lock.release()

    return [incremental, handle, diff(previous, current)]