Пример #1
0
def store(mod_name, oid, data, opts, block=True):
    mod_dir = get_mod_dir(mod_name)
    sys_utils.assert_dir_exists(mod_dir)

    acquire_file_lock(mod_name, oid, opts, write=True)

    tempfile = os.path.join(datastore_dir, "TMP"+str(os.getpid())+mod_name)
    filename = get_fullpath(mod_dir, mod_name, oid, opts)
    logger.debug("Storing data at %s", filename)

    return_val = True

    if not sys_utils.write_object_to_file(tempfile, data):
        logger.error("Not able to store data at %s", filename)
        return_val = False
    try:
        # Need to do this for windows becuase you cannot rename to an existing file.
        # FIXME: is there any way to do this only if we know we are on windows?
        #if os.path.isfile(filename):
        #    os.remove(filename)
        os.rename(tempfile, filename)
    except:
        logger.error("Not able to rename tempfile to %s", filename)
        return_val = False
    logger.debug("Releasing " + filename)
    release_file_lock(mod_name, oid, opts)

    return return_val
Пример #2
0
def local_store(plugin_name, data_name, data):
    plugin_dir = os.path.join(localstore_dir, plugin_name)
    sys_utils.assert_dir_exists(plugin_dir)
    filename = os.path.join(plugin_dir, data_name)
    logger.debug("Storing data at %s", filename)
    if not sys_utils.write_object_to_file(filename, data):
        logger.error("Not able to store data at %s", filename)
        return False
    return True