2009-11-01 15:21:20 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2009-12-29 00:04:57 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2009-12-29 00:04:57 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-01 15:21:20 +00:00
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
import sys, os
|
2009-09-04 01:33:22 +00:00
|
|
|
import re
|
2009-11-18 17:07:42 +00:00
|
|
|
import http, http.client, http.server, urllib, socket
|
2010-04-28 01:54:12 +00:00
|
|
|
import subprocess, shutil, time, hashlib, zlib
|
2009-08-29 17:25:22 +00:00
|
|
|
|
2009-09-01 01:09:05 +00:00
|
|
|
import netrender.model
|
2009-08-29 17:25:22 +00:00
|
|
|
|
2009-11-18 17:07:42 +00:00
|
|
|
try:
|
|
|
|
import bpy
|
|
|
|
except:
|
|
|
|
bpy = None
|
|
|
|
|
2011-02-05 22:46:59 +00:00
|
|
|
VERSION = bytes("1.3", encoding='utf8')
|
2009-08-29 17:25:22 +00:00
|
|
|
|
2009-09-19 22:11:26 +00:00
|
|
|
# Jobs status
|
|
|
|
JOB_WAITING = 0 # before all data has been entered
|
|
|
|
JOB_PAUSED = 1 # paused by user
|
2009-09-23 21:46:29 +00:00
|
|
|
JOB_FINISHED = 2 # finished rendering
|
|
|
|
JOB_QUEUED = 3 # ready to be dispatched
|
2009-09-19 22:11:26 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
JOB_STATUS_TEXT = {
|
|
|
|
JOB_WAITING: "Waiting",
|
|
|
|
JOB_PAUSED: "Paused",
|
|
|
|
JOB_FINISHED: "Finished",
|
|
|
|
JOB_QUEUED: "Queued"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-19 22:11:26 +00:00
|
|
|
# Frames status
|
2009-08-29 17:25:22 +00:00
|
|
|
QUEUED = 0
|
|
|
|
DISPATCHED = 1
|
|
|
|
DONE = 2
|
|
|
|
ERROR = 3
|
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
FRAME_STATUS_TEXT = {
|
2009-12-29 00:04:57 +00:00
|
|
|
QUEUED: "Queued",
|
|
|
|
DISPATCHED: "Dispatched",
|
|
|
|
DONE: "Done",
|
|
|
|
ERROR: "Error"
|
|
|
|
}
|
2009-09-23 01:59:57 +00:00
|
|
|
|
netrender
New Feature:
VCS job type
Render a file (with dependencies) from a version control system (currently only supports subversion, but system is already generic).
On client, working path, server path and current revision can be guessed from data on disk or entered manually.
On slave, a working copy is created (if needed) where specified by the job and updated to the proper revision.
On master web page, job types now appear in the job lists. The job page shows the list of dependencies for "normal" jobs or versioning information for VCS jobs.
Limitations: Need to have command line tools "svn" and "svnversion". Working copy path must be the same on client and slaves (the client gets the job path relative to the working copy). When guessing, working copy path is set to the folder where the current file is (this can be changed manually after). On the slave, it will update the working copy AS SPECIFIED to the revision, so if that path is too deep, some dependencies will not be updated properly. Doesn't support mixed revisions (and will not give any warnings for that), it will always use the first revision specified by "svnversion"
Bugfix:
Thumbnail generation doesn't chew down memory anymore and always gives correct result (thumbnail on master especially could mess up between jobs with the name result filename)
2010-10-27 18:24:58 +00:00
|
|
|
class DirectoryContext:
|
|
|
|
def __init__(self, path):
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.curdir = os.path.abspath(os.curdir)
|
|
|
|
os.chdir(self.path)
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
os.chdir(self.curdir)
|
|
|
|
|
2010-11-14 22:11:56 +00:00
|
|
|
class BreakableIncrementedSleep:
|
|
|
|
def __init__(self, increment, default_timeout, max_timeout, break_fct):
|
|
|
|
self.increment = increment
|
|
|
|
self.default = default_timeout
|
|
|
|
self.max = max_timeout
|
|
|
|
self.current = self.default
|
|
|
|
self.break_fct = break_fct
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.current = self.default
|
|
|
|
|
|
|
|
def increase(self):
|
|
|
|
self.current = min(self.current + self.increment, self.max)
|
|
|
|
|
|
|
|
def sleep(self):
|
|
|
|
for i in range(self.current):
|
|
|
|
time.sleep(1)
|
|
|
|
if self.break_fct():
|
|
|
|
break
|
|
|
|
|
|
|
|
self.increase()
|
|
|
|
|
2010-08-14 16:30:41 +00:00
|
|
|
def responseStatus(conn):
|
|
|
|
response = conn.getresponse()
|
|
|
|
response.read()
|
|
|
|
return response.status
|
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
def reporting(report, message, errorType = None):
|
|
|
|
if errorType:
|
|
|
|
t = 'ERROR'
|
|
|
|
else:
|
|
|
|
t = 'INFO'
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
if report:
|
|
|
|
report(t, message)
|
|
|
|
return None
|
|
|
|
elif errorType:
|
|
|
|
raise errorType(message)
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def clientScan(report = None):
|
|
|
|
try:
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
|
|
|
s.settimeout(30)
|
|
|
|
|
|
|
|
s.bind(('', 8000))
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
buf, address = s.recvfrom(64)
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
address = address[0]
|
|
|
|
port = int(str(buf, encoding='utf8'))
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
reporting(report, "Master server found")
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
return (address, port)
|
|
|
|
except socket.timeout:
|
|
|
|
reporting(report, "No master server on network", IOError)
|
|
|
|
|
|
|
|
return ("", 8000) # return default values
|
|
|
|
|
2011-01-28 00:00:10 +00:00
|
|
|
def clientConnection(address, port, report = None, scan = True, timeout = 5):
|
2009-12-16 21:00:25 +00:00
|
|
|
if address == "[default]":
|
2009-11-18 18:00:46 +00:00
|
|
|
# calling operator from python is fucked, scene isn't in context
|
|
|
|
# if bpy:
|
|
|
|
# bpy.ops.render.netclientscan()
|
|
|
|
# else:
|
2010-01-04 21:05:52 +00:00
|
|
|
if not scan:
|
|
|
|
return None
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-04 21:05:52 +00:00
|
|
|
address, port = clientScan()
|
|
|
|
if address == "":
|
|
|
|
return None
|
2009-12-29 00:04:57 +00:00
|
|
|
|
|
|
|
try:
|
2011-01-28 00:00:10 +00:00
|
|
|
conn = http.client.HTTPConnection(address, port, timeout = timeout)
|
2009-12-29 00:04:57 +00:00
|
|
|
|
2009-12-16 21:00:25 +00:00
|
|
|
if conn:
|
|
|
|
if clientVerifyVersion(conn):
|
|
|
|
return conn
|
|
|
|
else:
|
|
|
|
conn.close()
|
|
|
|
reporting(report, "Incorrect master version", ValueError)
|
2010-11-14 22:11:56 +00:00
|
|
|
except BaseException as err:
|
2009-12-16 21:00:25 +00:00
|
|
|
if report:
|
|
|
|
report('ERROR', str(err))
|
|
|
|
return None
|
|
|
|
else:
|
2010-11-14 22:11:56 +00:00
|
|
|
print(err)
|
|
|
|
return None
|
2009-08-29 17:25:22 +00:00
|
|
|
|
|
|
|
def clientVerifyVersion(conn):
|
2009-12-29 00:04:57 +00:00
|
|
|
conn.request("GET", "/version")
|
|
|
|
response = conn.getresponse()
|
|
|
|
|
|
|
|
if response.status != http.client.OK:
|
|
|
|
conn.close()
|
|
|
|
return False
|
|
|
|
|
|
|
|
server_version = response.read()
|
|
|
|
|
|
|
|
if server_version != VERSION:
|
|
|
|
print("Incorrect server version!")
|
|
|
|
print("expected", str(VERSION, encoding='utf8'), "received", str(server_version, encoding='utf8'))
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2009-08-29 17:25:22 +00:00
|
|
|
|
2009-12-14 23:09:08 +00:00
|
|
|
def fileURL(job_id, file_index):
|
|
|
|
return "/file_%s_%i" % (job_id, file_index)
|
|
|
|
|
|
|
|
def logURL(job_id, frame_number):
|
|
|
|
return "/log_%s_%i.log" % (job_id, frame_number)
|
|
|
|
|
2010-01-08 02:33:20 +00:00
|
|
|
def renderURL(job_id, frame_number):
|
|
|
|
return "/render_%s_%i.exr" % (job_id, frame_number)
|
2009-12-14 23:09:08 +00:00
|
|
|
|
2009-12-15 18:09:01 +00:00
|
|
|
def cancelURL(job_id):
|
|
|
|
return "/cancel_%s" % (job_id)
|
|
|
|
|
2010-04-28 01:54:12 +00:00
|
|
|
def hashFile(path):
|
|
|
|
f = open(path, "rb")
|
|
|
|
value = hashData(f.read())
|
|
|
|
f.close()
|
|
|
|
return value
|
|
|
|
|
|
|
|
def hashData(data):
|
|
|
|
m = hashlib.md5()
|
|
|
|
m.update(data)
|
|
|
|
return m.hexdigest()
|
|
|
|
|
|
|
|
|
2010-05-02 21:34:08 +00:00
|
|
|
def prefixPath(prefix_directory, file_path, prefix_path, force = False):
|
2011-01-28 00:45:53 +00:00
|
|
|
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
|
|
|
|
|
2009-12-29 00:04:57 +00:00
|
|
|
# if an absolute path, make sure path exists, if it doesn't, use relative local path
|
|
|
|
full_path = file_path
|
2010-05-02 21:34:08 +00:00
|
|
|
if force or not os.path.exists(full_path):
|
2010-07-17 18:40:00 +00:00
|
|
|
p, n = os.path.split(os.path.normpath(full_path))
|
2009-12-29 00:04:57 +00:00
|
|
|
|
|
|
|
if prefix_path and p.startswith(prefix_path):
|
2010-05-02 21:34:08 +00:00
|
|
|
if len(prefix_path) < len(p):
|
2010-08-14 16:30:41 +00:00
|
|
|
directory = os.path.join(prefix_directory, p[len(prefix_path)+1:]) # +1 to remove separator
|
2010-05-02 21:34:08 +00:00
|
|
|
if not os.path.exists(directory):
|
|
|
|
os.mkdir(directory)
|
|
|
|
else:
|
|
|
|
directory = prefix_directory
|
2010-08-14 16:30:41 +00:00
|
|
|
full_path = os.path.join(directory, n)
|
2009-12-29 00:04:57 +00:00
|
|
|
else:
|
2010-08-14 16:30:41 +00:00
|
|
|
full_path = os.path.join(prefix_directory, n)
|
2009-12-29 00:04:57 +00:00
|
|
|
else:
|
2010-12-27 18:53:34 +00:00
|
|
|
full_path = os.path.join(prefix_directory, file_path)
|
2009-12-29 00:04:57 +00:00
|
|
|
|
|
|
|
return full_path
|
2010-01-09 18:21:27 +00:00
|
|
|
|
2011-01-08 19:42:26 +00:00
|
|
|
def getResults(server_address, server_port, job_id, resolution_x, resolution_y, resolution_percentage, frame_ranges):
|
2011-02-05 22:46:59 +00:00
|
|
|
if bpy.app.debug:
|
|
|
|
print("=============================================")
|
|
|
|
print("============= FETCHING RESULTS ==============")
|
|
|
|
|
2011-01-08 19:42:26 +00:00
|
|
|
frame_arguments = []
|
|
|
|
for r in frame_ranges:
|
|
|
|
if len(r) == 2:
|
|
|
|
frame_arguments.extend(["-s", str(r[0]), "-e", str(r[1]), "-a"])
|
|
|
|
else:
|
|
|
|
frame_arguments.extend(["-f", str(r[0])])
|
|
|
|
|
|
|
|
filepath = os.path.join(bpy.app.tempdir, "netrender_temp.blend")
|
|
|
|
bpy.ops.wm.save_as_mainfile(filepath=filepath, copy=True, check_existing=False)
|
2011-02-05 22:46:59 +00:00
|
|
|
|
|
|
|
arguments = [sys.argv[0], "-b", "-noaudio", filepath, "-o", bpy.path.abspath(bpy.context.scene.render.filepath), "-P", __file__] + frame_arguments + ["--", "GetResults", server_address, str(server_port), job_id, str(resolution_x), str(resolution_y), str(resolution_percentage)]
|
|
|
|
if bpy.app.debug:
|
|
|
|
print("Starting subprocess:")
|
|
|
|
print(" ".join(arguments))
|
|
|
|
|
|
|
|
process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
2011-01-08 19:42:26 +00:00
|
|
|
while process.poll() is None:
|
2011-02-05 22:46:59 +00:00
|
|
|
stdout = process.stdout.read(1024)
|
|
|
|
if bpy.app.debug:
|
|
|
|
print(str(stdout, encoding='utf-8'), end="")
|
|
|
|
|
|
|
|
|
|
|
|
# read leftovers if needed
|
|
|
|
stdout = process.stdout.read()
|
|
|
|
if bpy.app.debug:
|
|
|
|
print(str(stdout, encoding='utf-8'))
|
2011-01-08 19:42:26 +00:00
|
|
|
|
|
|
|
os.remove(filepath)
|
|
|
|
|
2011-02-05 22:46:59 +00:00
|
|
|
if bpy.app.debug:
|
|
|
|
print("=============================================")
|
2011-01-08 19:42:26 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def _getResults(server_address, server_port, job_id, resolution_x, resolution_y, resolution_percentage):
|
|
|
|
render = bpy.context.scene.render
|
|
|
|
|
|
|
|
netsettings = bpy.context.scene.network_render
|
|
|
|
|
|
|
|
netsettings.server_address = server_address
|
|
|
|
netsettings.server_port = int(server_port)
|
|
|
|
netsettings.job_id = job_id
|
|
|
|
|
|
|
|
render.engine = 'NET_RENDER'
|
|
|
|
render.resolution_x = int(resolution_x)
|
|
|
|
render.resolution_y = int(resolution_y)
|
|
|
|
render.resolution_percentage = int(resolution_percentage)
|
2011-01-30 22:15:50 +00:00
|
|
|
|
|
|
|
render.use_full_sample = False
|
|
|
|
render.use_compositing = False
|
|
|
|
render.use_border = False
|
2011-01-08 19:42:26 +00:00
|
|
|
|
|
|
|
|
2010-01-25 21:10:33 +00:00
|
|
|
def getFileInfo(filepath, infos):
|
2011-01-08 19:42:26 +00:00
|
|
|
process = subprocess.Popen([sys.argv[0], "-b", "-noaudio", filepath, "-P", __file__, "--", "FileInfo"] + infos, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
2010-01-25 21:10:33 +00:00
|
|
|
stdout = bytes()
|
2010-09-18 10:43:32 +00:00
|
|
|
while process.poll() is None:
|
2010-01-25 21:10:33 +00:00
|
|
|
stdout += process.stdout.read(1024)
|
|
|
|
|
|
|
|
# read leftovers if needed
|
|
|
|
stdout += process.stdout.read()
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-25 21:10:33 +00:00
|
|
|
stdout = str(stdout, encoding="utf8")
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-25 21:10:33 +00:00
|
|
|
values = [eval(v[1:].strip()) for v in stdout.split("\n") if v.startswith("$")]
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-25 21:10:33 +00:00
|
|
|
return values
|
2011-01-08 19:42:26 +00:00
|
|
|
|
2010-01-31 14:46:28 +00:00
|
|
|
|
2010-01-25 21:10:33 +00:00
|
|
|
if __name__ == "__main__":
|
2010-12-29 18:34:43 +00:00
|
|
|
try:
|
|
|
|
start = sys.argv.index("--") + 1
|
|
|
|
except ValueError:
|
|
|
|
start = 0
|
2011-01-08 19:42:26 +00:00
|
|
|
action, *args = sys.argv[start:]
|
|
|
|
|
|
|
|
if action == "FileInfo":
|
|
|
|
for info in args:
|
|
|
|
print("$", eval(info))
|
|
|
|
elif action == "GetResults":
|
|
|
|
_getResults(args[0], args[1], args[2], args[3], args[4], args[5])
|