Allow downloading files with None file_loading/file_loaded/map_type

This commit is contained in:
Sybren A. Stüvel 2016-06-17 15:43:13 +02:00
parent 988dc72ba1
commit 332c32ca9c

View File

@ -548,8 +548,8 @@ async def download_file_by_uuid(file_uuid,
metadata_directory: str, metadata_directory: str,
*, *,
map_type: str = None, map_type: str = None,
file_loading: callable, file_loading: callable = None,
file_loaded: callable, file_loaded: callable = None,
future: asyncio.Future): future: asyncio.Future):
if is_cancelled(future): if is_cancelled(future):
log.debug('download_file_by_uuid(%r) cancelled.', file_uuid) log.debug('download_file_by_uuid(%r) cancelled.', file_uuid)
@ -567,7 +567,7 @@ async def download_file_by_uuid(file_uuid,
save_as_json(file_desc, metadata_file) save_as_json(file_desc, metadata_file)
root, ext = os.path.splitext(file_desc['filename']) root, ext = os.path.splitext(file_desc['filename'])
if root.endswith(map_type): if map_type is None or root.endswith(map_type):
target_filename = '%s%s' % (root, ext) target_filename = '%s%s' % (root, ext)
else: else:
target_filename = '%s-%s%s' % (root, map_type, ext) target_filename = '%s-%s%s' % (root, map_type, ext)
@ -575,6 +575,7 @@ async def download_file_by_uuid(file_uuid,
file_path = os.path.join(target_directory, sanitize_filename(target_filename)) file_path = os.path.join(target_directory, sanitize_filename(target_filename))
file_url = file_desc['link'] file_url = file_desc['link']
# log.debug('Texture %r:\n%s', file_uuid, pprint.pformat(file_desc.to_dict())) # log.debug('Texture %r:\n%s', file_uuid, pprint.pformat(file_desc.to_dict()))
if file_loading is not None:
loop.call_soon_threadsafe(file_loading, file_path, file_desc) loop.call_soon_threadsafe(file_loading, file_path, file_desc)
# Cached headers are stored in the project space # Cached headers are stored in the project space
@ -583,6 +584,7 @@ async def download_file_by_uuid(file_uuid,
await download_to_file(file_url, file_path, header_store=header_store, future=future) await download_to_file(file_url, file_path, header_store=header_store, future=future)
if file_loaded is not None:
loop.call_soon_threadsafe(file_loaded, file_path, file_desc) loop.call_soon_threadsafe(file_loaded, file_path, file_desc)