netrender. first draft of html master details. Just point a browser at the master...
[blender.git] / release / io / netrender / utils.py
1 import bpy
2 import sys, os
3 import re
4 import http, http.client, http.server, urllib
5 import subprocess, shutil, time, hashlib
6
7 import netrender.model
8
9 VERSION = b"0.5"
10
11 # Jobs status
12 JOB_WAITING = 0 # before all data has been entered
13 JOB_PAUSED = 1 # paused by user
14 JOB_QUEUED = 2 # ready to be dispatched
15
16 # Frames status
17 QUEUED = 0
18 DISPATCHED = 1
19 DONE = 2
20 ERROR = 3
21
22 STATUS_TEXT = {
23                                                                 QUEUED: "Queued",
24                                                                 DISPATCHED: "Dispatched",
25                                                                 DONE: "Done",
26                                                                 ERROR: "Error"
27                                                         }
28
29 def rnaType(rna_type):
30         bpy.types.register(rna_type)
31         return rna_type
32
33 def rnaOperator(rna_op):
34         bpy.ops.add(rna_op)
35         return rna_op
36
37 def clientConnection(scene):
38                 netsettings = scene.network_render
39                 
40                 if netsettings.server_address == "[default]":
41                         bpy.ops.render.netclientscan()
42                 
43                 conn = http.client.HTTPConnection(netsettings.server_address, netsettings.server_port)
44                 
45                 if clientVerifyVersion(conn):
46                         return conn
47                 else:
48                         conn.close()
49                         return None
50
51 def clientVerifyVersion(conn):
52         conn.request("GET", "/version")
53         response = conn.getresponse()
54         
55         if response.status != http.client.OK:
56                 conn.close()
57                 return False
58         
59         server_version = response.read()
60         
61         if server_version != VERSION:
62                 print("Incorrect server version!")
63                 print("expected", VERSION, "received", server_version)
64                 return False
65         
66         return True
67
68 def prefixPath(prefix_directory, file_path, prefix_path):
69         if os.path.isabs(file_path):
70                 # if an absolute path, make sure path exists, if it doesn't, use relative local path
71                 full_path = file_path
72                 if not os.path.exists(full_path):
73                         p, n = os.path.split(full_path)
74                         
75                         if prefix_path and p.startswith(prefix_path):
76                                 directory = prefix_directory + p[len(prefix_path):]
77                                 full_path = directory + n
78                                 if not os.path.exists(directory):
79                                         os.mkdir(directory)
80                         else:
81                                 full_path = prefix_directory + n
82         else:
83                 full_path = prefix_directory + file_path
84         
85         return full_path