Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ui.py « netrender « io « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 594ebcd12dbd1d329d1013e982a51de9b3a0706a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

import bpy
import sys, os
import http, http.client, http.server, urllib
import subprocess, shutil, time, hashlib

import netrender
import netrender.slave as slave
import netrender.master as master

from netrender.utils import *

VERSION = b"0.3"

PATH_PREFIX = "/tmp/"

QUEUED = 0
DISPATCHED = 1
DONE = 2
ERROR = 3

def init_file():
    if netrender.init_file != bpy.data.filepath:
        netrender.init_file = bpy.data.filepath
        netrender.init_data = True
        netrender.init_address = True

def init_data(netsettings):
    init_file()

    if netrender.init_data:
        netrender.init_data = False

        netsettings.active_slave_index = 0
        while(len(netsettings.slaves) > 0):
            netsettings.slaves.remove(0)

        netsettings.active_blacklisted_slave_index = 0
        while(len(netsettings.slaves_blacklist) > 0):
            netsettings.slaves_blacklist.remove(0)

        netsettings.active_job_index = 0
        while(len(netsettings.jobs) > 0):
            netsettings.jobs.remove(0)

def verify_address(netsettings):
    init_file()

    if netrender.init_address:
        netrender.init_address = False

        try:
            conn = clientConnection(netsettings.server_address, netsettings.server_port, scan = False)
        except:
            conn = None

        if conn:
            conn.close()
        else:
            netsettings.server_address = "[default]"

class RenderButtonsPanel():
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "render"
    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here

    def poll(self, context):
        rd = context.scene.render
        return (rd.use_game_engine==False) and (rd.engine in self.COMPAT_ENGINES)

