本文整理汇总了Python中database.DatabaseManager.retrieve_file_path方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.retrieve_file_path方法的具体用法?Python DatabaseManager.retrieve_file_path怎么用?Python DatabaseManager.retrieve_file_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.retrieve_file_path方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emulation_info_state
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [as 别名]
def emulation_info_state(uuid):
state_info = {}
state_ref = dbm.retrieve_save_state(uuid=uuid)[0]
other_save_states = dbm.retrieve_save_state(game_uuid=state_ref['game_uuid'])
state_extra_files = dbm.retrieve_file_path(save_state_uuid=uuid)
state_info['record'] = state_ref
state_info['availableStates'] = filter(lambda s: True if s.get('save_state_source_data') or s.get('rl_starts_data') else False, other_save_states)
state_info['fileMapping'] = {k: os.path.join('/game_data', v, k.split('/')[-1]) for k, v in map(lambda x: (x['file_path'], x['source_data']),
state_extra_files)} if state_extra_files else None
state_info['fileInformation'] = {f['file_path']: f for f in state_extra_files}
# Save data is singular, and probably LZMA compressed
if state_ref['save_state_source_data']:
state_info['stateFileURL'] = os.path.join('/cite_data', state_ref['save_state_source_data'], '{}'.format(state_ref['uuid']))
# Save data is multiple and probably run length encoded
if state_ref['rl_starts_data'] and state_ref['rl_lengths_data']:
state_info['rlStartsURL'] = os.path.join('/cite_data', state_ref['rl_starts_data'], '{}'.format(state_ref['uuid']))
state_info['rlLengthsURL'] = os.path.join('/cite_data', state_ref['rl_lengths_data'], '{}'.format(state_ref['uuid']))
if state_extra_files:
main_exec = dbm.retrieve_file_path(save_state_uuid=uuid, main_executable=True)[0]
state_info['gameFileURL'] = os.path.join('/game_data', main_exec['source_data'], main_exec['file_path'].split('/')[-1])
else:
game_ref = dbm.retrieve_game_ref(state_ref['game_uuid'])
state_info['gameFileURL'] = os.path.join('/game_data', game_ref['source_data'], game_ref['data_image_source'])
return jsonify(state_info)
示例2: citation_page
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [as 别名]
def citation_page(uuid):
game_ref = dbm.retrieve_game_ref(uuid)
perf_ref = dbm.retrieve_perf_ref(uuid)
derived_performances = dbm.retrieve_derived_performances(uuid)
previous_performances = dbm.retrieve_performance_chain(uuid)[:-1]
save_states = dbm.retrieve_save_state(game_uuid=uuid)
extra_files = dbm.retrieve_file_path(game_uuid=uuid)
if game_ref:
return render_template('citation.html',
citeref=game_ref,
is_game=True,
is_performance=False,
derived_performances=derived_performances,
extra_files=extra_files,
save_states=save_states)
elif perf_ref:
performance_video = "/cite_data/{}/{}".format(perf_ref['replay_source_file_ref'],
perf_ref['replay_source_file_name'])
return render_template('citation.html',
citeref=perf_ref,
is_game=False,
is_performance=True,
previous_performances=previous_performances,
performance_video=performance_video)
return "No record found, sorry."
示例3: play_page
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [as 别名]
def play_page(uuid):
init_state = request.values.get('init_state')
cite_ref = dbm.retrieve_game_ref(uuid)
state_dicts = dbm.retrieve_save_state(game_uuid=uuid)
if init_state:
init_state = dbm.retrieve_save_state(uuid=init_state)[0]
has_exec = dbm.retrieve_file_path(save_state_uuid=init_state['uuid'], main_executable=True)
else:
has_exec = dbm.retrieve_file_path(game_uuid=uuid, save_state_uuid=None, main_executable=True)
init_state = {'uuid': 'NO_ID'}
if cite_ref and (cite_ref['data_image_source'] or has_exec):
return render_template('play.html',
init_state=init_state,
cite_ref=cite_ref)
return "No game data source found, sorry!"
示例4: emulation_info_game
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [as 别名]
def emulation_info_game(uuid):
game_info = {}
game_ref = dbm.retrieve_game_ref(uuid)
game_extra_files = dbm.retrieve_file_path(game_uuid=uuid, save_state_uuid=None)
if game_ref and (game_ref['data_image_source'] or game_extra_files):
gis = game_ref['data_image_source']
gsd = game_ref['source_data']
main_exec = dbm.retrieve_file_path(game_uuid=uuid, save_state_uuid=None, main_executable=True)
main_fp = main_exec[0]['file_path'].split('/')[-1] if main_exec else None
game_info['gameFileURL'] = os.path.join('/game_data', gsd, gis) if gis else main_fp
if game_extra_files:
game_info['fileMapping'] = {k: os.path.join('/game_data', v, k.split('/')[-1]) for k, v in map(lambda x: (x['file_path'], x['source_data']),
game_extra_files)}
game_info['fileInformation'] = {f['file_path']: f for f in game_extra_files}
game_info['stateFileURL'] = None
game_info['record'] = game_ref.elements
game_info['availableStates'] = filter(lambda s: True if s.get('save_state_source_data') or s.get('rl_starts_data') else False, dbm.retrieve_save_state(game_uuid=uuid))
game_info['availablePerformances'] = [dict(p.get_element_items()) for p in dbm.retrieve_derived_performances(uuid)]
return jsonify(game_info)
示例5: add_extra_file
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [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)
示例6: delete
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import retrieve_file_path [as 别名]
def delete(ctx, uuid, keep_performances):
no_prompts = ctx.obj['NO_PROMPTS']
verbose = ctx.obj['VERBOSE']
def check_delete(path):
try:
shutil.rmtree(path)
except OSError as e:
print e.message
def delete_from_fts(uuid):
ix = open_dir(LOCAL_FTS_INDEX)
writer = ix.writer()
writer.delete_by_term('id', uuid)
writer.commit()
game_ref = dbm.retrieve_game_ref(uuid)
perf_ref = dbm.retrieve_perf_ref(uuid)
state_ref = dbm.retrieve_save_state(uuid=uuid)
if game_ref:
perfs = dbm.retrieve_derived_performances(uuid)
states = dbm.retrieve_save_state(game_uuid=uuid)
files = dbm.retrieve_file_path(game_uuid=uuid)
for f in files:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_GAME_DATA_STORE, f['source_data']))
dbm.delete_from_table(dbm.GAME_FILE_PATH_TABLE, ['game_uuid'], [uuid])
for s in states:
if s['save_state_source_data']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, s['save_state_source_data']))
else:
if s['rl_starts_data']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, s['rl_starts_data']))
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, s['rl_lengths_data']))
if s['has_screen']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, s['uuid']))
dbm.delete_from_table(dbm.GAME_SAVE_TABLE, ['game_uuid'], [uuid])
for p in perfs:
if p['replay_source_file_ref']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, p['replay_source_file_ref']))
dbm.delete_from_table(dbm.SAVE_STATE_PERFORMANCE_LINK_TABLE,['performance_uuid'], [p['uuid']])
dbm.delete_from_table(dbm.PERFORMANCE_CITATION_TABLE, ['game_uuid'], [uuid])
if game_ref['source_data']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_GAME_DATA_STORE, game_ref['source_data']))
dbm.delete_from_table(dbm.GAME_CITATION_TABLE, ['uuid'], [uuid])
delete_from_fts(uuid)
elif perf_ref:
dbm.delete_from_table(dbm.SAVE_STATE_PERFORMANCE_LINK_TABLE,['performance_uuid'], [uuid])
if perf_ref['replay_source_file_ref']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, perf_ref['replay_source_file_ref']))
dbm.delete_from_table(dbm.PERFORMANCE_CITATION_TABLE, ['uuid'], [uuid])
delete_from_fts(uuid)
elif state_ref:
state_ref = state_ref[0] # retrieve states returns lists
files = dbm.retrieve_file_path(save_state_uuid=uuid)
for f in files:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_GAME_DATA_STORE, f['source_data']))
dbm.delete_from_table(dbm.SAVE_STATE_PERFORMANCE_LINK_TABLE,['save_state_uuid'], [uuid])
if state_ref['has_screen']:
check_delete(os.path.join(LOCAL_DATA_ROOT, LOCAL_CITATION_DATA_STORE, state_ref['uuid']))
dbm.delete_from_table(dbm.GAME_SAVE_TABLE, ['uuid'], [uuid])
delete_from_fts(uuid)
else:
click.echo('UUID {} not found.'.format(uuid))
sys.exit(1)