Patch T41093: Cleanup non-manifold
[blender-addons.git] / render_renderfarmfi / operators.py
blob2c867934bfbc918ba9bb21e39574ac4cd75732bf
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 #####
19 import hashlib
21 import bpy
23 from .utils import _write_credentials, _read_credentials
24 from .prepare import _prepare_scene
25 from .upload import _ore_upload
26 from .rpc import rffi, _do_refresh
27 from .exceptions import LoginFailedException, SessionCancelFailedException
29 class OpSwitchRenderfarm(bpy.types.Operator):
30 bl_label = "Switch to Renderfarm.fi"
31 bl_idname = "ore.switch_to_renderfarm_render"
33 def execute(self, context):
34 ore = bpy.context.scene.ore_render
35 rd = bpy.context.scene.render
37 ore.resox = rd.resolution_x
38 ore.resoy = rd.resolution_y
39 ore.fps = rd.fps
40 ore.start = bpy.context.scene.frame_start
41 ore.end = bpy.context.scene.frame_end
42 if (rd.engine == 'CYCLES'):
43 ore.samples = bpy.context.scene.cycles.samples
44 ore.engine = 'cycles'
45 else:
46 ore.engine = 'blender'
47 bpy.context.scene.render.engine = 'RENDERFARMFI_RENDER'
48 return {'FINISHED'}
50 class OpSwitchBlenderRender(bpy.types.Operator):
51 bl_label = "Switch to local render"
52 bl_idname = "ore.switch_to_local_render"
54 def execute(self, context):
55 rd = bpy.context.scene.render
56 ore = bpy.context.scene.ore_render
57 rd.resolution_x = ore.resox
58 rd.resolution_y = ore.resoy
59 rd.fps = ore.fps
60 bpy.context.scene.frame_start = ore.start
61 bpy.context.scene.frame_end = ore.end
62 if (bpy.context.scene.ore_render.engine == 'cycles'):
63 rd.engine = 'CYCLES'
64 bpy.context.scene.cycles.samples = ore.samples
65 else:
66 bpy.context.scene.render.engine = 'BLENDER_RENDER'
67 return {'FINISHED'}
69 # Copies start & end frame + others from render settings to ore settings
70 class OpCopySettings(bpy.types.Operator):
71 bl_label = "Copy settings from current scene"
72 bl_idname = "ore.copy_settings"
74 def execute(self, context):
75 sce = bpy.context.scene
76 rd = sce.render
77 ore = sce.ore_render
78 ore.resox = rd.resolution_x
79 ore.resoy = rd.resolution_y
80 ore.start = sce.frame_start
81 ore.end = sce.frame_end
82 ore.fps = rd.fps
83 return {'FINISHED'}
85 class ORE_RefreshOp(bpy.types.Operator):
86 bl_idname = 'ore.refresh_session_list'
87 bl_label = 'Refresh'
89 def execute(self, context):
90 result = _do_refresh(self)
91 if (result == 0):
92 return {'FINISHED'}
93 else:
94 return {'CANCELLED'}
96 class ORE_OpenDownloadLocation(bpy.types.Operator):
97 bl_idname = 'ore.open_download_location'
98 bl_label = 'Download new version for your platform'
100 def execute(self, context):
101 import webbrowser
102 webbrowser.open(bpy.download_location)
103 return {'FINISHED'}
105 class ORE_CancelSession(bpy.types.Operator):
106 bl_idname = 'ore.cancel_session'
107 bl_label = 'Cancel Session'
109 def execute(self, context):
110 sce = context.scene
111 ore = sce.ore_render
112 if len(bpy.ore_complete_session_queue)>0:
113 s = bpy.ore_complete_session_queue[ore.selected_session]
114 try:
115 rffi.cancel_session(self, s)
116 except SessionCancelFailedException as scfe:
117 print("sessioncancelfailedexception", scfe)
119 return {'FINISHED'}
121 class ORE_GetCompletedSessions(bpy.types.Operator):
122 bl_idname = 'ore.completed_sessions'
123 bl_label = 'Completed sessions'
125 def execute(self, context):
126 sce = context.scene
127 ore = sce.ore_render
128 bpy.queue_selected = 1
129 bpy.ore_active_session_queue = bpy.ore_completed_sessions
130 update_session_list(completed_sessions, ore)
132 return {'FINISHED'}
134 class ORE_GetCancelledSessions(bpy.types.Operator):
135 bl_idname = 'ore.cancelled_sessions'
136 bl_label = 'Cancelled sessions'
138 def execute(self, context):
139 sce = context.scene
140 ore = sce.ore_render
141 bpy.queue_selected = 4
142 bpy.ore_active_session_queue = bpy.ore_cancelled_sessions
143 update_session_list(cancelled_sessions, ore)
145 return {'FINISHED'}
147 class ORE_GetActiveSessions(bpy.types.Operator):
148 bl_idname = 'ore.active_sessions'
149 bl_label = 'Rendering sessions'
151 def execute(self, context):
152 sce = context.scene
153 ore = sce.ore_render
154 bpy.queue_selected = 2
155 bpy.ore_active_session_queue = bpy.ore_active_sessions
156 update_session_list(active_sessions, ore)
158 return {'FINISHED'}
160 class ORE_GetPendingSessions(bpy.types.Operator):
161 bl_idname = 'ore.accept_sessions' # using ORE lingo in API. acceptQueue is session waiting for admin approval
162 bl_label = 'Pending sessions'
164 def execute(self, context):
165 sce = context.scene
166 ore = sce.ore_render
167 bpy.queue_selected = 3
168 bpy.ore_active_session_queue = bpy.ore_pending_sessions
169 update_session_list(pending_sessions, ore)
171 return {'FINISHED'}
173 class ORE_CheckUpdate(bpy.types.Operator):
174 bl_idname = 'ore.check_update'
175 bl_label = 'Check for a new version'
177 def execute(self, context):
178 blenderproxy = xmlrpc.client.ServerProxy(r'http://xmlrpc.renderfarm.fi/renderfarmfi/blender', verbose=bpy.RFFI_VERBOSE)
179 try:
180 self.report({'INFO'}, 'Checking for newer version on Renderfarm.fi')
181 dl_url = blenderproxy.blender.getCurrentVersion(bpy.CURRENT_VERSION)
182 if len(dl_url['url']) > 0:
183 self.report({'INFO'}, 'Found a newer version on Renderfarm.fi ' + dl_url['url'])
184 bpy.download_location = dl_url['url']
185 bpy.found_newer_version = True
186 else:
187 bpy.up_to_date = True
188 self.report({'INFO'}, 'Done checking for newer version on Renderfarm.fi')
189 except xmlrpc.client.Fault as f:
190 print('ERROR:', f)
191 self.report({'ERROR'}, 'An error occurred while checking for newer version on Renderfarm.fi: ' + f.faultString)
192 except xmlrpc.client.ProtocolError as e:
193 print('ERROR:', e)
194 self.report({'ERROR'}, 'An HTTP error occurred while checking for newer version on Renderfarm.fi: ' + str(e.errcode) + ' ' + e.errmsg)
196 return {'FINISHED'}
198 class ORE_LoginOp(bpy.types.Operator):
199 bl_idname = 'ore.login'
200 bl_label = 'Login'
202 def execute(self, context):
203 sce = context.scene
204 ore = sce.ore_render
206 ore.password = ore.password.strip()
207 ore.username = ore.username.strip()
209 print("writing new credentials")
210 _write_credentials(hashlib.md5(ore.password.encode() + ore.username.encode()).hexdigest(),ore.username)
211 _read_credentials()
212 ore.password = ''
213 ore.username = ''
214 bpy.loginInserted = False
215 bpy.passwordCorrect = False
217 try:
218 _do_refresh(self, True)
220 bpy.passwordCorrect = True
221 bpy.loginInserted = True
223 except LoginFailedException as v:
224 bpy.ready = False
225 bpy.loginInserted = False
226 bpy.passwordCorrect = False
227 ore.username = bpy.rffi_user
228 _write_credentials('', '')
229 _read_credentials()
230 ore.hash = ''
231 ore.password = ''
232 self.report({'WARNING'}, "Incorrect login: " + str(v))
233 print(v)
234 return {'CANCELLED'}
236 return {'FINISHED'}
238 class ORE_ResetOp(bpy.types.Operator):
239 bl_idname = "ore.reset"
240 bl_label = "Reset Preparation"
242 def execute(self, context):
243 sce = context.scene
244 ore = sce.ore_render
245 ore.prepared = False
246 bpy.loginInserted = False
247 bpy.prepared = False
248 ore.hash = ''
249 ore.username = ''
250 ore.passowrd = ''
251 ore.longdesc = ''
252 ore.shortdesc = '-'
253 ore.tags = ''
254 ore.title = ''
255 ore.url = ''
257 return {'FINISHED'}
259 class ORE_TestRenderOp(bpy.types.Operator):
260 bl_idname = "ore.test_render"
261 bl_label = "Run a test render"
263 def execute(self, context):
264 rd = context.scene.render
265 rd.engine = 'BLENDER_RENDER'
266 rd.threads_mode = 'AUTO'
267 rd.threads = 1
268 bpy.ops.render.render()
269 rd.threads_mode = 'FIXED'
270 rd.threads = 1
271 rd.engine = 'RENDERFARMFI_RENDER'
272 return {'FINISHED'}
274 class ORE_UploaderOp(bpy.types.Operator):
275 bl_idname = "ore.upload"
276 bl_label = "Render on Renderfarm.fi"
278 def execute(self, context):
280 bpy.uploadInProgress = True
281 _prepare_scene()
283 returnValue = _ore_upload(self, context)
284 bpy.uploadInProgress = False
285 return returnValue
287 class ORE_UseBlenderReso(bpy.types.Operator):
288 bl_idname = "ore.use_scene_settings"
289 bl_label = "Use Scene settings"
291 def execute(self, context):
292 sce = context.scene
293 ore = sce.ore_render
294 rd = context.scene.render
296 ore.resox = rd.resolution_x
297 ore.resoy = rd.resolution_y
298 ore.start = sce.frame_start
299 ore.end = sce.frame_end
300 ore.fps = rd.fps
302 return {'FINISHED'}
304 class ORE_UseCyclesRender(bpy.types.Operator):
305 bl_idname = "ore.use_cycles_render"
306 bl_label = "Cycles"
308 def execute(self, context):
309 context.scene.ore_render.engine = 'cycles'
310 return {'FINISHED'}
312 class ORE_UseBlenderRender(bpy.types.Operator):
313 bl_idname = "ore.use_blender_render"
314 bl_label = "Blender Internal"
316 def execute(self, context):
317 context.scene.ore_render.engine = 'blender'
318 return {'FINISHED'}
320 class ORE_ChangeUser(bpy.types.Operator):
321 bl_idname = "ore.change_user"
322 bl_label = "Change user"
324 def execute(self, context):
325 ore = context.scene.ore_render
326 _write_credentials('', '')
327 _read_credentials()
328 ore.password = ''
329 bpy.ore_sessions = []
330 ore.hash = ''
331 bpy.rffi_user = ''
332 bpy.rffi_hash = ''
333 bpy.rffi_creds_found = False
334 bpy.passwordCorrect = False
335 bpy.loginInserted = False
336 bpy.rffi_accepts = False
337 bpy.rffi_motd = ''
339 return {'FINISHED'}
341 class ORE_CheckStatus(bpy.types.Operator):
342 bl_idname = "ore.check_status"
343 bl_label = "Check Renderfarm.fi Accept status"
345 def execute(self, context):
346 rffi.check_status()
347 return {'FINISHED'}