-
Notifications
You must be signed in to change notification settings - Fork 1
/
dutchdevnukeconsol.py
528 lines (328 loc) · 12.5 KB
/
dutchdevnukeconsol.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#===============================================================================
#
# Author : Pmg Lemmen
# Company : Dutchdevelopers
# email : peter@dutchdevelopers.nl
# Date : 13/12/12
# Mod : 4/12/14
#
#
# Paste the followin items in menu.py
#
# #Collect Files Menu Node
# collectMenu = nuke.menu("Nodes").addMenu("Consolidator")
# collectMenu.addCommand('make backup ', 'dutchdevscripts.dutchdevscripts()')
# collectMenu.addCommand('Help', 'dutchdevscripts.Help()')
# collectMenu.addCommand('Manual', 'dutchdevscripts.Manual()')
#
# add the following line to init.py
# import dutchdevscripts
#
# rename the pyton file to dutchdevscripts.py
# copy dutchdevscripts.py it in the plugins directory
#
#
#===============================================================================
import nuke
import os
import sys
import shutil
import re
import threading
import time
import webbrowser
##############################################################
##
## Prepare system for writing slashes etc.
##
##############################################################
plemke_version = "v1.0.12 2012 "
only_enabled_nodes = False
slash = '/'
project_file_name = ""
project_file_dir = ""
backup_root_dir = "e:/backup/"
backup_project_dir = "backup1"
handlesize = 0
errorcnt = 0;
def SetWindows():
global slash
slash = '/'
def SetLinux():
global slash
slash = '/'
def SetMac():
global slash
slash = '/'
def open_log_file( projectname ):
global backup_root_dir
global backup_project_dir
node_dir = backup_root_dir + '/' + backup_project_dir + '/backup_info.txt'
myfile = open( node_dir, "w" )
myfile.write( "#################################################################################\n");
myfile.write( "# \n" );
myfile.write( "# Version : " + plemke_version + "\n");
myfile.write( "# Author : Pmg Lemmen \n");
myfile.write( "# project : " + projectname + "\n" );
myfile.write( "# \n" );
myfile.write( "#################################################################################\n");
myfile.close()
def write_log_file( text ):
global backup_root_dir
global backup_project_dir
node_dir = backup_root_dir + '/'+ backup_project_dir + '/backup_info.txt'
myfile = open( node_dir , "a" )
myfile.write( text+"\n");
myfile.close()
##############################################################
def SystemInit():
global platform
global root
platform = os.name
if platform == "nt":
SetWindows()
if platform == "mac":
SetMac()
if platform == "linux":
SetLinux()
##############################################################
def Help():
url = 'http://www.dutchdevelopers.nl/'
webbrowser.open_new(url)
##############################################################
def Manual():
url = 'http://www.dutchdevelopers.nl/nukemanual'
webbrowser.open_new(url)
##############################################################
def collectPanel():
colPanel = nuke.Panel("Consolidator")
colPanel.addFilenameSearch("Output Path:", "")
colPanel.addButton("Cancel")
colPanel.addButton("OK")
retVar = colPanel.show()
pathVar = colPanel.value("Output Path:")
return (retVar, pathVar)
##############################################################
def convert_file_to_relative( inname ):
nuke.message( inname )
##############################################################
#
def prepare_current_project():
global globalprogress
global project_file_name
global project_file_dir
global backup_root_dir
global backup_project_dir
global backup_project_name
nuke.selectAll();
errorcnt = 0;
backup_project_name = backup_root_dir + '/' + backup_project_dir
if os.path.lexists( backup_root_dir ) == False:
os.mkdir( backup_root_dir )
if os.path.lexists( backup_project_name ) == False:
os.mkdir( backup_project_name )
project_fps = nuke.Root()['fps'].value()
project_file_name = nuke.Root()['name'].value()
project_file_dir = nuke.root()['project_directory'].value() ;
if project_file_dir != "" :
project_file_dir = nuke.root()['project_directory'].value() + '/';
#// + '/'
globalprogress = nuke.ProgressTask("Plemkes consolidator")
globalprogress.setProgress(0)
return 0
def ok_to_backup( anode ):
global only_enabled_nodes
if only_enabled_nodes == False:
return True
if anode['disable'].value() == True:
return False
return True
def make_node_dir( inode ):
global plemke_version
global backup_root_dir
global backup_project_name
node_name = inode['name'].value()
node_dir = backup_root_dir + '/' + backup_project_dir + '/'+ node_name
if os.path.lexists( node_dir ) == False:
os.mkdir( node_dir )
myfile = open( node_dir+'/'+node_name+'_info.txt', "w" )
myfile.write( "#################################################################################\n");
myfile.write( "# \n" );
myfile.write( "# Version : " + plemke_version + "\n");
myfile.write( "# Author : Pmg Lemmen \n");
myfile.write( "# nodename : " + node_name + "\n" );
myfile.write( "# Org path : " + inode['file'].value()+ "\n" );
myfile.write( "# \n" );
myfile.write( "#################################################################################\n");
myfile.close()
return node_dir
def backup_image_sequence( inode ):
global errorcnt
global handlesize
dest = make_node_dir( inode )
first = inode['first'].value() - int( handlesize );
last = inode['last'].value() + int( handlesize );
total = last-first
deler = 1.0/total
frame_range = range( first , last )
filename = inode['file'].value();
globalprogress.setMessage( "backup Node : "+inode['name'].value() + " "+str(total ) + " Frames \n")
for frame in frame_range :
globalprogress.setMessage( "Frame "+str(frame-first) + " from " +str(total ) + " Frames \n")
if globalprogress.isCancelled():
break
newfilename = filename % frame
source_file = project_file_dir + newfilename
if os.path.lexists( source_file ) == False:
errorcnt = errorcnt + 1
write_log_file( "Missing source in sequence : "+source_file )
else:
if os.path.lexists( dest+'/'+ os.path.basename( newfilename ) ) == False:
shutil.copy( source_file , dest )
a=0
pos = 100.0 * deler * ( frame - first )
globalprogress.setProgress( int( pos ) )
file_name = os.path.basename( filename )
new_path = inode.knob('name').value() + slash + file_name
inode.knob('file').setValue( new_path );
def backup_image_file( inode ):
global errorcnt
dest = make_node_dir( inode )
filename = inode['file'].value();
globalprogress.setMessage( "backup Node : "+inode['name'].value() )
source_file = project_file_dir + filename
if os.path.lexists( source_file ) == False:
errorcnt = errorcnt + 1
write_log_file( "Missing source : "+source_file )
else:
shutil.copy( source_file , dest )
file_name = os.path.basename( filename )
new_path = inode.knob('name').value() + slash + file_name
inode.knob('file').setValue( new_path );
def backup_audio_file( inode ):
global errorcnt
dest = make_node_dir( inode )
filename = inode['file'].value();
globalprogress.setMessage( "backup Node : "+inode['name'].value() )
source_file = project_file_dir + filename
if os.path.lexists( source_file ) == False:
errorcnt = errorcnt + 1
write_log_file( "Missing source : "+source_file )
else:
shutil.copy( source_file , dest )
file_name = os.path.basename( filename )
new_path = inode.knob('name').value() + slash + file_name
inode.knob('file').setValue( new_path );
def backup_geo_file( inode ):
global errorcnt
dest = make_node_dir( inode )
filename = inode['file'].value();
globalprogress.setMessage( "backup Node : "+inode['name'].value() )
source_file = project_file_dir + filename
if os.path.lexists( source_file ) == False:
errorcnt = errorcnt + 1
write_log_file( "Missing source : "+source_file )
else:
shutil.copy( source_file , dest )
file_name = os.path.basename( filename )
new_path = inode.knob('name').value() + slash + file_name
inode.knob('file').setValue( new_path );
def backup_movie_file( mnode ):
global errorcnt
dest = make_node_dir( mnode )
filename = mnode['file'].value();
source_file = project_file_dir + filename
globalprogress.setMessage( "backup movie Node : "+mnode['name'].value() )
nuke.message( source_file )
if os.path.lexists( source_file ) == False:
errorcnt = errorcnt + 1
write_log_file( "Missing source : "+source_file )
else:
shutil.copy( source_file , dest )
file_name = os.path.basename( filename )
new_path = mnode.knob('name').value() + slash + file_name
mnode.knob('file').setValue( new_path );
def read_root_item( items ):
nuke.message( items['name'].value() )
def read_graphic_node( items ):
if ok_to_backup( items ) == False :
return False
chars = set('%#')
first = items['first'].value();
last = items['last'].value();
total = last - first
media_type = "unknown"
if total > 0 :
filename = items['file'].value()
if any( (c in chars ) for c in filename ):
backup_image_sequence( items )
else:
backup_movie_file( items )
else:
backup_image_file( items )
def read_viewer_node( vnode ):
global only_enabled_nodes
def read_audio_node( anode ):
global only_enabled_nodes
if ok_to_backup( anode ) == True :
backup_audio_file( anode )
def read_geo2_node( anode ):
global only_enabled_nodes
if ok_to_backup( anode ) == True :
backup_geo_file( anode )
def read_node( nodename , node ):
if nodename == 'Root':
read_root_node( node )
elif nodename == 'Viewer':
read_viewer_node( node )
elif nodename == 'ReadGeo':
read_geo2_node( node )
elif nodename == 'ReadGeo2':
read_geo2_node( node )
elif nodename == 'AudioRead':
read_audio_node( node )
elif nodename == 'Read':
read_graphic_node( node )
##############################################################
# Parent Function
def dutchdevscripts():
global globalprogress
global only_enabled_nodes
global backup_project_dir
global backup_root_dir
global handlesize
global plemke_version
dpan = nuke.Panel( "Where to save?");
dpan.setWidth( 300 );
dpan.setTitle( "plemkes consolidator "+plemke_version );
dpan.addBooleanCheckBox( "backup enabled nodes only" , False );
dpan.addSingleLineInput( "Handle size" , str( handlesize ) );
dpan.addFilenameSearch( "Folder Path" , "Select backup folder" );
dpan.addSingleLineInput( "Backup name" , "NKBK_0001" );
if dpan.show() == 1 :
backup_root_dir = dpan.value('Folder Path' )
backup_project_dir = dpan.value('Backup name' )
else:
nuke.message('You have to select a backup directory ')
return 0
only_enabled_nodes = dpan.value('backup enabled nodes only' )
handlesize = dpan.value('Handle size' )
prepare_current_project()
backup_project_name = 'backup_'+ os.path.basename( project_file_name )
open_log_file( backup_project_name )
for items in nuke.allNodes():
bla = items.Class()
read_node( bla , items )
#### for some strange reasons it skipped reads
new_project_directory = backup_root_dir+'/'+backup_project_dir
setting_proj_dir = nuke.root()['project_directory']
setting_proj_dir.setValue( new_project_directory )
out_name = backup_root_dir + '/'+ backup_project_dir + '/' + backup_project_name
nuke.scriptSave( out_name )
node_dir = backup_root_dir + '/' + backup_project_dir + '/backup_info.txt'
nuke.message( "Backup Done\nThere are "+ str( errorcnt ) + " Errors \nErrors are mostly missing source files\nOpen "+node_dir + " to check the errors ")
del globalprogress
return 1
##############################################################
#
SystemInit()