-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnuke_renamer.py
More file actions
104 lines (95 loc) · 2.6 KB
/
Copy pathnuke_renamer.py
File metadata and controls
104 lines (95 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#get nodes
nodes = nuke.allNodes()
print nodes
### get nuke string
for n in nodes:
if n.Class() == 'Read':
print n.name()
print n.knob('inFile').value()
#extend this to extract versions
for n in nodes:
if n.Class() == 'Read':
print n.name()
curr = n.knob('inFile').value()
ver = curr.split('_')[-3]
take = curr.split('_')[-2]
print curr
print ver
print take
#now lets get the versions
for n in nodes:
if n.Class() == 'Read':
curr = n.knob('inFile').value()
ver = curr.split('_')[-3]
take = curr.split('_')[-2]
fpath = curr.rpartition('/')[0].rpartition('/')[0]+'/'
versbits = curr.replace(fpath, '')
searcher = versbits.split('_v')[0]+'_'
print n.name()
for a in os.listdir(fpath):
if searcher in a:
print a.split('_v')[-1].split('_')[0], a.split('_t')[-1].split('_')[0]
#now let's get the highest version
for n in nodes:
if n.Class() == 'Read':
curr = n.knob('inFile').value()
ver = curr.split('_')[-3]
take = curr.split('_')[-2]
fpath = curr.rpartition('/')[0].rpartition('/')[0]+'/'
versbits = curr.replace(fpath, '')
searcher = versbits.split('_v')[0]+'_'
print n.name()
version = []
for a in os.listdir(fpath):
if searcher in a:
version.append(int(a.split('_v')[-1].split('_')[0]))
print max(version)
#now lets add that versions’ highest take
for n in nodes:
if n.Class() == 'Read':
curr = n.knob('inFile').value()
ver = curr.split('_')[-3]
take = curr.split('_')[-2]
fpath = curr.rpartition('/')[0].rpartition('/')[0]+'/'
versbits = curr.replace(fpath, '')
searcher = versbits.split('_v')[0]+'_'
print n.name()
version = []
for a in os.listdir(fpath):
if searcher in a:
version.append(int(a.split('_v')[-1].split('_')[0]))
newver = max(version)
takes = []
for a in os.listdir(fpath):
if '_v'+str(newver) in a and searcher in a:
takes.append(int(a.split('_t')[-1].split('_')[0]))
newtake = max(takes)
print newver, newtake
#final step, lets update the path and throw it back to the node
for n in nodes:
if n.Class() == 'Read':
curr = n.knob('file').value()
ver = curr.split('_')[-3]
take = curr.split('_')[-2]
fpath = curr.rpartition('/')[0].rpartition('/')[0]+'/'
versbits = curr.replace(fpath, '')
searcher = versbits.split('_v')[0]+'_'
print n.name()
version = []
for a in os.listdir(fpath):
if searcher in a:
version.append(int(a.split('_v')[-1].split('_')[0]))
newver = max(version)
takes = []
for a in os.listdir(fpath):
if '_v'+str(newver) in a and searcher in a:
takes.append(int(a.split('_t')[-1].split('_')[0]))
newtake = max(takes)
print ver
print take
print curr
new = curr.replace(ver, 'v%02d'%newver)
new =new.replace(take, 't%02d'%newtake)
n.knob('file').setValue(new)
n.knob('on_error').setValue(3)
n.knob("reload").execute()