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 #####
20
import http, http.client, http.server, urllib
21
import subprocess, shutil, time, hashlib
23
from netrender.utils import *
26
def __init__(self, job_id = 0, slave_id = 0, frames = []):
28
self.slave_id = slave_id
33
"job_id": self.job_id,
34
"slave_id": self.slave_id,
39
def materialize(data):
44
logfile.job_id = data["job_id"]
45
logfile.slave_id = data["slave_id"]
46
logfile.frames = data["frames"]
66
"address": self.address,
68
"total_done": self.total_done,
69
"total_error": self.total_error,
70
"last_seen": self.last_seen
74
def materialize(data, cache = True):
80
if cache and slave_id in RenderSlave._slave_map:
81
return RenderSlave._slave_map[slave_id]
85
slave.name = data["name"]
86
slave.address = data["address"]
87
slave.stats = data["stats"]
88
slave.total_done = data["total_done"]
89
slave.total_error = data["total_error"]
90
slave.last_seen = data["last_seen"]
93
RenderSlave._slave_map[slave_id] = slave
101
JOB_BLENDER: "Blender",
102
JOB_PROCESS: "Process"
106
def __init__(self, filepath = "", index = 0, start = -1, end = -1, signature=0):
107
self.filepath = filepath
108
self.original_path = filepath
109
self.signature = signature
116
"filepath": self.filepath,
117
"original_path": self.original_path,
121
"signature": self.signature
125
def materialize(data):
129
rfile = RenderFile(data["filepath"], data["index"], data["start"], data["end"], data["signature"])
130
rfile.original_path = data["original_path"]
135
def __init__(self, job_info = None):
137
self.type = JOB_BLENDER
139
self.category = "None"
140
self.status = JOB_WAITING
147
self.last_dispatched = 0.0
151
self.type = job_info.type
152
self.name = job_info.name
153
self.category = job_info.category
154
self.status = job_info.status
155
self.files = job_info.files
156
self.chunks = job_info.chunks
157
self.priority = job_info.priority
158
self.blacklist = job_info.blacklist
160
def addFile(self, file_path, start=-1, end=-1):
161
signature = hashFile(file_path)
162
self.files.append(RenderFile(file_path, len(self.files), start, end, signature))
164
def addFrame(self, frame_number, command = ""):
165
frame = RenderFrame(frame_number, command)
166
self.frames.append(frame)
170
return len(self.frames)
172
def countFrames(self, status=QUEUED):
174
for f in self.frames:
175
if f.status == status:
180
def countSlaves(self):
181
return len(set((frame.slave for frame in self.frames if frame.status == DISPATCHED)))
183
def statusText(self):
184
return JOB_STATUS_TEXT[self.status]
186
def framesStatus(self):
194
for frame in self.frames:
195
results[frame.status] += 1
199
def __contains__(self, frame_number):
200
for f in self.frames:
201
if f.number == frame_number:
206
def __getitem__(self, frame_number):
207
for f in self.frames:
208
if f.number == frame_number:
213
def serialize(self, frames = None):
214
min_frame = min((f.number for f in frames)) if frames else -1
215
max_frame = max((f.number for f in frames)) if frames else -1
220
"category": self.category,
221
"status": self.status,
222
"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)],
223
"frames": [f.serialize() for f in self.frames if not frames or f in frames],
224
"chunks": self.chunks,
225
"priority": self.priority,
227
"blacklist": self.blacklist,
228
"last_dispatched": self.last_dispatched
232
def materialize(data):
238
job.type = data["type"]
239
job.name = data["name"]
240
job.category = data["category"]
241
job.status = data["status"]
242
job.files = [RenderFile.materialize(f) for f in data["files"]]
243
job.frames = [RenderFrame.materialize(f) for f in data["frames"]]
244
job.chunks = data["chunks"]
245
job.priority = data["priority"]
246
job.usage = data["usage"]
247
job.blacklist = data["blacklist"]
248
job.last_dispatched = data["last_dispatched"]
253
def __init__(self, number = 0, command = ""):
258
self.command = command
260
def statusText(self):
261
return FRAME_STATUS_TEXT[self.status]
265
"number": self.number,
267
"status": self.status,
268
"slave": None if not self.slave else self.slave.serialize(),
269
"command": self.command
273
def materialize(data):
277
frame = RenderFrame()
278
frame.number = data["number"]
279
frame.time = data["time"]
280
frame.status = data["status"]
281
frame.slave = RenderSlave.materialize(data["slave"])
282
frame.command = data["command"]