本文整理汇总了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)