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 #####
25
from os.path import join
29
from .ore_session import OreSession
30
from .exceptions import LoginFailedException
32
def _write_credentials(hash, user):
33
with open(join(bpy.utils.user_resource('CONFIG', 'rffi', True), 'rffi_credentials.py'), 'w') as pwfile:
34
pwfile.write('hash=\''+hash+'\'\n')
35
pwfile.write('user=\''+user+'\'')
38
def _read_credentials():
39
bpy.rffi_creds_found = False
43
pwfile = bpy.utils.user_resource('CONFIG', 'rffi', True)
45
pwmod = imp.find_module('rffi_credentials',[pwfile])
46
except ImportError as e:
47
_write_credentials('', '')
48
pwmod = imp.find_module('rffi_credentials',[pwfile])
50
user_creds = imp.load_module('rffi_credentials', pwmod[0], pwmod[1], pwmod[2])
51
bpy.rffi_user = user_creds.user
52
bpy.rffi_hash = user_creds.hash
53
bpy.rffi_creds_found = True
54
except ImportError as e:
55
# doesn't exist yet, write template
56
_write_credentials('', '')
57
pwfile = bpy.utils.user_resource('CONFIG', 'rffi', True)
58
pwmod = imp.find_module('rffi_credentials',[pwfile])
60
user_creds = imp.load_module('rffi_credentials', pwmod[0], pwmod[1], pwmod[2])
61
bpy.rffi_user = user_creds.user
62
bpy.rffi_hash = user_creds.hash
63
bpy.rffi_creds_found = True
64
except Exception as e2:
65
print("Couldn't write rffi_credentials.py", e2)
67
if pwmod and pwmod[0]: pwmod[0].close()
69
return bpy.rffi_creds_found
72
def _xmlsessions_to_oresessions(sessions, stage=None):
74
for session in sessions:
77
s = s + ' (' + stage + ')'
78
sinfo = OreSession(session['sessionId'], s)
79
if stage in {'Completed', 'Active'}:
80
sinfo.frames = session['framesRendered']
81
sinfo.startframe = session['startFrame']
82
sinfo.endframe = session['endFrame']
87
def update_session_list(session_list, ore):
88
while(len(session_list) > 0):
89
session_list.remove(0)
91
for s in bpy.ore_active_session_queue:
93
session = session_list[-1]
94
session.name = s.title + ' [' + str(s.percentageComplete()) + '% complete]'
96
def update_complete_session_list(ore):
99
bpy.ore_active_session_queue = bpy.ore_cancelled_sessions
100
update_session_list(ore.rejected_sessions, ore)
101
bpy.ore_active_session_queue = bpy.ore_active_sessions
102
update_session_list(ore.active_sessions, ore)
103
bpy.ore_active_session_queue = bpy.ore_pending_sessions
104
update_session_list(ore.pending_sessions, ore)
105
bpy.ore_active_session_queue = bpy.ore_completed_sessions
106
update_session_list(ore.completed_sessions, ore)
108
bpy.ore_complete_session_queue = []
109
bpy.ore_complete_session_queue.extend(bpy.ore_pending_sessions)
110
bpy.ore_complete_session_queue.extend(bpy.ore_active_sessions)
111
bpy.ore_complete_session_queue.extend(bpy.ore_completed_sessions)
112
bpy.ore_complete_session_queue.extend(bpy.ore_cancelled_sessions)
114
bpy.ore_active_session_queue = bpy.ore_complete_session_queue
115
update_session_list(ore.all_sessions, ore)
117
def check_status(ore):
120
if bpy.rffi_creds_found == False and bpy.rffi_hash == '':
121
bpy.errors.append('missing_creds')
123
if '' in {ore.title, ore.longdesc, ore.shortdesc}:
124
bpy.errors.append('missing_desc')
127
set_status('username', bpy.rffi_hash=='' and ore.username=='')
128
set_status('password', bpy.rffi_hash=='' and ore.password=='')
130
set_status('title', ore.title=='')
131
set_status('longdesc', ore.longdesc=='')
132
set_status('shortdesc', ore.shortdesc=='')
135
def set_status(property, status):
137
bpy.statusMessage[property] = 'ERROR'
139
bpy.statusMessage[property] = 'TRIA_RIGHT'
141
def show_status(layoutform, property, message):
142
if bpy.statusMessage[property] == 'ERROR':
143
layoutform.label(text='', icon='ERROR')