~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons/render_renderfarmfi/utils.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ##### BEGIN GPL LICENSE BLOCK #####
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
# ##### END GPL LICENSE BLOCK #####
 
18
 
 
19
import imp
 
20
import xmlrpc.client
 
21
import math
 
22
import sys
 
23
import traceback
 
24
 
 
25
from os.path import join
 
26
 
 
27
import bpy
 
28
 
 
29
from .ore_session import OreSession
 
30
from .exceptions import LoginFailedException
 
31
 
 
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+'\'')
 
36
 
 
37
 
 
38
def _read_credentials():
 
39
    bpy.rffi_creds_found = False
 
40
    bpy.rffi_user = ''
 
41
    bpy.rffi_hash = ''
 
42
 
 
43
    pwfile = bpy.utils.user_resource('CONFIG', 'rffi', True)
 
44
    try:
 
45
        pwmod = imp.find_module('rffi_credentials',[pwfile])
 
46
    except ImportError as e:
 
47
        _write_credentials('', '')
 
48
        pwmod = imp.find_module('rffi_credentials',[pwfile])
 
49
    try:
 
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])
 
59
        try:
 
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)
 
66
    finally:
 
67
        if pwmod and pwmod[0]: pwmod[0].close()
 
68
 
 
69
    return bpy.rffi_creds_found
 
70
 
 
71
 
 
72
def _xmlsessions_to_oresessions(sessions, stage=None):
 
73
    output = []
 
74
    for session in sessions:
 
75
        s = session['title']
 
76
        if stage:
 
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']
 
83
        output.append(sinfo)
 
84
    return output
 
85
 
 
86
 
 
87
def update_session_list(session_list, ore):
 
88
    while(len(session_list) > 0):
 
89
        session_list.remove(0)
 
90
    
 
91
    for s in bpy.ore_active_session_queue:
 
92
        session_list.add()
 
93
        session = session_list[-1]
 
94
        session.name = s.title + ' [' + str(s.percentageComplete()) + '% complete]'
 
95
 
 
96
def update_complete_session_list(ore):
 
97
    all_sessions = []
 
98
    
 
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)
 
107
    
 
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)
 
113
    
 
114
    bpy.ore_active_session_queue = bpy.ore_complete_session_queue
 
115
    update_session_list(ore.all_sessions, ore)
 
116
 
 
117
def check_status(ore):
 
118
    bpy.errors = []
 
119
    
 
120
    if bpy.rffi_creds_found == False and bpy.rffi_hash == '':
 
121
        bpy.errors.append('missing_creds')
 
122
    
 
123
    if '' in {ore.title, ore.longdesc, ore.shortdesc}:
 
124
        bpy.errors.append('missing_desc')
 
125
        bpy.infoError = True
 
126
 
 
127
    set_status('username', bpy.rffi_hash=='' and ore.username=='')
 
128
    set_status('password', bpy.rffi_hash=='' and ore.password=='')
 
129
    
 
130
    set_status('title', ore.title=='')
 
131
    set_status('longdesc', ore.longdesc=='')
 
132
    set_status('shortdesc', ore.shortdesc=='')
 
133
 
 
134
 
 
135
def set_status(property, status):
 
136
    if status:
 
137
        bpy.statusMessage[property] = 'ERROR'
 
138
    else:
 
139
        bpy.statusMessage[property] = 'TRIA_RIGHT'
 
140
 
 
141
def show_status(layoutform, property, message):
 
142
    if bpy.statusMessage[property] == 'ERROR':
 
143
        layoutform.label(text='', icon='ERROR')
 
144