diff options
Diffstat (limited to 'release/scripts/io/netrender/model.py')
-rw-r--r-- | release/scripts/io/netrender/model.py | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/release/scripts/io/netrender/model.py b/release/scripts/io/netrender/model.py index cf13fe1e1fa..f541b0c5e1a 100644 --- a/release/scripts/io/netrender/model.py +++ b/release/scripts/io/netrender/model.py @@ -23,13 +23,15 @@ import subprocess, shutil, time, hashlib from netrender.utils import * class LogFile: - def __init__(self, job_id = 0, frames = []): + def __init__(self, job_id = 0, slave_id = 0, frames = []): self.job_id = job_id + self.slave_id = slave_id self.frames = frames def serialize(self): return { "job_id": self.job_id, + "slave_id": self.slave_id, "frames": self.frames } @@ -40,6 +42,7 @@ class LogFile: logfile = LogFile() logfile.job_id = data["job_id"] + logfile.slave_id = data["slave_id"] logfile.frames = data["frames"] return logfile @@ -68,27 +71,28 @@ class RenderSlave: } @staticmethod - def materialize(data): + def materialize(data, cache = True): if not data: return None slave_id = data["id"] - - if slave_id in RenderSlave._slave_map: + + if cache and slave_id in RenderSlave._slave_map: return RenderSlave._slave_map[slave_id] - else: - slave = RenderSlave() - slave.id = slave_id - slave.name = data["name"] - slave.address = data["address"] - slave.stats = data["stats"] - slave.total_done = data["total_done"] - slave.total_error = data["total_error"] - slave.last_seen = data["last_seen"] - + + slave = RenderSlave() + slave.id = slave_id + slave.name = data["name"] + slave.address = data["address"] + slave.stats = data["stats"] + slave.total_done = data["total_done"] + slave.total_error = data["total_error"] + slave.last_seen = data["last_seen"] + + if cache: RenderSlave._slave_map[slave_id] = slave - return slave + return slave JOB_BLENDER = 1 JOB_PROCESS = 2 @@ -98,21 +102,58 @@ JOB_TYPES = { JOB_PROCESS: "Process" } +class RenderFile: + def __init__(self, filepath = "", index = 0, start = -1, end = -1): + self.filepath = filepath + self.index = index + self.start = start + self.end = end + + def serialize(self): + return { + "filepath": self.filepath, + "index": self.index, + "start": self.start, + "end": self.end + } + + @staticmethod + def materialize(data): + if not data: + return None + + rfile = RenderFile(data["filepath"], data["index"], data["start"], data["end"]) + + return rfile + class RenderJob: - def __init__(self): + def __init__(self, job_info = None): self.id = "" self.type = JOB_BLENDER self.name = "" + self.category = "None" + self.status = JOB_WAITING self.files = [] - self.frames = [] self.chunks = 0 self.priority = 0 - self.usage = 0.0 self.blacklist = [] + + self.usage = 0.0 self.last_dispatched = 0.0 - + self.frames = [] + + if job_info: + self.type = job_info.type + self.name = job_info.name + self.category = job_info.category + self.status = job_info.status + self.files = job_info.files + self.chunks = job_info.chunks + self.priority = job_info.priority + self.blacklist = job_info.blacklist + def addFile(self, file_path, start=-1, end=-1): - self.files.append((file_path, start, end)) + self.files.append(RenderFile(file_path, len(self.files), start, end)) def addFrame(self, frame_number, command = ""): frame = RenderFrame(frame_number, command) @@ -133,6 +174,9 @@ class RenderJob: def countSlaves(self): return len(set((frame.slave for frame in self.frames if frame.status == DISPATCHED))) + def statusText(self): + return JOB_STATUS_TEXT[self.status] + def framesStatus(self): results = { QUEUED: 0, @@ -167,7 +211,9 @@ class RenderJob: "id": self.id, "type": self.type, "name": self.name, - "files": [f for f in self.files if f[1] == -1 or not frames or (f[1] <= max_frame and f[2] >= min_frame)], + "category": self.category, + "status": self.status, + "files": [f.serialize() for f in self.files if f.start == -1 or not frames or (f.start <= max_frame and f.end >= min_frame)], "frames": [f.serialize() for f in self.frames if not frames or f in frames], "chunks": self.chunks, "priority": self.priority, @@ -185,7 +231,9 @@ class RenderJob: job.id = data["id"] job.type = data["type"] job.name = data["name"] - job.files = data["files"] + job.category = data["category"] + job.status = data["status"] + job.files = [RenderFile.materialize(f) for f in data["files"]] job.frames = [RenderFrame.materialize(f) for f in data["frames"]] job.chunks = data["chunks"] job.priority = data["priority"] @@ -204,7 +252,7 @@ class RenderFrame: self.command = command def statusText(self): - return STATUS_TEXT[self.status] + return FRAME_STATUS_TEXT[self.status] def serialize(self): return { |