· 5 years ago · Jul 24, 2020, 09:46 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
16def libImport():
17 import sys
18 sys.path.append('C:/Python27/Lib/site-packages')
19
20 import requests
21 import json
22 import sys
23 import getpass
24 import shutil
25 import os
26 import os.path
27 import zipfile
28
29
30libImport()
31
32
33######
34# HARD CODED STUFF YOU'LL NEED TO CHANGE
35scratch = "C:/Users/colorist/Desktop/tmp"
36exr_writer = "C:/Users/colorist/.nuke/tarantula/io/producer_nuke_submit_EXRs.nk"
37
38
39#HARD CODED, WILL EVENTUALLY BE REPLACED WITH FUNCTION
40def getApiKey():
41 return "0ov3nqnxQVkA6XgpoghQa3XTpx5cICmx"
42
43
44
45#GETS INFO ABOUT THE CURRENT ARTIST FROM THE ONLINE DATABASE
46def getInfo(api_key):
47 data = {'api_key': api_key}
48 url = 'https://trn.la/api/artist/shots'
49 session = requests.Session()
50 r = session.post(url, data=data)
51 return json.loads(json.dumps(r.json()))
52 r.raw.close()
53
54#CREATES PANEL FOR ARTIST
55def panel(shotInfo):
56 p = nuke.Panel('submit: ' + shotInfo['shots']['shot_name'])
57 p.addBooleanCheckBox(shotInfo["shots"]["tarantula_note"], False)
58 p.addNotepad('your note', '')
59 ret = p.show()
60
61 if p.value(shotInfo["shots"]["tarantula_note"]) == False:
62 nuke.message("Please confirm you've addressed the note: \n\n" + shotInfo["shots"]["tarantula_note"])
63 return False
64
65 if len(p.value('your note')) < 7:
66 nuke.message("Please provide more info about what updates you've made to this shot.")
67 return False
68
69 return p.value('your note')
70
71#GETS INFO ABOUT THE READ NODE SO THAT THE PROGRAM KNOWS WHAT TO UPLOAD
72def getReadInfo():
73 dwaa = exr = bitsPerChannel = False
74
75 n = nuke.selectedNode()
76 file = n['file'].value().split('/')[-1]
77 file = file.split(".")[0]
78 first_frame = n["first"].value()
79 last_frame = n["last"].value()
80 node_name = n["name"].value()
81
82 #does not require user to rerender
83 # 0 = file // 1 = first_frame // 2 = last_frame // 3 = node_name
84 return [file, first_frame, last_frame, node_name]
85
86
87#COPIES THE CORRECT READ NODE AND RENDERS USING THAT READ NODE
88def renderEXRs():
89 info = getReadInfo()
90 scratch_dir = scratch
91
92 if os.path.exists(scratch_dir + '/' + info[0] ):
93 pass
94 else:
95 os.mkdir(scratch_dir + '/' + info[0] )
96
97 output_destination = scratch_dir + '/' + info[0] + '/' + info[0] + "_%04d.exr"
98
99 #EXR WRITER
100 nuke.nodePaste(exr_writer)
101
102 n = nuke.selectedNode()
103 n["file"].setValue(output_destination)
104 exr_write_node = n['name'].getValue()
105
106 try:
107 nuke.execute(exr_write_node, info[1], info[2])
108 except:
109 print "something went wrong"
110
111 #deletes write nodes
112 nuke.delete(nuke.toNode(exr_write_node))
113
114 #creates zip file
115 print scratch_dir + '/' + info[0]
116 zip = zipfile.ZipFile(scratch_dir + '/' + info[0] + '.zip', mode='w', allowZip64 = True)
117 #shutil.make_archive(scratch_dir + '/' + info[0], 'zip', scratch_dir)
118
119 nuke.toNode(info[3]).setSelected(True)
120
121 return scratch_dir + getSep() + info[0] + ".zip"
122
123
124#UPLOADS
125def upload(api_key):
126
127 i = getInfo(api_key)
128 shot_note = panel(i)
129 readInfo = getReadInfo()
130 scratch_dir = scratch + "/scratch"
131
132 #THIS IS WHERE THE RENDER FUNCTION IS CALLED
133 zip_file = renderEXRs()
134
135 url = "https://trn.la/api/artist/submit_work"
136
137 data = {"api_key": api_key,
138 "shot_work_id": i["shots"]["work_id"],
139 "artist_note": shot_note
140 }
141
142 files = {
143 'shot_file': open(zip_file, 'rb')
144 }
145
146 session = requests.Session()
147 r = session.post(url, data=data, files=files, stream=True)
148
149 print r.json()
150 return r.json()
151
152 r.raw.close()
153
154
155if len(nuke.selectedNodes()) == 1:
156 x = upload(getApiKey())
157 if x["success"] == False:
158 nuke.message("Submission Failed. Have you already submitted this shot?")
159 elif x["success"] == True:
160 nuke.message('Submitted to Tarantula')
161else:
162 nuke.message('please select one read node to upload')
163