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 #####
21 from os
.path
import join
25 from .ore_session
import OreSession
27 def _write_credentials(hash, user
):
28 with
open(join(bpy
.utils
.user_resource('CONFIG', 'rffi', True), 'rffi_credentials.py'), 'w') as pwfile
:
29 pwfile
.write('hash=\''+hash+'\'\n')
30 pwfile
.write('user=\''+user
+'\'')
33 def _read_credentials():
34 bpy
.rffi_creds_found
= False
38 pwfile
= bpy
.utils
.user_resource('CONFIG', 'rffi', True)
40 pwmod
= imp
.find_module('rffi_credentials',[pwfile
])
42 _write_credentials('', '')
43 pwmod
= imp
.find_module('rffi_credentials',[pwfile
])
45 user_creds
= imp
.load_module('rffi_credentials', pwmod
[0], pwmod
[1], pwmod
[2])
46 bpy
.rffi_user
= user_creds
.user
47 bpy
.rffi_hash
= user_creds
.hash
48 bpy
.rffi_creds_found
= True
50 # doesn't exist yet, write template
51 _write_credentials('', '')
52 pwfile
= bpy
.utils
.user_resource('CONFIG', 'rffi', True)
53 pwmod
= imp
.find_module('rffi_credentials',[pwfile
])
55 user_creds
= imp
.load_module('rffi_credentials', pwmod
[0], pwmod
[1], pwmod
[2])
56 bpy
.rffi_user
= user_creds
.user
57 bpy
.rffi_hash
= user_creds
.hash
58 bpy
.rffi_creds_found
= True
59 except Exception as e2
:
60 print("Couldn't write rffi_credentials.py", e2
)
62 if pwmod
and pwmod
[0]: pwmod
[0].close()
64 return bpy
.rffi_creds_found
67 def _xmlsessions_to_oresessions(sessions
, stage
=None):
69 for session
in sessions
:
72 s
= s
+ ' (' + stage
+ ')'
73 sinfo
= OreSession(session
['sessionId'], s
)
74 if stage
in {'Rendering', 'Completed', 'Active'}:
75 sinfo
.frames
= session
['framesRendered']
76 sinfo
.startframe
= session
['startFrame']
77 sinfo
.endframe
= session
['endFrame']
82 def update_session_list(session_list
, ore
):
83 while(len(session_list
) > 0):
84 session_list
.remove(0)
86 for s
in bpy
.ore_active_session_queue
:
88 session
= session_list
[-1]
89 session
.name
= s
.title
+ ' [' + str(s
.percentageComplete()) + '% complete]'
91 def update_complete_session_list(ore
):
92 bpy
.ore_active_session_queue
= bpy
.ore_cancelled_sessions
93 update_session_list(ore
.rejected_sessions
, ore
)
94 bpy
.ore_active_session_queue
= bpy
.ore_active_sessions
95 update_session_list(ore
.active_sessions
, ore
)
96 bpy
.ore_active_session_queue
= bpy
.ore_pending_sessions
97 update_session_list(ore
.pending_sessions
, ore
)
98 bpy
.ore_active_session_queue
= bpy
.ore_completed_sessions
99 update_session_list(ore
.completed_sessions
, ore
)
101 bpy
.ore_complete_session_queue
= []
102 bpy
.ore_complete_session_queue
.extend(bpy
.ore_pending_sessions
)
103 bpy
.ore_complete_session_queue
.extend(bpy
.ore_active_sessions
)
104 bpy
.ore_complete_session_queue
.extend(bpy
.ore_completed_sessions
)
105 bpy
.ore_complete_session_queue
.extend(bpy
.ore_cancelled_sessions
)
107 bpy
.ore_active_session_queue
= bpy
.ore_complete_session_queue
108 update_session_list(ore
.all_sessions
, ore
)
110 def check_status(ore
):
113 if bpy
.rffi_creds_found
== False and bpy
.rffi_hash
== '':
114 bpy
.errors
.append('missing_creds')
116 if '' in {ore
.title
, ore
.longdesc
, ore
.shortdesc
}:
117 bpy
.errors
.append('missing_desc')
120 set_status('username', bpy
.rffi_hash
=='' and ore
.username
=='')
121 set_status('password', bpy
.rffi_hash
=='' and ore
.password
=='')
123 set_status('title', ore
.title
=='')
124 set_status('longdesc', ore
.longdesc
=='')
125 set_status('shortdesc', ore
.shortdesc
=='')
128 def set_status(property, status
):
130 bpy
.statusMessage
[property] = 'ERROR'
132 bpy
.statusMessage
[property] = 'TRIA_RIGHT'
134 def show_status(layoutform
, property, message
):
135 if bpy
.statusMessage
[property] == 'ERROR':
136 layoutform
.label(text
='', icon
='ERROR')