# Setting panel, use in the scene for now.
class RENDER_PT_network_settings(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Network Settings"
    COMPAT_ENGINES = {'NET_RENDER'}

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        verify_address(netsettings)

        layout.prop(netsettings, "mode", expand=True)

        if netsettings.mode in ("RENDER_MASTER", "RENDER_SLAVE"):
            layout.operator("render.netclientstart", icon='PLAY')

        layout.prop(netsettings, "path")

        split = layout.split(percentage=0.7)

        col = split.column()
        col.label(text="Server Adress:")
        col.prop(netsettings, "server_address", text="")

        col = split.column()
        col.label(text="Port:")
        col.prop(netsettings, "server_port", text="")

        if netsettings.mode != "RENDER_MASTER":
            layout.operator("render.netclientscan", icon='FILE_REFRESH', text="")

        layout.operator("render.netclientweb", icon='QUESTION')

class RENDER_PT_network_slave_settings(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Slave Settings"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        return (super().poll(context)
                and scene.network_render.mode == "RENDER_SLAVE")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        rd = scene.render
        netsettings = scene.network_render

        layout.prop(netsettings, "slave_clear")
        layout.prop(netsettings, "slave_thumb")
        layout.prop(netsettings, "slave_outputlog")
        layout.label(text="Threads:")
        layout.prop(rd, "threads_mode", expand=True)
        sub = layout.column()
        sub.enabled = rd.threads_mode == 'FIXED'
        sub.prop(rd, "threads")

class RENDER_PT_network_master_settings(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Master Settings"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        return (super().poll(context)
                and scene.network_render.mode == "RENDER_MASTER")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        layout.prop(netsettings, "master_broadcast")
        layout.prop(netsettings, "master_clear")

class RENDER_PT_network_job(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Job Settings"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        return (super().poll(context)
                and scene.network_render.mode == "RENDER_CLIENT")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        verify_address(netsettings)

        if netsettings.server_address != "[default]":
            layout.operator("render.netclientanim", icon='RENDER_ANIMATION')
            layout.operator("render.netclientsend", icon='FILE_BLEND')
            layout.operator("render.netclientsendframe", icon='RENDER_STILL')
            if netsettings.job_id:
                row = layout.row()
                row.operator("render.render", text="Get Image", icon='RENDER_STILL')
                row.operator("render.render", text="Get Animation", icon='RENDER_ANIMATION').animation = True

        split = layout.split(percentage=0.3)

        col = split.column()
        col.label(text="Name:")
        col.label(text="Category:")

        col = split.column()
        col.prop(netsettings, "job_name", text="")
        col.prop(netsettings, "job_category", text="")

        row = layout.row()
        row.prop(netsettings, "priority")
        row.prop(netsettings, "chunks")

class RENDER_PT_network_slaves(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Slaves Status"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        netsettings = scene.network_render
        if netsettings.mode != "RENDER_CLIENT":
            return False
        verify_address(netsettings)
        return (super().poll(context)
                and netsettings.server_address != "[default]")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        row = layout.row()
        row.template_list(netsettings, "slaves", netsettings, "active_slave_index", rows=2)

        sub = row.column(align=True)
        sub.operator("render.netclientslaves", icon='FILE_REFRESH', text="")
        sub.operator("render.netclientblacklistslave", icon='ZOOMOUT', text="")

        init_data(netsettings)

        if netsettings.active_slave_index >= 0 and len(netsettings.slaves) > 0:
            layout.separator()

            slave = netrender.slaves[netsettings.active_slave_index]

            layout.label(text="Name: " + slave.name)
            layout.label(text="Address: " + slave.address[0])
            layout.label(text="Seen: " + time.ctime(slave.last_seen))
            layout.label(text="Stats: " + slave.stats)

class RENDER_PT_network_slaves_blacklist(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Slaves Blacklist"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        netsettings = scene.network_render
        if netsettings.mode != "RENDER_CLIENT":
            return False
        verify_address(netsettings)
        return (super().poll(context)
                and netsettings.server_address != "[default]")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        row = layout.row()
        row.template_list(netsettings, "slaves_blacklist", netsettings, "active_blacklisted_slave_index", rows=2)

        sub = row.column(align=True)
        sub.operator("render.netclientwhitelistslave", icon='ZOOMOUT', text="")

        init_data(netsettings)

        if netsettings.active_blacklisted_slave_index >= 0 and len(netsettings.slaves_blacklist) > 0:
            layout.separator()

            slave = netrender.blacklist[netsettings.active_blacklisted_slave_index]

            layout.label(text="Name: " + slave.name)
            layout.label(text="Address: " + slave.address[0])
            layout.label(text="Seen: " + time.ctime(slave.last_seen))
            layout.label(text="Stats: " + slave.stats)

class RENDER_PT_network_jobs(bpy.types.Panel, RenderButtonsPanel):
    bl_label = "Jobs"
    COMPAT_ENGINES = {'NET_RENDER'}

    def poll(self, context):
        scene = context.scene
        netsettings = scene.network_render
        if netsettings.mode != "RENDER_CLIENT":
            return False
        verify_address(netsettings)
        return (super().poll(context)
                and netsettings.server_address != "[default]")

    def draw(self, context):
        layout = self.layout

        scene = context.scene
        netsettings = scene.network_render

        row = layout.row()
        row.template_list(netsettings, "jobs", netsettings, "active_job_index", rows=2)

        sub = row.column(align=True)
        sub.operator("render.netclientstatus", icon='FILE_REFRESH', text="")
        sub.operator("render.netclientcancel", icon='ZOOMOUT', text="")
        sub.operator("render.netclientcancelall", icon='PANEL_CLOSE', text="")
        sub.operator("render.netclientdownload", icon='RENDER_ANIMATION', text="")

        init_data(netsettings)

        if netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0:
            layout.separator()

            job = netrender.jobs[netsettings.active_job_index]

            layout.label(text="Name: %s" % job.name)
            layout.label(text="Length: %04i" % len(job))
            layout.label(text="Done: %04i" % job.results[DONE])
            layout.label(text="Error: %04i" % job.results[ERROR])

class NetRenderSettings(bpy.types.IDPropertyGroup):
    pass

class NetRenderSlave(bpy.types.IDPropertyGroup):
    pass

class NetRenderJob(bpy.types.IDPropertyGroup):
    pass

def addProperties():
    bpy.types.Scene.PointerProperty(attr="network_render", type=NetRenderSettings, name="Network Render", description="Network Render Settings")
    
    NetRenderSettings.StringProperty( attr="server_address",
                    name="Server address",
                    description="IP or name of the master render server",
                    maxlen = 128,
                    default = "[default]")
    
    NetRenderSettings.IntProperty( attr="server_port",
                    name="Server port",
                    description="port of the master render server",
                    default = 8000,
                    min=1,
                    max=65535)
    
    NetRenderSettings.BoolProperty( attr="master_broadcast",
                    name="Broadcast",
                    description="broadcast master server address on local network",
                    default = True)
    
    NetRenderSettings.BoolProperty( attr="slave_clear",
                    name="Clear on exit",
                    description="delete downloaded files on exit",
                    default = True)
    
    NetRenderSettings.BoolProperty( attr="slave_thumb",
                    name="Generate thumbnails",
                    description="Generate thumbnails on slaves instead of master",
                    default = False)
    
    NetRenderSettings.BoolProperty( attr="slave_outputlog",
                    name="Output render log on console",
                    description="Output render text log to console as well as sending it to the master",
                    default = True)
    
    NetRenderSettings.BoolProperty( attr="master_clear",
                    name="Clear on exit",
                    description="delete saved files on exit",
                    default = False)
    
    default_path = os.environ.get("TEMP")
    
    if not default_path:
        if os.name == 'nt':
            default_path = "c:/tmp/"
        else:
            default_path = "/tmp/"
    elif not default_path.endswith(os.sep):
        default_path += os.sep
    
    NetRenderSettings.StringProperty( attr="path",
                    name="Path",
                    description="Path for temporary files",
                    maxlen = 128,
                    default = default_path,
                    subtype='FILE_PATH')
    
    NetRenderSettings.StringProperty( attr="job_name",
                    name="Job name",
                    description="Name of the job",
                    maxlen = 128,
                    default = "[default]")
    
    NetRenderSettings.StringProperty( attr="job_category",
                    name="Job category",
                    description="Category of the job",
                    maxlen = 128,
                    default = "")
    
    NetRenderSettings.IntProperty( attr="chunks",
                    name="Chunks",
                    description="Number of frame to dispatch to each slave in one chunk",
                    default = 5,
                    min=1,
                    max=65535)
    
    NetRenderSettings.IntProperty( attr="priority",
                    name="Priority",
                    description="Priority of the job",
                    default = 1,
                    min=1,
                    max=10)
    
    NetRenderSettings.StringProperty( attr="job_id",
                    name="Network job id",
                    description="id of the last sent render job",
                    maxlen = 64,
                    default = "")
    
    NetRenderSettings.IntProperty( attr="active_slave_index",
                    name="Index of the active slave",
                    description="",
                    default = -1,
                    min= -1,
                    max=65535)
    
    NetRenderSettings.IntProperty( attr="active_blacklisted_slave_index",
                    name="Index of the active slave",
                    description="",
                    default = -1,
                    min= -1,
                    max=65535)
    
    NetRenderSettings.IntProperty( attr="active_job_index",
                    name="Index of the active job",
                    description="",
                    default = -1,
                    min= -1,
                    max=65535)
    
    NetRenderSettings.EnumProperty(attr="mode",
                            items=(
                                            ("RENDER_CLIENT", "Client", "Act as render client"),
                                            ("RENDER_MASTER", "Master", "Act as render master"),
                                            ("RENDER_SLAVE", "Slave", "Act as render slave"),
                                        ),
                            name="Network mode",
                            description="Mode of operation of this instance",
                            default="RENDER_CLIENT")
    
    NetRenderSettings.CollectionProperty(attr="slaves", type=NetRenderSlave, name="Slaves", description="")
    NetRenderSettings.CollectionProperty(attr="slaves_blacklist", type=NetRenderSlave, name="Slaves Blacklist", description="")
    NetRenderSettings.CollectionProperty(attr="jobs", type=NetRenderJob, name="Job List", description="")
    
    NetRenderSlave.StringProperty( attr="name",
                    name="Name of the slave",
                    description="",
                    maxlen = 64,
                    default = "")
    
    NetRenderJob.StringProperty( attr="name",
                    name="Name of the job",
                    description="",
                    maxlen = 128,
                    default = "")