async def _get_farms(cookie: str, rendering_mode: str, number_of_frames: int) -> Coroutine: try: async with Platform() as plt: farms = await plt.req_get_farms(cookie, { 'renderingMode': rendering_mode, 'numberOfFrames': number_of_frames }, jsonify=True) if len(farms) == 0: bpy.context.window_manager.tresorio_user_props.is_launching_rendering = False BACKEND_LOGGER.error( "Empty response from server while getting farms") alert(TRADUCTOR['notif']['something_went_wrong'][CONFIG_LANG]) return for farm in farms: print(farm) item = bpy.context.window_manager.tresorio_farm_props.add() item.cost = farm["costPerHour"] item.gpu = farm["totalResources"]["gpus"]["SAAS"] item.cpu = farm["totalResources"]["cpus"] # Ram is converted into MB item.ram = farm["totalResources"]["ram"] / (1000 * 1000) item.is_available = farm["isAvailable"] item.units_per_farmer = farm["singleFarmerResources"]["units"] item.number_of_farmers = farm["farmersCount"] except Exception as err: bpy.context.window_manager.tresorio_user_props.is_launching_rendering = False BACKEND_LOGGER.error(err) alert(TRADUCTOR['notif']['something_went_wrong'][CONFIG_LANG])
async def _resume_render(cookie: str, render, farm_index: int) -> Coroutine: """Resume rendering""" try: async with Platform() as plt: await plt.req_resume_render(cookie, render.id, farm_index, render.mode, jsonify=True) await _update_list_renderings(cookie) notif(TRADUCTOR['notif']['rendering_resumed'][CONFIG_LANG].format( render.name)) bpy.context.window_manager.tresorio_user_settings_props.show_selected_render = True except Exception as err: BACKEND_LOGGER.error(err) popup_msg = TRADUCTOR['notif']['err_launch_render'][CONFIG_LANG] if isinstance(err, ClientResponseError): logout_if_unauthorized(err) if err.status == HTTPStatus.FORBIDDEN: popup_msg = TRADUCTOR['notif']['not_enough_credits'][ CONFIG_LANG] elif err.status == HTTPStatus.SERVICE_UNAVAILABLE: alert( TRADUCTOR['notif']['rendering_failed'][CONFIG_LANG].format( render.name.capitalize()), subtitle=TRADUCTOR['notif']['not_enough_servers'] [CONFIG_LANG]) return elif err.status == HTTPStatus.NOT_FOUND: popup_msg = TRADUCTOR['notif']['no_scene'][CONFIG_LANG].format( render.project_name.capitalize()) alert(TRADUCTOR['notif']['rendering_failed'][CONFIG_LANG].format( render.name.capitalize()) + popup_msg)
async def _new_upload(cookie: str, path: str, project_name: str) -> Coroutine: """This function upload a new .blend file""" render_form = bpy.context.scene.tresorio_render_form render_info = None print("Uploading", path) bpy.context.window_manager.tresorio_report_props.uploading_blend_file = True try: async with Platform() as plt: render_info = await plt.req_create_render(cookie, os.path.getsize(path), project_name, jsonify=True) bpy.context.scene.tresorio_render_form.project_id = render_info[ 'id'] try: await _update_list_renderings(cookie) except Exception: pass bpy.context.window_manager.tresorio_renders_list_index = 0 for dirname, dirnames, filenames in os.walk(path): # for subdirname in dirnames: # print(os.path.relpath(os.path.join(dirname, subdirname), path)) for filename in filenames: abspath = os.path.join(dirname, filename) relpath = pathlib.PurePosixPath( pathlib.Path(os.path.relpath(abspath, path))) print("Uploading", relpath) bpy.context.scene.tresorio_render_form.file_uploading = os.path.basename( abspath) loop = asyncio.get_running_loop() upload = functools.partial( force_sync(_upload_blend_file_async), abspath, relpath, render_info) await loop.run_in_executor(None, upload) except Exception as err: BACKEND_LOGGER.error(err) popup_msg = TRADUCTOR['notif']['err_upl_blendfile'][CONFIG_LANG] if isinstance(err, ClientResponseError): logout_if_unauthorized(err) if err.status == HTTPStatus.SERVICE_UNAVAILABLE: popup_msg = TRADUCTOR['notif']['not_enough_servers'][ CONFIG_LANG] alert(popup_msg) return finally: bpy.context.scene.tresorio_render_form.upload_percent = 0.0 bpy.context.window_manager.tresorio_report_props.uploading_blend_file = False
async def _stop_render(cookie: str, render: TresorioRendersDetailsProps) -> Coroutine: try: async with Platform() as plt: BACKEND_LOGGER.debug(f'Stopping render {render.id}') await plt.req_stop_render(cookie, render.id, jsonify=True) except Exception as err: BACKEND_LOGGER.error(err) if isinstance(err, ClientResponseError): logout_if_unauthorized(err) alert(TRADUCTOR['notif']['err_stop_render'][CONFIG_LANG]) else: await _update_rendering(render, cookie)
async def _chunked_upload(cookie: str, blend_path: str, target_path: str, project_name: str) -> Coroutine: """This function upload a new .blend file""" render_form = bpy.context.scene.tresorio_render_form user = bpy.context.window_manager.tresorio_user_props bpy.context.window_manager.tresorio_report_props.uploading = True try: src.operators.upload_modal.end_callback = _on_end src.operators.upload_modal.error_callback = _on_unknown_error src.operators.upload_modal.pack_start_callback = _on_pack_start src.operators.upload_modal.pack_progress_callback = _on_pack_progress src.operators.upload_modal.pack_end_callback = _on_pack_end src.operators.upload_modal.pack_error_callback = _on_pack_error src.operators.upload_modal.missing_file_callback = _on_missing_file src.operators.upload_modal.project_creation_error_callback = _on_project_creation_error src.operators.upload_modal.upload_start_callback = _on_upload_start src.operators.upload_modal.upload_progress_callback = _on_upload_progress src.operators.upload_modal.upload_end_callback = _on_upload_end src.operators.upload_modal.upload_error_callback = _on_upload_error bpy.ops.tresorio.upload_modal( blend_path=blend_path, target_path=target_path, project_name=project_name, url=backend_url, cookie=cookie, storage_url=API_CONFIG[MODE]['storage'], storage_access_key=user.storage_access_key, storage_secret_key=user.storage_secret_key, bucket_name=user.id + '-renderings' # storage_access_key = 'test10', # storage_secret_key = 'test10-secret', # bucket_name = 'test-bucket2' ) except Exception as err: bpy.context.window_manager.tresorio_report_props.uploading = False bpy.context.scene.tresorio_render_form.upload_percent = 0.0 bpy.context.window_manager.tresorio_report_props.uploading_blend_file = False bpy.context.scene.tresorio_render_form.pack_percent = 0.0 bpy.context.window_manager.tresorio_report_props.packing_textures = False bpy.context.scene.tresorio_render_form.file_uploading = '' BACKEND_LOGGER.error(err) popup_msg = TRADUCTOR['notif']['err_upl_blendfile'][CONFIG_LANG] alert(popup_msg)
async def _delete_render( cookie: str, render_id: str, ) -> Coroutine: try: async with Platform() as plt: renders = await plt.req_delete_render(cookie, render_id, jsonify=True) update_ui_renderings(renders, is_new=True) except Exception as err: BACKEND_LOGGER.error(err) if isinstance(err, ClientResponseError): logout_if_unauthorized(err) alert(TRADUCTOR['notif']['err_delete_render'][CONFIG_LANG])
async def _download_render_results(cookie: str, render: TresorioRendersDetailsProps, render_result_path: str) -> Coroutine: try: user_settings = bpy.context.window_manager.tresorio_user_settings_props loop = asyncio.get_running_loop() open_on_dl = user_settings.open_image_on_download download = functools.partial( _download_folder_from_S3, render_result_path, render, open_on_dl, ) render.downloading = True await loop.run_in_executor(None, download) except Exception as err: BACKEND_LOGGER.error(err) UPDATE_QUEUE.put(('finished_download', render_details['id'])) alert(TRADUCTOR['notif']['err_download_folder_from_S3results'] [CONFIG_LANG])
def execute(self, context: bpy.types.Context ) -> Set[str]: """Called when operator is called""" user_props = context.window_manager.tresorio_user_props if not user_props.is_logged: popup(TRADUCTOR['notif']['not_logged_in'] [CONFIG_LANG], icon='ERROR') return {'CANCELLED'} if not bpy.data.is_saved or bpy.data.is_dirty: popup(TRADUCTOR['notif']['file_not_saved'] [CONFIG_LANG], icon='ERROR') return {'CANCELLED'} blend_path = bpy.data.filepath folder = context.scene.tresorio_render_form.project_folder project_name = bpy.path.clean_name(context.scene.tresorio_render_form.project_name) project = project_name + TRADUCTOR['field']['tresorio_suffix'][CONFIG_LANG] target_path = os.path.join(folder, project) if not os.path.exists(folder): alert(TRADUCTOR['notif']['doesnt_exist'][CONFIG_LANG].format(folder)) return {'CANCELLED'} if not os.path.isdir(folder): alert(TRADUCTOR['notif']['not_dir'][CONFIG_LANG].format(folder)) return {'CANCELLED'} if os.path.exists(target_path) and not os.path.isdir(target_path): alert(TRADUCTOR['notif']['pack_error'][CONFIG_LANG].format(project)) return {'CANCELLED'} new_upload(blend_path, target_path, project_name) return {'FINISHED'}
async def _new_render(cookie: str, launch_render: Dict[str, Any]) -> Coroutine: """This function creates a new render and launches it.""" render_form = bpy.context.scene.tresorio_render_form try: async with Platform() as plt: launch_render['projectId'] = render_form.project_id await plt.req_launch_render(cookie, launch_render, jsonify=True) await _update_list_renderings(cookie) notif(TRADUCTOR['notif']['rendering_launched'][CONFIG_LANG].format( render_form.rendering_name.capitalize(), render_form.project_name.capitalize())) bpy.context.window_manager.tresorio_renders_list_index = 0 bpy.context.window_manager.tresorio_user_settings_props.show_selected_render = True except Exception as err: BACKEND_LOGGER.error(err) popup_msg = TRADUCTOR['notif']['err_launch_render'][CONFIG_LANG] if isinstance(err, ClientResponseError): logout_if_unauthorized(err) if err.status == HTTPStatus.FORBIDDEN: popup_msg = TRADUCTOR['notif']['not_enough_credits'][ CONFIG_LANG] elif err.status == HTTPStatus.SERVICE_UNAVAILABLE: alert( TRADUCTOR['notif']['rendering_failed'][CONFIG_LANG].format( render_form.rendering_name.capitalize()), subtitle=TRADUCTOR['notif']['not_enough_servers'] [CONFIG_LANG]) return elif err.status == HTTPStatus.CONFLICT: popup_msg = TRADUCTOR['notif']['render_name_already_taken'][ CONFIG_LANG].format(render_form.rendering_name) elif err.status == HTTPStatus.NOT_FOUND: popup_msg = TRADUCTOR['notif']['no_scene'][CONFIG_LANG].format( render_form.project_name.capitalize()) elif err.status == HTTPStatus.BAD_REQUEST: popup_msg = TRADUCTOR['notif']['wrong_name'][CONFIG_LANG] alert(TRADUCTOR['notif']['rendering_failed'][CONFIG_LANG].format( render_form.rendering_name.capitalize()) + popup_msg)
def print_error(e): print(e) exc_type, exc_obj, exc_tb = sys.exc_info() print(exc_type, exc_tb.tb_frame.f_code.co_filename, exc_tb.tb_lineno) alert(str(e))
def _on_unknown_error(error: str): print('[UNKNOWN ERROR]') alert(TRADUCTOR['notif']['unknown_error_upl'][CONFIG_LANG], subtitle=error)
def _on_project_creation_error(project_name: str, error: str): print('[PROJECT CREATION ERROR]') alert( TRADUCTOR['notif']['error_project'][CONFIG_LANG].format(project_name), subtitle=error)
def _on_pack_error(blend_path: str, target_path: str, error: str): print('[PACK ERROR]') alert(TRADUCTOR['notif']['cant_pack_textures'][CONFIG_LANG], subtitle=error)
def _on_upload_error(filename: str, error: str): print('[UPL ERROR]') alert(TRADUCTOR['notif']['err_upl'][CONFIG_LANG].format(filename, error))