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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
import sys, os
|
|
|
|
import http, http.client, http.server, urllib
|
|
|
|
import subprocess, shutil, time, hashlib
|
|
|
|
|
|
|
|
from netrender.utils import *
|
|
|
|
|
2009-09-18 03:29:50 +00:00
|
|
|
class LogFile:
|
|
|
|
def __init__(self, job_id = 0, frames = []):
|
|
|
|
self.job_id = job_id
|
|
|
|
self.frames = frames
|
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return {
|
|
|
|
"job_id": self.job_id,
|
|
|
|
"frames": self.frames
|
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def materialize(data):
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
logfile = LogFile()
|
|
|
|
logfile.job_id = data["job_id"]
|
|
|
|
logfile.frames = data["frames"]
|
|
|
|
|
|
|
|
return logfile
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
class RenderSlave:
|
|
|
|
_slave_map = {}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.id = ""
|
|
|
|
self.name = ""
|
2009-09-23 01:59:57 +00:00
|
|
|
self.address = ("",0)
|
2009-08-29 17:25:22 +00:00
|
|
|
self.stats = ""
|
|
|
|
self.total_done = 0
|
|
|
|
self.total_error = 0
|
|
|
|
self.last_seen = 0.0
|
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return {
|
|
|
|
"id": self.id,
|
|
|
|
"name": self.name,
|
2009-09-01 01:09:05 +00:00
|
|
|
"address": self.address,
|
2009-08-29 17:25:22 +00:00
|
|
|
"stats": self.stats,
|
|
|
|
"total_done": self.total_done,
|
|
|
|
"total_error": self.total_error,
|
|
|
|
"last_seen": self.last_seen
|
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def materialize(data):
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
slave_id = data["id"]
|
|
|
|
|
|
|
|
if slave_id in RenderSlave._slave_map:
|
|
|
|
return RenderSlave._slave_map[slave_id]
|
|
|
|
else:
|
|
|
|
slave = RenderSlave()
|
|
|
|
slave.id = slave_id
|
|
|
|
slave.name = data["name"]
|
2009-09-01 01:09:05 +00:00
|
|
|
slave.address = data["address"]
|
2009-08-29 17:25:22 +00:00
|
|
|
slave.stats = data["stats"]
|
|
|
|
slave.total_done = data["total_done"]
|
|
|
|
slave.total_error = data["total_error"]
|
|
|
|
slave.last_seen = data["last_seen"]
|
|
|
|
|
|
|
|
RenderSlave._slave_map[slave_id] = slave
|
|
|
|
|
|
|
|
return slave
|
|
|
|
|
2009-10-01 18:57:22 +00:00
|
|
|
JOB_BLENDER = 1
|
|
|
|
JOB_PROCESS = 2
|
|
|
|
|
|
|
|
JOB_TYPES = {
|
|
|
|
JOB_BLENDER: "Blender",
|
|
|
|
JOB_PROCESS: "Process"
|
|
|
|
}
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
class RenderJob:
|
|
|
|
def __init__(self):
|
|
|
|
self.id = ""
|
2009-10-01 18:57:22 +00:00
|
|
|
self.type = JOB_BLENDER
|
2009-08-29 17:25:22 +00:00
|
|
|
self.name = ""
|
2009-09-01 01:09:05 +00:00
|
|
|
self.files = []
|
2009-08-29 17:25:22 +00:00
|
|
|
self.frames = []
|
|
|
|
self.chunks = 0
|
|
|
|
self.priority = 0
|
2009-09-24 21:05:54 +00:00
|
|
|
self.usage = 0.0
|
2009-08-29 17:25:22 +00:00
|
|
|
self.blacklist = []
|
|
|
|
self.last_dispatched = 0.0
|
|
|
|
|
2009-09-09 02:25:14 +00:00
|
|
|
def addFile(self, file_path, start=-1, end=-1):
|
|
|
|
self.files.append((file_path, start, end))
|
|
|
|
|
2009-10-01 18:57:22 +00:00
|
|
|
def addFrame(self, frame_number, command = ""):
|
|
|
|
frame = RenderFrame(frame_number, command)
|
2009-09-01 01:09:05 +00:00
|
|
|
self.frames.append(frame)
|
|
|
|
return frame
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
def __len__(self):
|
|
|
|
return len(self.frames)
|
|
|
|
|
2009-09-19 22:11:26 +00:00
|
|
|
def countFrames(self, status=QUEUED):
|
|
|
|
total = 0
|
2009-09-21 16:01:31 +00:00
|
|
|
for f in self.frames:
|
|
|
|
if f.status == status:
|
2009-09-19 22:11:26 +00:00
|
|
|
total += 1
|
|
|
|
|
|
|
|
return total
|
|
|
|
|
|
|
|
def countSlaves(self):
|
|
|
|
return len(set((frame.slave for frame in self.frames if frame.status == DISPATCHED)))
|
|
|
|
|
2009-08-30 02:40:42 +00:00
|
|
|
def framesStatus(self):
|
2009-08-29 17:25:22 +00:00
|
|
|
results = {
|
|
|
|
QUEUED: 0,
|
|
|
|
DISPATCHED: 0,
|
|
|
|
DONE: 0,
|
|
|
|
ERROR: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for frame in self.frames:
|
|
|
|
results[frame.status] += 1
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
|
|
|
def __contains__(self, frame_number):
|
|
|
|
for f in self.frames:
|
|
|
|
if f.number == frame_number:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def __getitem__(self, frame_number):
|
|
|
|
for f in self.frames:
|
|
|
|
if f.number == frame_number:
|
|
|
|
return f
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def serialize(self, frames = None):
|
2009-09-09 02:25:14 +00:00
|
|
|
min_frame = min((f.number for f in frames)) if frames else -1
|
|
|
|
max_frame = max((f.number for f in frames)) if frames else -1
|
2009-08-29 17:25:22 +00:00
|
|
|
return {
|
|
|
|
"id": self.id,
|
2009-10-01 18:57:22 +00:00
|
|
|
"type": self.type,
|
2009-08-29 17:25:22 +00:00
|
|
|
"name": self.name,
|
2009-10-09 01:52:57 +00:00
|
|
|
"files": [f for f in self.files if f[1] == -1 or not frames or (f[1] <= max_frame and f[2] >= min_frame)],
|
2009-08-29 17:25:22 +00:00
|
|
|
"frames": [f.serialize() for f in self.frames if not frames or f in frames],
|
2009-09-01 01:09:05 +00:00
|
|
|
"chunks": self.chunks,
|
2009-08-29 17:25:22 +00:00
|
|
|
"priority": self.priority,
|
2009-09-24 21:05:54 +00:00
|
|
|
"usage": self.usage,
|
2009-08-29 17:25:22 +00:00
|
|
|
"blacklist": self.blacklist,
|
|
|
|
"last_dispatched": self.last_dispatched
|
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def materialize(data):
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
job = RenderJob()
|
|
|
|
job.id = data["id"]
|
2009-10-01 18:57:22 +00:00
|
|
|
job.type = data["type"]
|
2009-08-29 17:25:22 +00:00
|
|
|
job.name = data["name"]
|
2009-09-01 01:09:05 +00:00
|
|
|
job.files = data["files"]
|
2009-08-29 17:25:22 +00:00
|
|
|
job.frames = [RenderFrame.materialize(f) for f in data["frames"]]
|
2009-09-01 01:09:05 +00:00
|
|
|
job.chunks = data["chunks"]
|
2009-08-29 17:25:22 +00:00
|
|
|
job.priority = data["priority"]
|
2009-09-24 21:05:54 +00:00
|
|
|
job.usage = data["usage"]
|
2009-08-29 17:25:22 +00:00
|
|
|
job.blacklist = data["blacklist"]
|
|
|
|
job.last_dispatched = data["last_dispatched"]
|
|
|
|
|
|
|
|
return job
|
|
|
|
|
|
|
|
class RenderFrame:
|
2009-10-01 18:57:22 +00:00
|
|
|
def __init__(self, number = 0, command = ""):
|
2009-09-01 01:09:05 +00:00
|
|
|
self.number = number
|
2009-08-29 17:25:22 +00:00
|
|
|
self.time = 0
|
|
|
|
self.status = QUEUED
|
|
|
|
self.slave = None
|
2009-10-01 18:57:22 +00:00
|
|
|
self.command = command
|
2009-08-29 17:25:22 +00:00
|
|
|
|
2009-09-23 01:59:57 +00:00
|
|
|
def statusText(self):
|
|
|
|
return STATUS_TEXT[self.status]
|
|
|
|
|
2009-08-29 17:25:22 +00:00
|
|
|
def serialize(self):
|
|
|
|
return {
|
|
|
|
"number": self.number,
|
|
|
|
"time": self.time,
|
|
|
|
"status": self.status,
|
2009-10-01 18:57:22 +00:00
|
|
|
"slave": None if not self.slave else self.slave.serialize(),
|
|
|
|
"command": self.command
|
2009-08-29 17:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def materialize(data):
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
frame = RenderFrame()
|
|
|
|
frame.number = data["number"]
|
|
|
|
frame.time = data["time"]
|
|
|
|
frame.status = data["status"]
|
|
|
|
frame.slave = RenderSlave.materialize(data["slave"])
|
2009-10-01 18:57:22 +00:00
|
|
|
frame.command = data["command"]
|
2009-08-29 17:25:22 +00:00
|
|
|
|
|
|
|
return frame
|