Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Poirier <theeth@yahoo.com>2012-02-12 23:32:24 +0400
committerMartin Poirier <theeth@yahoo.com>2012-02-12 23:32:24 +0400
commita6d7d6c040ff61c7b894cb374ded7c5d450290c2 (patch)
treeef6df78ba1c5b2bcaa1294faa11e6a23d62756c8
parenta4683ac1a4f0e3ff23573dff1c9d739e6d46ac69 (diff)
netrender
change to the repatching and local naming algorithms to better support different files with same name and dependency folder hierarchies.
-rw-r--r--netrender/master.py12
-rw-r--r--netrender/repath.py36
-rw-r--r--netrender/slave.py6
-rw-r--r--netrender/utils.py62
4 files changed, 77 insertions, 39 deletions
diff --git a/netrender/master.py b/netrender/master.py
index 96894808..d5989f8c 100644
--- a/netrender/master.py
+++ b/netrender/master.py
@@ -777,15 +777,15 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
if job:
- render_file = job.files[file_index]
+ rfile = job.files[file_index]
- if render_file:
- main_file = job.files[0].filepath # filename of the first file
+ if rfile:
+ main_file = job.files[0].original_path # original path of the first file
main_path, main_name = os.path.split(main_file)
if file_index > 0:
- file_path = prefixPath(job.save_path, render_file.filepath, main_path, force = True)
+ file_path = createLocalPath(rfile, job.save_path, main_path, True)
else:
file_path = os.path.join(job.save_path, main_name)
@@ -793,8 +793,8 @@ class RenderHandler(http.server.BaseHTTPRequestHandler):
self.write_file(file_path)
- render_file.filepath = file_path # set the new path
- found = render_file.updateStatus() # make sure we have the right file
+ rfile.filepath = file_path # set the new path
+ found = rfile.updateStatus() # make sure we have the right file
if not found: # checksum mismatch
self.server.stats("", "File upload but checksum mismatch, this shouldn't happen")
diff --git a/netrender/repath.py b/netrender/repath.py
index af8f79d8..e06b17c5 100644
--- a/netrender/repath.py
+++ b/netrender/repath.py
@@ -21,6 +21,8 @@ import subprocess
import bpy
+DEBUG = False
+
from netrender.utils import *
BLENDER_PATH = sys.argv[0]
@@ -44,7 +46,9 @@ def update(job):
path, ext = os.path.splitext(job_full_path)
- new_path = path + ".remap" + ext
+ new_path = path + ".remap" + ext
+
+ original_path = main_file.original_path
# Disable for now. Partial repath should work anyway
#all = main_file.filepath != main_file.original_path
@@ -57,26 +61,33 @@ def update(job):
# Only update if needed
if paths:
- process = subprocess.Popen([BLENDER_PATH, "-b", "-noaudio", job_full_path, "-P", __file__, "--", new_path] + paths, stdout=sys.stdout, stderr=subprocess.STDOUT)
+ process = subprocess.Popen([BLENDER_PATH, "-b", "-noaudio", job_full_path, "-P", __file__, "--", new_path, original_path] + paths, stdout=sys.stdout, stderr=subprocess.STDOUT)
process.wait()
os.renames(job_full_path, job_full_path + ".bak")
os.renames(new_path, job_full_path)
-def process(paths):
+def process(original_path, paths):
+ if DEBUG: print("==========================================================")
+ original_directory = os.path.dirname(original_path)
path_map = {}
for i in range(0, len(paths), 2):
# special case for point cache
if paths[i].endswith(".bphys"):
path, filename = os.path.split(paths[i+1])
cache_name = filename.split("_")[0]
+ if DEBUG: print(cache_name, path)
path_map[cache_name] = path
# special case for fluids
elif paths[i].endswith(".bobj.gz"):
+ if DEBUG: print(os.path.split(paths[i])[0], os.path.split(paths[i+1])[0])
path_map[os.path.split(paths[i])[0]] = os.path.split(paths[i+1])[0]
else:
- path_map[os.path.split(paths[i])[1]] = paths[i+1]
+ if DEBUG: print(paths[i], paths[i+1])
+ path_map[paths[i]] = paths[i+1]
+ if DEBUG: print("----------------------------------------------------------")
+
# TODO original paths aren't really the original path, they are the normalized path
# so we repath using the filenames only.
@@ -84,8 +95,9 @@ def process(paths):
# LIBRARIES
###########################
for lib in bpy.data.libraries:
- file_path = bpy.path.abspath(lib.filepath)
- new_path = path_map.get(os.path.split(file_path)[1], None)
+ file_path = bpy.path.abspath(lib.filepath, start=original_directory)
+ new_path = path_map.get(file_path, None)
+ if DEBUG: print(file_path, new_path)
if new_path:
lib.filepath = new_path
@@ -94,8 +106,9 @@ def process(paths):
###########################
for image in bpy.data.images:
if image.source == "FILE" and not image.packed_file:
- file_path = bpy.path.abspath(image.filepath)
- new_path = path_map.get(os.path.split(file_path)[1], None)
+ file_path = bpy.path.abspath(image.filepath, start=original_directory)
+ new_path = path_map.get(file_path, None)
+ if DEBUG: print(file_path, new_path)
if new_path:
image.filepath = new_path
@@ -109,6 +122,7 @@ def process(paths):
cache_name = cacheName(object, point_cache)
new_path = path_map.get(cache_name, None)
+ if DEBUG: print(cache_name, new_path)
if new_path:
point_cache.use_external = True
point_cache.filepath = new_path
@@ -126,6 +140,7 @@ def process(paths):
modifier.filepath = new_path
processObjectDependencies(pointCacheFunc, fluidFunc, multiresFunc)
+ if DEBUG: print("==========================================================")
if __name__ == "__main__":
@@ -135,9 +150,8 @@ if __name__ == "__main__":
i = 0
if i:
- new_path = sys.argv[i+1]
- args = sys.argv[i+2:]
+ new_path, original_path, *args = sys.argv[i+1:]
- process(args)
+ process(original_path, args)
bpy.ops.wm.save_as_mainfile(filepath=new_path, check_existing=False)
diff --git a/netrender/slave.py b/netrender/slave.py
index ea132df2..fe3979a7 100644
--- a/netrender/slave.py
+++ b/netrender/slave.py
@@ -59,7 +59,7 @@ def testCancel(conn, job_id, frame_number):
return False
def testFile(conn, job_id, slave_id, rfile, JOB_PREFIX, main_path=None):
- job_full_path = prefixPath(JOB_PREFIX, rfile.filepath, main_path, force=rfile.force)
+ job_full_path = createLocalPath(rfile, JOB_PREFIX, main_path, rfile.force)
found = os.path.exists(job_full_path)
@@ -73,7 +73,7 @@ def testFile(conn, job_id, slave_id, rfile, JOB_PREFIX, main_path=None):
if not found:
# Force prefix path if not found
- job_full_path = prefixPath(JOB_PREFIX, rfile.filepath, main_path, force=True)
+ job_full_path = createLocalPath(rfile, JOB_PREFIX, main_path, True)
print("Downloading", job_full_path)
temp_path = os.path.join(JOB_PREFIX, "slave.temp")
with ConnectionContext():
@@ -170,7 +170,7 @@ def render_slave(engine, netsettings, threads):
if job.type == netrender.model.JOB_BLENDER:
- job_path = job.files[0].filepath # path of main file
+ job_path = job.files[0].original_path # original path of the first file
main_path, main_file = os.path.split(job_path)
job_full_path = testFile(conn, job.id, slave_id, job.files[0], JOB_PREFIX)
diff --git a/netrender/utils.py b/netrender/utils.py
index 4e6c40bf..c173e02d 100644
--- a/netrender/utils.py
+++ b/netrender/utils.py
@@ -308,30 +308,54 @@ def processObjectDependencies(pointCacheFunction, fluidFunction, multiresFunctio
pointCacheFunction(object, psys, psys.point_cache)
-def prefixPath(prefix_directory, file_path, prefix_path, force = False):
- if (os.path.isabs(file_path) or
- len(file_path) >= 3 and (file_path[1:3] == ":/" or file_path[1:3] == ":\\") or # Windows absolute path don't count as absolute on unix, have to handle them myself
- file_path[0] == "/" or file_path[0] == "\\"): # and vice versa
+def createLocalPath(rfile, prefixdirectory, prefixpath, forcelocal):
+ filepath = rfile.original_path
+ prefixpath = os.path.normpath(prefixpath) if prefixpath else None
+ if (os.path.isabs(filepath) or
+ filepath[1:3] == ":/" or filepath[1:3] == ":\\" or # Windows absolute path don't count as absolute on unix, have to handle them ourself
+ filepath[:1] == "/" or filepath[:1] == "\\"): # and vice versa
# if an absolute path, make sure path exists, if it doesn't, use relative local path
- full_path = file_path
- if force or not os.path.exists(full_path):
- p, n = os.path.split(os.path.normpath(full_path))
-
- if prefix_path and p.startswith(prefix_path):
- if len(prefix_path) < len(p):
- directory = os.path.join(prefix_directory, p[len(prefix_path)+1:]) # +1 to remove separator
- if not os.path.exists(directory):
- os.mkdir(directory)
- else:
- directory = prefix_directory
- full_path = os.path.join(directory, n)
+ finalpath = filepath
+ if forcelocal or not os.path.exists(finalpath):
+ path, name = os.path.split(os.path.normpath(finalpath))
+
+ # Don't add signatures to cache files, relink fails otherwise
+ if not name.endswith(".bphys") and not name.endswith(".bobj.gz"):
+ name, ext = os.path.splitext(name)
+ name = name + "_" + rfile.signature + ext
+
+ if prefixpath and path.startswith(prefixpath):
+ suffix = ""
+ while path != prefixpath:
+ path, last = os.path.split(path)
+ suffix = os.path.join(last, suffix)
+
+ directory = os.path.join(prefixdirectory, suffix)
+
+ if not os.path.exists(directory):
+ os.mkdir(directory)
+
+ finalpath = os.path.join(directory, name)
else:
- full_path = os.path.join(prefix_directory, n)
+ finalpath = os.path.join(prefixdirectory, name)
else:
- full_path = os.path.join(prefix_directory, file_path)
+ directory, name = os.path.split(filepath)
+
+ # Don't add signatures to cache files
+ if not name.endswith(".bphys") and not name.endswith(".bobj.gz"):
+ name, ext = os.path.splitext(name)
+ name = name + "_" + rfile.signature + ext
+
+ directory = directory.replace("../")
+ directory = os.path.join(prefixdirectory, directory)
+
+ if not os.path.exists(directory):
+ os.mkdir(directory)
+
+ finalpath = os.path.join(directory, name)
- return full_path
+ return finalpath
def getResults(server_address, server_port, job_id, resolution_x, resolution_y, resolution_percentage, frame_ranges):
if bpy.app.debug: