· 5 years ago · Jul 24, 2020, 09:02 PM
1
2
3#### TASKS #####
4# 1. make new config with
5# a. scratch dir
6# b. api key
7# c.
8
9
10######################### TO DO #########################
11# A. INSTALLER NEEDS TO INCLUDE RELEVANT PYTHON PACKAGES
12# 1. REQUESTS
13
14#########################################################
15
16
17def getSep():
18 return "\\"
19
20
21def libImport():
22 import sys
23 sys.path.append('C:' + getSep() + 'Python27' + getSep() + 'Lib' + getSep() + 'site-packages')
24
25
26
27 import requests
28 import json
29 import sys
30 import getpass
31 import shutil
32 import os
33 import os.path
34
35
36libImport()
37
38
39
40
41######
42#hard coded stuff
43scratch = "C:\\Users\\colorist\\Desktop\\tmp"
44
45
46def getApiKey():
47 return "0ov3nqnxQVkA6XgpoghQa3XTpx5cICmx"
48
49
50
51
52def getInfo(api_key):
53 data = {'api_key': api_key}
54 url = 'https://trn.la/api/artist/shots'
55 session = requests.Session()
56 r = session.post(url, data=data)
57 return json.loads(json.dumps(r.json()))
58 r.raw.close()
59
60def panel(shotInfo):
61 p = nuke.Panel('submit: ' + shotInfo['shots']['shot_name'])
62 p.addBooleanCheckBox(shotInfo["shots"]["tarantula_note"], False)
63 p.addNotepad('your note', '')
64 ret = p.show()
65
66 if p.value(shotInfo["shots"]["tarantula_note"]) == False:
67 nuke.message("Please confirm you've addressed the note: \n\n" + shotInfo["shots"]["tarantula_note"])
68 return False
69
70 if len(p.value('your note')) < 7:
71 nuke.message("Please provide more info about what updates you've made to this shot.")
72 return False
73
74 return p.value('your note')
75
76def getReadInfo():
77 dwaa = exr = bitsPerChannel = False
78
79 n = nuke.selectedNode()
80 file = n['file'].value().split(getSep())[-1]
81 file = file.split(".")[0]
82 first_frame = n["first"].value()
83 last_frame = n["last"].value()
84 node_name = n["name"].value()
85
86 #does not require user to rerender
87 # 0 = file // 1 = first_frame // 2 = last_frame // 3 = node_name
88 return [file, first_frame, last_frame, node_name]
89
90
91def renderEXRs():
92 info = getReadInfo()
93 settings = getSettings()
94 scratch_dir = settings['artist']['scratch directory']
95
96 if os.path.exists(scratch_dir + getSep() + info[0] ):
97 pass
98 else:
99 os.mkdir(scratch_dir + getSep() + info[0] )
100
101 output_destination = scratch_dir + getSep() + info[0] + getSep() + info[0] + "_%04d.exr"
102
103 #EXR WRITER
104 nuke.nodePaste("/Users/petertimberlake/.nuke/tarantula/io/producer_nuke_submit_EXRs.nk")
105
106 n = nuke.selectedNode()
107 n["file"].setValue(output_destination)
108 thumbnail_write_node = n['name'].getValue()
109
110 try:
111 nuke.execute(thumbnail_write_node, info[1], info[2])
112 except:
113 print "something went wrong"
114
115 #deletes write nodes
116 nuke.delete(nuke.toNode(thumbnail_write_node))
117
118 #creates zip file
119 shutil.make_archive(scratch_dir + getSep() + info[0], 'zip', scratch_dir)
120
121 nuke.toNode(info[3]).setSelected(True)
122
123 return scratch_dir + getSep() + info[0] + ".zip"
124
125
126
127def upload(api_key):
128
129 i = getInfo(api_key)
130 shot_note = panel(i)
131 readInfo = getReadInfo()
132 scratch_dir = scratch + "\\scratch"
133
134 if readInfo == False:
135 print "render and zip"
136 zip_file = renderEXRs()
137 elif readInfo != False:
138 print "only zip"
139
140 if os.path.exists(scratch_dir):
141 pass
142 else:
143 os.makedirs(scratch_dir)
144 zip_file = shutil.make_archive(os.path.dirname(nuke.selectedNode()['file'].value()), 'zip', scratch_dir)
145
146
147 url = "https://trn.la/api/artist/submit_work"
148
149 data = {"api_key": api_key,
150 "shot_work_id": i["shots"]["work_id"],
151 "artist_note": shot_note
152 }
153
154 files = {
155 'shot_file': open(zip_file, 'rb')
156 }
157
158 session = requests.Session()
159 r = session.post(url, data=data, files=files, stream=True)
160
161 print r.json()
162 return r.json()
163
164 r.raw.close()
165
166
167
168
169if len(nuke.selectedNodes()) == 1:
170 x = upload(getApiKey())
171 if x["success"] == False:
172 nuke.message("Submission Failed. Have you already submitted this shot?")
173 elif x["success"] == True:
174 nuke.message('Submitted to Tarantula')
175else:
176 nuke.message('please select one read node to upload')
177
178
179
180