From 39c340f2807a72a2f255bc9461da1054ba0941b1 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 1 Dec 2012 20:16:15 -0600 Subject: [PATCH] Moving blender render files to be accessed via pkg_resources Previously the .blend and .py files had to be in the same directory mediagoblin/celery launched from. This is now fixed so it pulls them out of the package proper. --- .../stl/assets/blender_render.blend | Bin .../media_types/stl/assets/blender_render.py | 0 mediagoblin/media_types/stl/processing.py | 39 +++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) rename blender_render.blend => mediagoblin/media_types/stl/assets/blender_render.blend (100%) rename blender_render.py => mediagoblin/media_types/stl/assets/blender_render.py (100%) diff --git a/blender_render.blend b/mediagoblin/media_types/stl/assets/blender_render.blend similarity index 100% rename from blender_render.blend rename to mediagoblin/media_types/stl/assets/blender_render.blend diff --git a/blender_render.py b/mediagoblin/media_types/stl/assets/blender_render.py similarity index 100% rename from blender_render.py rename to mediagoblin/media_types/stl/assets/blender_render.py diff --git a/mediagoblin/media_types/stl/processing.py b/mediagoblin/media_types/stl/processing.py index 35ac7ea9..97b7ac2e 100644 --- a/mediagoblin/media_types/stl/processing.py +++ b/mediagoblin/media_types/stl/processing.py @@ -18,6 +18,7 @@ import os import json import logging import subprocess +import pkg_resources from mediagoblin import mg_globals as mgg from mediagoblin.processing import create_pub_filepath, \ @@ -29,6 +30,17 @@ from mediagoblin.media_types.stl import model_loader _log = logging.getLogger(__name__) SUPPORTED_FILETYPES = ['stl', 'obj'] +BLEND_FILE = pkg_resources.resource_filename( + 'mediagoblin.media_types.stl', + os.path.join( + 'assets', + 'blender_render.blend')) +BLEND_SCRIPT = pkg_resources.resource_filename( + 'mediagoblin.media_types.stl', + os.path.join( + 'assets', + 'blender_render.py')) + def sniff_handler(media_file, **kw): if kw.get('media') is not None: @@ -55,7 +67,12 @@ def blender_render(config): arg_string = "blender -b blender_render.blend -F " arg_string +="JPEG -P blender_render.py" env = {"RENDER_SETUP" : json.dumps(config), "DISPLAY":":0"} - subprocess.call(arg_string.split(" "), env=env) + subprocess.call( + ["blender", + "-b", BLEND_FILE, + "-F", "JPEG", + "-P", BLEND_SCRIPT], + env=env) def process_stl(entry): @@ -93,16 +110,16 @@ def process_stl(entry): path = create_pub_filepath(entry, name_builder.fill(name)) render_file = mgg.public_store.get_file(path, "wb") shot = { - "model_path" : queued_filename, - "model_ext" : ext, - "camera_coord" : camera, - "camera_focus" : model.average, - "camera_clip" : greatest*10, - "greatest" : greatest, - "projection" : project, - "width" : width, - "height" : height, - "out_file" : render_file.name, + "model_path": queued_filename, + "model_ext": ext, + "camera_coord": camera, + "camera_focus": model.average, + "camera_clip": greatest*10, + "greatest": greatest, + "projection": project, + "width": width, + "height": height, + "out_file": render_file.name, } render_file.close() blender_render(shot) -- 2.25.1