* fix snprintf error with mingw
[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 @rnaType
32 class SCENE_PT_network_settings(RenderButtonsPanel):
33         __label__ = "Network Settings"
34         COMPAT_ENGINES = set(['NET_RENDER'])
35
36         def draw_header(self, context):
37                 layout = self.layout
38                 scene = context.scene
39
40         def draw(self, context):
41                 layout = self.layout
42                 scene = context.scene
43                 rd = scene.render_data
44                 
45                 layout.active = True
46                 
47                 split = layout.split()
48                 
49                 col = split.column()
50                 
51                 if scene.network_render.mode == "RENDER_CLIENT":
52                         col.itemO("render.netclientanim", icon='ICON_RENDER_ANIMATION', text="Animaton on network")
53                         
54                 col.itemR(scene.network_render, "mode")
55                 col.itemR(scene.network_render, "path")
56                 col.itemR(scene.network_render, "server_address")
57                 col.itemR(scene.network_render, "server_port")
58                 
59                 if scene.network_render.mode == "RENDER_MASTER":
60                         col.itemR(scene.network_render, "server_broadcast")
61                 else:
62                         col.itemO("render.netclientscan", icon="ICON_FILE_REFRESH", text="")
63                 
64                 if scene.network_render.mode == "RENDER_CLIENT":
65                         col.itemO("render.netclientsend", text="send job to server")
66                         col.itemR(scene.network_render, "job_name")
67                         col.itemR(scene.network_render, "priority")
68                         col.itemR(scene.network_render, "chunks")
69
70 @rnaType
71 class SCENE_PT_network_slaves(RenderButtonsPanel):
72         __label__ = "Slaves Status"
73         COMPAT_ENGINES = set(['NET_RENDER'])
74         
75         def poll(self, context):
76                 scene = context.scene
77                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
78
79         def draw(self, context):
80                 layout = self.layout
81                 
82                 scene = context.scene
83                 netsettings = scene.network_render
84
85                 row = layout.row()
86                 row.template_list(netsettings, "slaves", netsettings, "active_slave_index", rows=2)
87
88                 col = row.column()
89
90                 subcol = col.column(align=True)
91                 subcol.itemO("render.netclientslaves", icon="ICON_FILE_REFRESH", text="")
92                 subcol.itemO("render.netclientblacklistslave", icon="ICON_ZOOMOUT", text="")
93                 
94                 if len(bpy.data.netrender_slaves) == 0 and len(netsettings.slaves) > 0:
95                         while(len(netsettings.slaves) > 0):
96                                 netsettings.slaves.remove(0)
97                 
98                 if netsettings.active_slave_index >= 0 and len(netsettings.slaves) > 0:
99                         layout.itemS()
100                         
101                         slave = bpy.data.netrender_slaves[netsettings.active_slave_index]
102
103                         layout.itemL(text="Name: " + slave.name)
104                         layout.itemL(text="Address: " + slave.address[0])
105                         layout.itemL(text="Seen: " + time.ctime(slave.last_seen))
106                         layout.itemL(text="Stats: " + slave.stats)
107
108 @rnaType
109 class SCENE_PT_network_slaves_blacklist(RenderButtonsPanel):
110         __label__ = "Slaves Blacklist"
111         COMPAT_ENGINES = set(['NET_RENDER'])
112         
113         def poll(self, context):
114                 scene = context.scene
115                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
116         
117         def draw(self, context):
118                 layout = self.layout
119                 
120                 scene = context.scene
121                 netsettings = scene.network_render
122
123                 row = layout.row()
124                 row.template_list(netsettings, "slaves_blacklist", netsettings, "active_blacklisted_slave_index", rows=2)
125
126                 col = row.column()
127
128                 subcol = col.column(align=True)
129                 subcol.itemO("render.netclientwhitelistslave", icon="ICON_ZOOMOUT", text="")
130
131                 if len(bpy.data.netrender_blacklist) == 0 and len(netsettings.slaves_blacklist) > 0:
132                         while(len(netsettings.slaves_blacklist) > 0):
133                                 netsettings.slaves_blacklist.remove(0)
134                 
135                 if netsettings.active_blacklisted_slave_index >= 0 and len(netsettings.slaves_blacklist) > 0:
136                         layout.itemS()
137                         
138                         slave = bpy.data.netrender_blacklist[netsettings.active_blacklisted_slave_index]
139
140                         layout.itemL(text="Name: " + slave.name)
141                         layout.itemL(text="Address: " + slave.address[0])
142                         layout.itemL(text="Seen: " + slave.last_seen)
143                         layout.itemL(text="Stats: " + time.ctime(slave.stats))
144
145 @rnaType
146 class SCENE_PT_network_jobs(RenderButtonsPanel):
147         __label__ = "Jobs"
148         COMPAT_ENGINES = set(['NET_RENDER'])
149         
150         def poll(self, context):
151                 scene = context.scene
152                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
153         
154         def draw(self, context):
155                 layout = self.layout
156                 
157                 scene = context.scene
158                 netsettings = scene.network_render
159
160                 row = layout.row()
161                 row.template_list(netsettings, "jobs", netsettings, "active_job_index", rows=2)
162
163                 col = row.column()
164
165                 subcol = col.column(align=True)
166                 subcol.itemO("render.netclientstatus", icon="ICON_FILE_REFRESH", text="")
167                 subcol.itemO("render.netclientcancel", icon="ICON_ZOOMOUT", text="")
168                 subcol.itemO("render.netclientcancelall", icon="ICON_ZOOMOUT", text="")
169                 subcol.itemO("render.netclientdownload", icon='ICON_RENDER_ANIMATION', text="")
170
171                 if len(bpy.data.netrender_jobs) == 0 and len(netsettings.jobs) > 0:
172                         while(len(netsettings.jobs) > 0):
173                                 netsettings.jobs.remove(0)
174                 
175                 if netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0:
176                         layout.itemS()
177                         
178                         job = bpy.data.netrender_jobs[netsettings.active_job_index]
179
180                         layout.itemL(text="Name: %s" % job.name)
181                         layout.itemL(text="Length: %04i" % len(job))
182                         layout.itemL(text="Done: %04i" % job.results[DONE])
183                         layout.itemL(text="Error: %04i" % job.results[ERROR])
184
185 @rnaType
186 class NetRenderSettings(bpy.types.IDPropertyGroup):
187         pass
188
189 @rnaType
190 class NetRenderSlave(bpy.types.IDPropertyGroup):
191         pass
192
193 @rnaType
194 class NetRenderJob(bpy.types.IDPropertyGroup):
195         pass
196
197 bpy.types.Scene.PointerProperty(attr="network_render", type=NetRenderSettings, name="Network Render", description="Network Render Settings")
198
199 NetRenderSettings.StringProperty( attr="server_address",
200                                 name="Server address",
201                                 description="IP or name of the master render server",
202                                 maxlen = 128,
203                                 default = "[default]")
204
205 NetRenderSettings.IntProperty( attr="server_port",
206                                 name="Server port",
207                                 description="port of the master render server",
208                                 default = 8000,
209                                 min=1,
210                                 max=65535)
211
212 NetRenderSettings.BoolProperty( attr="server_broadcast",
213                                 name="Broadcast server address",
214                                 description="broadcast server address on local network",
215                                 default = True)
216
217 if os.name == 'nt':
218         NetRenderSettings.StringProperty( attr="path",
219                                         name="Path",
220                                         description="Path for temporary files",
221                                         maxlen = 128,
222                                         default = "C:/tmp/")
223 else:
224         NetRenderSettings.StringProperty( attr="path",
225                                         name="Path",
226                                         description="Path for temporary files",
227                                         maxlen = 128,
228                                         default = "/tmp/")
229
230 NetRenderSettings.StringProperty( attr="job_name",
231                                 name="Job name",
232                                 description="Name of the job",
233                                 maxlen = 128,
234                                 default = "[default]")
235
236 NetRenderSettings.IntProperty( attr="chunks",
237                                 name="Chunks",
238                                 description="Number of frame to dispatch to each slave in one chunk",
239                                 default = 5,
240                                 min=1,
241                                 max=65535)
242
243 NetRenderSettings.IntProperty( attr="priority",
244                                 name="Priority",
245                                 description="Priority of the job",
246                                 default = 1,
247                                 min=1,
248                                 max=10)
249
250 NetRenderSettings.StringProperty( attr="job_id",
251                                 name="Network job id",
252                                 description="id of the last sent render job",
253                                 maxlen = 64,
254                                 default = "")
255
256 NetRenderSettings.IntProperty( attr="active_slave_index",
257                                 name="Index of the active slave",
258                                 description="",
259                                 default = -1,
260                                 min= -1,
261                                 max=65535)
262
263 NetRenderSettings.IntProperty( attr="active_blacklisted_slave_index",
264                                 name="Index of the active slave",
265                                 description="",
266                                 default = -1,
267                                 min= -1,
268                                 max=65535)
269
270 NetRenderSettings.IntProperty( attr="active_job_index",
271                                 name="Index of the active job",
272                                 description="",
273                                 default = -1,
274                                 min= -1,
275                                 max=65535)
276
277 NetRenderSettings.EnumProperty(attr="mode",
278                                                 items=(
279                                                                                 ("RENDER_CLIENT", "Client", "Act as render client"),
280                                                                                 ("RENDER_MASTER", "Master", "Act as render master"),
281                                                                                 ("RENDER_SLAVE", "Slave", "Act as render slave"),
282                                                                         ),
283                                                 name="network mode",
284                                                 description="mode of operation of this instance",
285                                                 default="RENDER_CLIENT")
286
287 NetRenderSettings.CollectionProperty(attr="slaves", type=NetRenderSlave, name="Slaves", description="")
288 NetRenderSettings.CollectionProperty(attr="slaves_blacklist", type=NetRenderSlave, name="Slaves Blacklist", description="")
289 NetRenderSettings.CollectionProperty(attr="jobs", type=NetRenderJob, name="Job List", description="")
290
291 NetRenderSlave.StringProperty( attr="name",
292                                 name="Name of the slave",
293                                 description="",
294                                 maxlen = 64,
295                                 default = "")
296
297 NetRenderJob.StringProperty( attr="name",
298                                 name="Name of the job",
299                                 description="",
300                                 maxlen = 128,
301                                 default = "")