1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
26 from netrender
.utils
import *
30 main_file
= job
.files
[0]
32 job_full_path
= main_file
.filepath
34 if os
.path
.exists(job_full_path
+ ".bak"):
35 os
.remove(job_full_path
) # repathed file
36 os
.renames(job_full_path
+ ".bak", job_full_path
)
41 main_file
= job
.files
[0]
43 job_full_path
= main_file
.filepath
46 path
, ext
= os
.path
.splitext(job_full_path
)
48 new_path
= path
+ ".remap" + ext
50 original_path
= main_file
.original_path
52 # Disable for now. Partial repath should work anyway
53 #all = main_file.filepath != main_file.original_path
56 for rfile
in job
.files
[1:]:
57 if all
or rfile
.original_path
!= rfile
.filepath
:
58 paths
.append(rfile
.original_path
)
59 paths
.append(rfile
.filepath
)
61 # Only update if needed
63 process
= subprocess
.Popen(
75 stderr
=subprocess
.STDOUT
,
79 os
.renames(job_full_path
, job_full_path
+ ".bak")
80 os
.renames(new_path
, job_full_path
)
82 def process(original_path
, paths
):
83 if DEBUG
: print("==========================================================")
84 original_directory
= os
.path
.dirname(original_path
)
86 for i
in range(0, len(paths
), 2):
87 # special case for point cache
88 if paths
[i
].endswith(".bphys"):
89 path
, filename
= os
.path
.split(paths
[i
+1])
90 cache_name
= filename
.split("_")[0]
91 if DEBUG
: print(cache_name
, path
)
92 path_map
[cache_name
] = path
93 # special case for fluids
94 elif paths
[i
].endswith(".bobj.gz"):
95 if DEBUG
: print(os
.path
.split(paths
[i
])[0], os
.path
.split(paths
[i
+1])[0])
96 path_map
[os
.path
.split(paths
[i
])[0]] = os
.path
.split(paths
[i
+1])[0]
98 if DEBUG
: print(paths
[i
], paths
[i
+1])
99 path_map
[paths
[i
]] = paths
[i
+1]
101 if DEBUG
: print("----------------------------------------------------------")
103 # TODO original paths aren't really the original path, they are the normalized path
104 # so we repath using the filenames only.
106 ###########################
108 ###########################
109 for lib
in bpy
.data
.libraries
:
110 file_path
= bpy
.path
.abspath(lib
.filepath
, start
=original_directory
)
111 new_path
= path_map
.get(file_path
, None)
112 if DEBUG
: print(file_path
, new_path
)
114 lib
.filepath
= new_path
116 ###########################
118 ###########################
119 for image
in bpy
.data
.images
:
120 if image
.source
== "FILE" and not image
.packed_file
:
121 file_path
= bpy
.path
.abspath(image
.filepath
, start
=original_directory
)
122 new_path
= path_map
.get(file_path
, None)
123 if DEBUG
: print(file_path
, new_path
)
125 image
.filepath
= new_path
128 ###########################
129 # FLUID + POINT CACHE
130 ###########################
131 def pointCacheFunc(object, owner
, point_cache
):
132 if not point_cache
.use_disk_cache
:
135 cache_name
= cacheName(object, point_cache
)
136 new_path
= path_map
.get(cache_name
, None)
137 if DEBUG
: print(cache_name
, new_path
)
139 point_cache
.use_external
= True
140 point_cache
.filepath
= new_path
141 point_cache
.name
= cache_name
143 def fluidFunc(object, modifier
, cache_path
):
144 fluid
= modifier
.settings
145 new_path
= path_map
.get(cache_path
, None)
147 fluid
.path
= new_path
149 def multiresFunc(object, modifier
, cache_path
):
150 new_path
= path_map
.get(cache_path
, None)
152 modifier
.filepath
= new_path
154 processObjectDependencies(pointCacheFunc
, fluidFunc
, multiresFunc
)
155 if DEBUG
: print("==========================================================")
158 if __name__
== "__main__":
160 i
= sys
.argv
.index("--")
165 new_path
, original_path
, *args
= sys
.argv
[i
+1:]
167 process(original_path
, args
)
169 bpy
.ops
.wm
.save_as_mainfile(filepath
=new_path
, check_existing
=False)