Moving blender render files to be accessed via pkg_resources
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 2 Dec 2012 02:16:15 +0000 (20:16 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 3 Dec 2012 20:40:48 +0000 (14:40 -0600)
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.

mediagoblin/media_types/stl/assets/blender_render.blend [moved from blender_render.blend with 100% similarity]
mediagoblin/media_types/stl/assets/blender_render.py [moved from blender_render.py with 100% similarity]
mediagoblin/media_types/stl/processing.py

index 35ac7ea95a8b3568e1caa5a990c8a0e782d05553..97b7ac2e106f6bdd9e3e9127b16f5a9c7dc01fa0 100644 (file)
@@ -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)