Merge with -r 22620:23107.
[blender.git] / release / io / netrender / ui.py
1 import bpy
2 import sys, os
3 import http, http.client, http.server, urllib
4 import subprocess, shutil, time, hashlib
5
6 import netrender.slave as slave
7 import netrender.master as master
8
9 from netrender.utils import *
10
11 VERSION = b"0.3"
12
13 PATH_PREFIX = "/tmp/"
14
15 QUEUED = 0
16 DISPATCHED = 1
17 DONE = 2
18 ERROR = 3
19
20 class RenderButtonsPanel(bpy.types.Panel):
21         __space_type__ = "PROPERTIES"
22         __region_type__ = "WINDOW"
23         __context__ = "scene"
24         # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
25         
26         def poll(self, context):
27                 rd = context.scene.render_data
28                 return (rd.use_game_engine==False) and (rd.engine in self.COMPAT_ENGINES)
29
30 # Setting panel, use in the scene for now.
31 class SCENE_PT_network_settings(RenderButtonsPanel):
32         __label__ = "Network Settings"
33         COMPAT_ENGINES = set(['NET_RENDER'])
34
35         def draw_header(self, context):
36                 layout = self.layout
37                 scene = context.scene
38
39         def draw(self, context):
40                 layout = self.layout
41                 scene = context.scene
42                 rd = scene.render_data
43                 
44                 layout.active = True
45                 
46                 split = layout.split()
47                 
48                 col = split.column()
49                 
50                 col.itemR(scene.network_render, "mode")
51                 col.itemR(scene.network_render, "server_address")
52                 col.itemR(scene.network_render, "server_port")
53                 col.itemR(scene.network_render, "path")
54                 
55                 if scene.network_render.mode == "RENDER_CLIENT":
56                         col.itemR(scene.network_render, "chunks")
57                         col.itemR(scene.network_render, "priority")
58                         col.itemR(scene.network_render, "job_name")
59                         col.itemO("render.netclientsend", text="send job to server")
60 bpy.types.register(SCENE_PT_network_settings)
61
62 class SCENE_PT_network_slaves(RenderButtonsPanel):
63         __label__ = "Slaves Status"
64         COMPAT_ENGINES = set(['NET_RENDER'])
65         
66         def poll(self, context):
67                 scene = context.scene
68                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
69
70         def draw(self, context):
71                 layout = self.layout
72                 
73                 scene = context.scene
74                 netsettings = scene.network_render
75
76                 row = layout.row()
77                 row.template_list(netsettings, "slaves", netsettings, "active_slave_index", rows=2)
78
79                 col = row.column()
80
81                 subcol = col.column(align=True)
82                 subcol.itemO("render.netclientslaves", icon="ICON_FILE_REFRESH", text="")
83                 subcol.itemO("render.netclientblacklistslave", icon="ICON_ZOOMOUT", text="")
84                 
85                 if len(bpy.data.netrender_slaves) == 0 and len(netsettings.slaves) > 0:
86                         while(len(netsettings.slaves) > 0):
87                                 netsettings.slaves.remove(0)
88                 
89                 if netsettings.active_slave_index >= 0 and len(netsettings.slaves) > 0:
90                         layout.itemS()
91                         
92                         slave = bpy.data.netrender_slaves[netsettings.active_slave_index]
93
94                         layout.itemL(text="Name: " + slave.name)
95                         layout.itemL(text="Address: " + slave.address[0])
96                         layout.itemL(text="Seen: " + time.ctime(slave.last_seen))
97                         layout.itemL(text="Stats: " + slave.stats)
98
99 bpy.types.register(SCENE_PT_network_slaves)
100
101 class SCENE_PT_network_slaves_blacklist(RenderButtonsPanel):
102         __label__ = "Slaves Blacklist"
103         COMPAT_ENGINES = set(['NET_RENDER'])
104         
105         def poll(self, context):
106                 scene = context.scene
107                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
108         
109         def draw(self, context):
110                 layout = self.layout
111                 
112                 scene = context.scene
113                 netsettings = scene.network_render
114
115                 row = layout.row()
116                 row.template_list(netsettings, "slaves_blacklist", netsettings, "active_blacklisted_slave_index", rows=2)
117
118                 col = row.column()
119
120                 subcol = col.column(align=True)
121                 subcol.itemO("render.netclientwhitelistslave", icon="ICON_ZOOMOUT", text="")
122
123                 if len(bpy.data.netrender_blacklist) == 0 and len(netsettings.slaves_blacklist) > 0:
124                         while(len(netsettings.slaves_blacklist) > 0):
125                                 netsettings.slaves_blacklist.remove(0)
126                 
127                 if netsettings.active_blacklisted_slave_index >= 0 and len(netsettings.slaves_blacklist) > 0:
128                         layout.itemS()
129                         
130                         slave = bpy.data.netrender_blacklist[netsettings.active_blacklisted_slave_index]
131
132                         layout.itemL(text="Name: " + slave.name)
133                         layout.itemL(text="Address: " + slave.address[0])
134                         layout.itemL(text="Seen: " + slave.last_seen)
135                         layout.itemL(text="Stats: " + time.ctime(slave.stats))
136                         
137 bpy.types.register(SCENE_PT_network_slaves_blacklist)
138
139 class SCENE_PT_network_jobs(RenderButtonsPanel):
140         __label__ = "Jobs"
141         COMPAT_ENGINES = set(['NET_RENDER'])
142         
143         def poll(self, context):
144                 scene = context.scene
145                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
146         
147         def draw(self, context):
148                 layout = self.layout
149                 
150                 scene = context.scene
151                 netsettings = scene.network_render
152
153                 row = layout.row()
154                 row.template_list(netsettings, "jobs", netsettings, "active_job_index", rows=2)
155
156                 col = row.column()
157
158                 subcol = col.column(align=True)
159                 subcol.itemO("render.netclientstatus", icon="ICON_FILE_REFRESH", text="")
160                 subcol.itemO("render.netclientcancel", icon="ICON_ZOOMOUT", text="")
161
162                 if len(bpy.data.netrender_jobs) == 0 and len(netsettings.jobs) > 0:
163                         while(len(netsettings.jobs) > 0):
164                                 netsettings.jobs.remove(0)
165                 
166                 if netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0:
167                         layout.itemS()
168                         
169                         job = bpy.data.netrender_jobs[netsettings.active_job_index]
170
171                         layout.itemL(text="Name: %s" % job.name)
172                         layout.itemL(text="Length: %04i" % len(job))
173                         layout.itemL(text="Done: %04i" % job.results[DONE])
174                         layout.itemL(text="Error: %04i" % job.results[ERROR])
175                         
176 bpy.types.register(SCENE_PT_network_jobs)
177
178 class NetRenderSettings(bpy.types.IDPropertyGroup):
179         pass
180
181 class NetRenderSlave(bpy.types.IDPropertyGroup):
182         pass
183
184 class NetRenderJob(bpy.types.IDPropertyGroup):
185         pass
186
187 bpy.types.register(NetRenderSettings)
188 bpy.types.register(NetRenderSlave)
189 bpy.types.register(NetRenderJob)
190
191 bpy.types.Scene.PointerProperty(attr="network_render", type=NetRenderSettings, name="Network Render", description="Network Render Settings")
192
193 NetRenderSettings.StringProperty( attr="server_address",
194                                 name="Server address",
195                                 description="IP or name of the master render server",
196                                 maxlen = 128,
197                                 default = "127.0.0.1")
198
199 NetRenderSettings.IntProperty( attr="server_port",
200                                 name="Server port",
201                                 description="port of the master render server",
202                                 default = 8000,
203                                 min=1,
204                                 max=65535)
205
206 NetRenderSettings.StringProperty( attr="path",
207                                 name="Path",
208                                 description="Path for temporary files",
209                                 maxlen = 128,
210                                 default = "/tmp/")
211
212 NetRenderSettings.StringProperty( attr="job_name",
213                                 name="Job name",
214                                 description="Name of the job",
215                                 maxlen = 128,
216                                 default = "[default]")
217
218 NetRenderSettings.IntProperty( attr="chunks",
219                                 name="Chunks",
220                                 description="Number of frame to dispatch to each slave in one chunk",
221                                 default = 5,
222                                 min=1,
223                                 max=65535)
224
225 NetRenderSettings.IntProperty( attr="priority",
226                                 name="Priority",
227                                 description="Priority of the job",
228                                 default = 1,
229                                 min=1,
230                                 max=10)
231
232 NetRenderSettings.StringProperty( attr="job_id",
233                                 name="Network job id",
234                                 description="id of the last sent render job",
235                                 maxlen = 64,
236                                 default = "")
237
238 NetRenderSettings.IntProperty( attr="active_slave_index",
239                                 name="Index of the active slave",
240                                 description="",
241                                 default = -1,
242                                 min= -1,
243                                 max=65535)
244
245 NetRenderSettings.IntProperty( attr="active_blacklisted_slave_index",
246                                 name="Index of the active slave",
247                                 description="",
248                                 default = -1,
249                                 min= -1,
250                                 max=65535)
251
252 NetRenderSettings.IntProperty( attr="active_job_index",
253                                 name="Index of the active job",
254                                 description="",
255                                 default = -1,
256                                 min= -1,
257                                 max=65535)
258
259 NetRenderSettings.EnumProperty(attr="mode",
260                                                 items=(
261                                                                                 ("RENDER_CLIENT", "Client", "Act as render client"),
262                                                                                 ("RENDER_MASTER", "Master", "Act as render master"),
263                                                                                 ("RENDER_SLAVE", "Slave", "Act as render slave"),
264                                                                         ),
265                                                 name="network mode",
266                                                 description="mode of operation of this instance",
267                                                 default="RENDER_CLIENT")
268
269 NetRenderSettings.CollectionProperty(attr="slaves", type=NetRenderSlave, name="Slaves", description="")
270 NetRenderSettings.CollectionProperty(attr="slaves_blacklist", type=NetRenderSlave, name="Slaves Blacklist", description="")
271 NetRenderSettings.CollectionProperty(attr="jobs", type=NetRenderJob, name="Job List", description="")
272
273 NetRenderSlave.StringProperty( attr="name",
274                                 name="Name of the slave",
275                                 description="",
276                                 maxlen = 64,
277                                 default = "")
278
279 NetRenderJob.StringProperty( attr="name",
280                                 name="Name of the job",
281                                 description="",
282                                 maxlen = 128,
283                                 default = "")