[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2990] trunk/py/scripts/addons/ netrender: netrender

Martin Poirier theeth at yahoo.com
Sun Feb 12 20:32:31 CET 2012


Revision: 2990
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2990
Author:   theeth
Date:     2012-02-12 19:32:24 +0000 (Sun, 12 Feb 2012)
Log Message:
-----------
netrender

change to the repatching and local naming algorithms to better support different files with same name and dependency folder hierarchies.

Modified Paths:
--------------
    trunk/py/scripts/addons/netrender/master.py
    trunk/py/scripts/addons/netrender/repath.py
    trunk/py/scripts/addons/netrender/slave.py
    trunk/py/scripts/addons/netrender/utils.py

Modified: trunk/py/scripts/addons/netrender/master.py
===================================================================
--- trunk/py/scripts/addons/netrender/master.py	2012-02-12 15:42:38 UTC (rev 2989)
+++ trunk/py/scripts/addons/netrender/master.py	2012-02-12 19:32:24 UTC (rev 2990)
@@ -777,15 +777,15 @@
 
                 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 @@
                         
                         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")

Modified: trunk/py/scripts/addons/netrender/repath.py
===================================================================
--- trunk/py/scripts/addons/netrender/repath.py	2012-02-12 15:42:38 UTC (rev 2989)
+++ trunk/py/scripts/addons/netrender/repath.py	2012-02-12 19:32:24 UTC (rev 2990)
@@ -21,6 +21,8 @@
 
 import bpy
 
+DEBUG = False
+
 from netrender.utils import *
 
 BLENDER_PATH = sys.argv[0]
@@ -44,8 +46,10 @@
         
     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
     all = False 
@@ -57,26 +61,33 @@
     
     # 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 @@
     # 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 @@
     ###########################
     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 @@
 
         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 @@
             modifier.filepath = new_path
         
     processObjectDependencies(pointCacheFunc, fluidFunc, multiresFunc)
+    if DEBUG: print("==========================================================")
                 
 
 if __name__ == "__main__":
@@ -135,9 +150,8 @@
         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)

Modified: trunk/py/scripts/addons/netrender/slave.py
===================================================================
--- trunk/py/scripts/addons/netrender/slave.py	2012-02-12 15:42:38 UTC (rev 2989)
+++ trunk/py/scripts/addons/netrender/slave.py	2012-02-12 19:32:24 UTC (rev 2990)
@@ -59,7 +59,7 @@
             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 @@
 
     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 @@
 
 
                 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)

Modified: trunk/py/scripts/addons/netrender/utils.py
===================================================================
--- trunk/py/scripts/addons/netrender/utils.py	2012-02-12 15:42:38 UTC (rev 2989)
+++ trunk/py/scripts/addons/netrender/utils.py	2012-02-12 19:32:24 UTC (rev 2990)
@@ -308,31 +308,55 @@
             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))
+        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)
 
-            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)
+                directory = os.path.join(prefixdirectory, suffix)
+                
+                if not os.path.exists(directory):
+                    os.mkdir(directory)
+
+                finalpath = os.path.join(directory, name)
             else:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list