当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseManager.check_for_existing_file方法代码示例

本文整理汇总了Python中database.DatabaseManager.check_for_existing_file方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.check_for_existing_file方法的具体用法?Python DatabaseManager.check_for_existing_file怎么用?Python DatabaseManager.check_for_existing_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.DatabaseManager的用法示例。


在下文中一共展示了DatabaseManager.check_for_existing_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_extra_file

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import check_for_existing_file [as 别名]
def add_extra_file(uuid):
    extra_file_b64 = request.form.get('extra_file_data')
    sha1_hash = request.form.get('sha1_hash')
    data_length = int(request.form.get('data_length'))
    file_name = request.form.get('file_name')
    rel_file_path = request.form.get('rel_file_path')
    is_executable = request.form.get('is_executable')
    main_executable = request.form.get('main_executable')
    decoded_b64 = base64.b64decode(extra_file_b64)
    extra_b_array = bytearray(decoded_b64)

    main_executable = True if main_executable == 'true' else False
    is_executable = True if is_executable == 'true' else False

    if len(extra_b_array) != data_length:
        extra_b_array.extend([0 for _ in range(len(extra_b_array), data_length)])

    hash_check = get_byte_array_hash(extra_b_array)
    if hash_check != sha1_hash:
        print "{} hash: {} not equal to client hash: {}".format(file_name, hash_check, sha1_hash)

    #   If file with current hash and path already exists, add a new record for save state but
    #   do not create a duplicate file
    file_id = dbm.check_for_existing_file(rel_file_path, hash_check)
    if file_id:
        dbm.link_existing_file_to_save_state(uuid, file_id)
        print "File {}:{} found.".format(file_name, rel_file_path)
    else:
        print "File {}:{} created.".format(file_name, rel_file_path)
        source_data_hash, file_name = save_byte_array_to_store(extra_b_array,
                                                               file_name=file_name,
                                                               store_path=LOCAL_GAME_DATA_STORE)
        fields = OrderedDict(
            game_uuid=None,
            save_state_uuid=uuid,
            is_executable=is_executable,
            main_executable=main_executable,
            file_path=rel_file_path,
            source_data=source_data_hash
        )
        state_ref = dbm.retrieve_save_state(uuid=uuid)[0]
        fields['game_uuid'] = state_ref['game_uuid']
        dbm.add_to_file_path_table(**fields)

    file_path = dbm.retrieve_file_path(save_state_uuid=uuid, file_path=rel_file_path)[0]
    return jsonify(file_path)
开发者ID:gamecip,项目名称:citetool-editor,代码行数:48,代码来源:app.py


注:本文中的database.DatabaseManager.check_for_existing_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。