-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckin.py
More file actions
1241 lines (953 loc) · 42.7 KB
/
Copy pathcheckin.py
File metadata and controls
1241 lines (953 loc) · 42.7 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
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
import cStringIO, os, re, shutil, sys, urllib
from xml.dom.minidom import parseString, parse
from xml.dom.minidom import getDOMImplementation
from common import *
#import tactic_load
from pyasm.application.common import *
class Checkin(object):
# class that creates the necessary files for checkin and uploads them
# to a server
def __init__(my):
my.env = AppEnvironment.get()
my.info = TacticInfo.get()
my.impl = my.info.get_app_implementation()
my.app = my.env.get_app()
my.app.set_namespace()
my.texture_paths = []
my.texture_nodes = []
my.texture_attrs = []
my.texture_file_codes = []
my.texture_md5_list = []
my.geo_info = []
# DEPRECATED
my.houdini_refs = []
my.generated_paths = []
my.upload_paths = []
my.options = {}
my.handlers = {}
my.handoff_dir = ''
#my.clean_up()
def clean_up(my):
ticket = my.env.get_ticket()
project_code = my.env.get_project_code()
# clear the upload dir first
from pyasm.application.common.interpreter.tactic_client_lib import *
client_server = TacticServerStub(setup=False)
server_name = my.env.get_server()
client_server.set_server(server_name)
client_server.set_project(project_code)
client_server.set_ticket(ticket)
client_server.clear_upload_dir()
def set_options(my, options_str):
exprs = options_str.split("|")
for expr in exprs:
name, value = expr.split("=")
my.options[name] = value
def set_option(my, name, value):
my.options[name] = value
def get_option(my, name):
if my.options.has_key(name):
return my.options[name]
else:
return ""
def set_handlers(my, handlers_str):
exprs = handlers_str.split("|")
for expr in exprs:
name, value = expr.split("=")
my.handlers[name] = value
def get_handler(my, name):
if my.handlers.has_key(name):
return my.handlers[name]
else:
return ""
def add_path(my, path):
my.generated_paths.append(path)
def upload_files(my):
upload_paths = Common.get_unique_list(my.generated_paths)
for path in upload_paths:
my.env.upload(path)
for path in my.upload_paths:
my.env.upload(path)
# remove upload files
#os.unlink(path)
def handoff_files(my):
dir = my.handoff_dir
for path in my.generated_paths:
file_name = os.path.basename(path)
file_name = Common.get_filesystem_name(file_name)
new_file_path = '%s/%s' %(dir, file_name)
print "copying to: ", new_file_path
shutil.copy(path, new_file_path)
for path in my.upload_paths:
my.env.upload(path)
def dump_nodes(my, asset_code, node_list):
''' exports non-tactic nodes'''
for node_name in node_list:
my._check_existence(node_name)
path = my._export_node(node_list, preserve_ref=False)
# dump out the reference file
return my.dump_file(asset_code, path, append=True)
def dump_node(my, node_name, instance=None):
'''exports a node and everything under it'''
namespace = my._check_existence(node_name)
# NOTE: Even an asset does not really have an instance, we must set
# it using the asset_name in checkin_asset, since the server checkin
# callback uses that to locate the description and ref.xml file
if not instance:
instance = namespace
# create the node data attribute if it doesn't exist
node_data = my.app.get_node_data(node_name)
node_data.create()
use_filename = True
if my.get_option('use_filename')=='false':
use_filename = False
my._export_node(node_name, use_filename=use_filename)
# dump out the reference file
return my.dump_ref(instance, [node_name])
def _check_existence(my, node_name):
# use naming to extract info
naming = my.app.get_node_naming(node_name)
namespace = naming.get_namespace()
asset_code = naming.get_asset_code()
# check whether node is in session
is_present = my.app.node_exists(node_name)
if not is_present:
msg = "Error: Node '%s' is not in the session" % node_name
raise TacticException(msg)
return namespace
def _export_node(my, node_name, preserve_ref=True, use_filename=True):
# NOTE: node_name can be a list ... should make this clearer
file_type = my.get_option("file_type")
context = my.get_option('context')
instance = my.get_option('instance')
filename = ''
export_method = my.get_option("export_method")
handler_cls = my.get_handler("checkin/create")
if export_method == "Pipeline" and handler_cls:
handler = AppEnvironment.create_from_class_path(handler_cls)
input = {'node_name': node_name}
handler.set_input(input)
handler.execute()
path = handler.get_output_value("path")
elif export_method == "Save":
# get the last saved file name and use it by default
old_path = my.app.get_file_path()
if use_filename and old_path:
filename = os.path.basename(old_path)
path = my.app.save("%s/%s" % (my.info.get_save_dir(), filename) )
else:
path = my.app.save_node(node_name, my.env.get_tmpdir(), type=file_type )
else:
old_path = my.app.get_file_path()
if use_filename:
filename = os.path.basename(old_path)
path = my.app.export_node(node_name, context, my.env.get_tmpdir(), \
type=file_type, preserve_ref=preserve_ref, filename=filename,\
instance=instance)
# now that the file is exported, allow an handler to process the file
handler_cls = my.get_handler("checkin/process")
if handler_cls:
handler = AppEnvironment.create_from_class_path(handler_cls)
handler.set_input({"path" : path})
handler.execute()
my.generated_paths.append(path)
# handle the dependencies in the old manner
if my.app.APPNAME == "maya":
md5_list = []
dependent_paths = my.handle_dependencies(path, node_name)
for dependent_path in dependent_paths:
my.generated_paths.append(dependent_path)
md5_list.append(Common.get_md5(dependent_path))
my.texture_md5_list = md5_list
return path
def handle_dependencies(my, path="", node_name=None):
'''record all the dependencies for a given session/app file'''
dependent_paths = []
if my.get_option('handle_texture_dependency')=='false':
return dependent_paths
# now that the file is exported, allow an handler to process the file
handler_cls = my.get_handler("checkin/dependency")
if handler_cls:
handler = AppEnvironment.create_from_class_path(handler_cls)
input = {"path":path, "node_name": node_name}
handler.set_input(input)
handler.execute()
# find all of the textures in the extracted file
if my.app.APPNAME == "maya":
if path.endswith(".ma"):
# handle the textures
my.texture_nodes, my.texture_paths, my.texture_attrs = \
my.impl.get_textures_from_path(path)
# remember all of the geo paths
my.geo_info = my.impl.get_geo_from_session(node_name)
for info in my.geo_info:
geo_path = info[1]
dependent_paths.append(geo_path)
else:
my.texture_nodes, my.texture_paths, my.texture_attrs = \
my.impl.get_textures_from_session(node_name)
elif my.app.APPNAME == "houdini":
my.texture_nodes, my.texture_paths, my.texture_attrs = \
my.app.get_textures_from_session(node_name)
elif my.app.APPNAME == "xsi":
if path.endswith(".xsi"):
my.texture_nodes, my.texture_paths, my.texture_attrs = \
my.impl.get_textures_from_path(path)
elif path.endswith(".emdl"):
my.texture_nodes, my.texture_paths, my.texture_attrs = \
my.app.get_textures_from_session(node_name)
# add all of the texture paths
for texture_path in my.texture_paths:
# FIXME: all of the texture paths are uploaded!!!, even if
# they are identical
dependent_paths.append(texture_path)
return dependent_paths
def read_file(my, file_path):
try:
file_path = file_path.replace("\\", "/")
doc = parse(file_path)
return doc
except Exception, e:
print "Error in xml file: ", file_path
raise Exception(e)
def dump_file(my, instance, ref_path, append=False):
'''dumps a file node in the ...ref.xml'''
# get all of the selected nodes
# This matches File.get_filesystem_name(instance)
filename = instance.replace("/", "__")
filename = filename.replace("|", "__")
filename = filename.replace(":", "__")
filename = filename.replace("?", "__")
filename = filename.replace("=", "__")
path = "%s/%s-ref.xml" % (my.env.get_tmpdir(), filename)
# dump info to send to the server
impl = getDOMImplementation()
doc = None
if append:
doc = my.read_file(path)
else:
doc = impl.createDocument(None, "session", None)
root = doc.documentElement
# create the top node reference
top_node = doc.createElement("file")
# add in a path
top_node.setAttribute("path", ref_path)
root.appendChild(top_node)
file = open(path, 'w')
file.write( doc.toprettyxml() )
file.close()
# return the xml file path
return path
def dump_ref(my, instance, node_names, append=False):
'''dumps all of the references in the group'''
# get all of the selected nodes
# This matches File.get_search_key(key)
file_name = Common.get_filesystem_name(instance)
path = "%s/%s-ref.xml" % (my.env.get_tmpdir(), file_name)
# dump info to send to the server
impl = getDOMImplementation()
doc = None
if append:
doc = my.read_file(path)
else:
doc = impl.createDocument(None, "session", None)
root = doc.documentElement
for node_name in node_names:
# create the top node reference
top_node = doc.createElement("ref")
if node_name:
node_naming = my.app.get_node_naming(node_name)
instance = node_naming.get_instance()
asset_snapshot_code = my.impl.get_snapshot_code(node_name,"asset")
anim_snapshot_code = my.impl.get_snapshot_code(node_name,"anim")
# add these assertions because if these are None, pretty print
# fails and it is difficult to find out where the error occured
assert asset_snapshot_code != None
assert anim_snapshot_code != None
assert instance != None
assert node_name != None
top_node.setAttribute("asset_snapshot_code", asset_snapshot_code)
top_node.setAttribute("anim_snapshot_code", anim_snapshot_code)
top_node.setAttribute("instance", instance)
top_node.setAttribute("node_name", node_name)
# add in a path
if my.generated_paths:
assert my.generated_paths[0] != None
top_node.setAttribute("path", my.generated_paths[0])
top_node.setAttribute("handoff_dir", my.handoff_dir)
# only generate for xsi as maya file may change on parsing
if my.app.name == 'xsi':
top_node_md5 = Common.get_md5(my.generated_paths[0])
top_node.setAttribute("md5", top_node_md5)
# add this top node
root.appendChild(top_node)
# get all of the tactic sub references.
sub_refs = my.app.get_reference_nodes(node_name)
for sub_ref in sub_refs:
node_naming2 = my.app.get_node_naming(sub_ref)
instance2 = node_naming2.get_instance()
sub_path = my.app.get_reference_path(sub_ref)
# remove maya's weird {#} at the end
sub_path = re.sub('{\d+}','', sub_path)
sub_asset_snapshot_code = my.impl.get_snapshot_code(sub_ref,"asset")
sub_anim_snapshot_code = my.impl.get_snapshot_code(sub_ref,"anim")
sub_node = doc.createElement("ref")
sub_node.setAttribute("asset_snapshot_code", sub_asset_snapshot_code)
sub_node.setAttribute("anim_snapshot_code", sub_anim_snapshot_code)
sub_node.setAttribute("instance", instance2)
sub_node.setAttribute("path", sub_path)
sub_node.setAttribute("node_name", sub_ref)
top_node.appendChild(sub_node)
# add in all of the textures
texture_nodes = my.texture_nodes
texture_paths = my.texture_paths
texture_attrs = my.texture_attrs
texture_file_codes = my.texture_file_codes
texture_md5_list = my.texture_md5_list
use_namespace = my.get_option('use_namespace')
for i in range(0, len(texture_paths)):
file_node = doc.createElement("file")
file_node.setAttribute("type", "texture")
# eliminate the namespace
if use_namespace:
texture_node = texture_nodes[i]
elif texture_nodes[i].find(":") != -1:
parts = texture_nodes[i].split(":")
texture_node = parts[-1]
else:
texture_node = texture_nodes[i]
file_node.setAttribute("node", texture_node)
file_node.setAttribute("attr", texture_attrs[i])
file_node.setAttribute("path", texture_paths[i])
try:
texture_file_code = texture_file_codes[i]
except IndexError:
texture_file_code = ''
file_node.setAttribute("code", texture_file_code)
# md5_list could be empty
if texture_md5_list:
md5 = texture_md5_list[i]
if md5:
file_node.setAttribute("md5", md5)
top_node.appendChild(file_node)
# add in the geo caches
for info in my.geo_info:
geo_node, geo_path = info
file_node = doc.createElement("file")
file_node.setAttribute("type", "geo")
file_node.setAttribute("path", geo_path)
file_node.setAttribute("node", geo_node)
top_node.appendChild(file_node)
# record the layers
if my.app.APPNAME == "maya":
layers = my.app.get_all_layers()
for layer in layers:
file_node = doc.createElement("layer")
file_node.setAttribute("name", layer)
top_node.appendChild(file_node)
"""
# Houdini references
# FIXME: I don't think this is necessary anymore.
for info in my.houdini_refs:
houdini_node = info[0]
houdini_attr = info[1]
houdini_path = info[2]
file_node = doc.createElement("file")
file_node.setAttribute("type", "texture")
file_node.setAttribute("path", houdini_path)
# TODO: this is the full node with the instance name. This
# should not have this hardcoded
file_node.setAttribute("node", houdini_node)
file_node.setAttribute("attr", houdini_attr)
top_node.appendChild(file_node)
"""
file = open(path, 'w')
file.write( doc.toprettyxml(encoding='utf-8'))
file.close()
#my.generated_paths.append(path)
# only this ref xml is uploaded
my.upload_paths.append(path)
return path
def dump_group(my, group_name, group_asset_code):
nodes = []
if my.get_option("selected") == "false":
'''nodes = my.app.get_top_nodes()
if not nodes:
msg = "No assets in session"
raise TacticException(msg)
'''
nodes = my.app.get_nodes_in_set(group_name)
else:
# get all of the selected nodes
nodes = my.app.get_selected_top_nodes()
if not nodes:
msg = "No assets selected"
raise TacticException(msg)
non_tactic_nodes = []
tactic_nodes = []
for node_name in nodes:
# dump the arbitrary nodes included in a set if any
if not my.app.is_tactic_node(node_name):
non_tactic_nodes.append(node_name)
else:
tactic_nodes.append(node_name)
# dump out the reference file
my.dump_ref(group_asset_code, tactic_nodes)
# dump out the animation for each interface
first = True
path = None
for node_name in tactic_nodes:
path = my._dump_interface(group_asset_code, node_name, first)
first = False
if non_tactic_nodes:
my.dump_nodes(group_asset_code, non_tactic_nodes)
return path
def _dump_interface(my, basename, node_name, create=True):
'''dump the animation: use animImport, but tag it with comments
so that multiple imports can be stored in the same file and
accessed non-linearly'''
node_naming = my.app.get_node_naming(node_name)
instance = node_naming.get_instance()
# dump the animation file
node_anim_path = my.impl.dump_interface(node_name)
#base, ext = os.path.splitext(node_anim_path)
ext = ".anim"
out_anim_file = "%s/%s%s" % (my.env.get_tmpdir(),basename,ext)
src_files = {}
src_files[node_anim_path] = 'ANIM'
if my.app.APPNAME == "maya":
# dump the static file for Maya
node_static_path = my.impl.dump_interface(node_name, mode='static')
src_files[node_static_path] = 'STATIC'
# copy into the master file
for src_file, src_file_type in src_files.items():
file = open(src_file, "r")
if create == True:
file2 = open(out_anim_file, "w")
create = False
# remember the created file
my.upload_paths.append(out_anim_file)
else:
file2 = open(out_anim_file, "a")
if my.app.APPNAME == "houdini":
file2.write("#------------------\n")
file2.write("#START_%s=%s\n" % (src_file_type, instance))
file2.write("#------------------\n")
else:
file2.write("//------------------\n")
file2.write("//START_%s=%s\n" % (src_file_type, instance))
file2.write("//------------------\n")
file2.write("\n")
for line in file.readlines():
# comment out the opadd for houdini
if my.app.APPNAME == "houdini" and line.startswith("opadd -n"):
line = "#%s" % line
file2.write(line)
if my.app.APPNAME == "houdini":
file2.write("#------------------\n")
file2.write("#END_%s=%s\n" % (src_file_type, instance))
file2.write("#------------------\n\n")
else:
file2.write("//------------------\n")
file2.write("//END_%s=%s\n" % (src_file_type, instance))
file2.write("//------------------\n\n")
file2.close()
file.close
return out_anim_file
def dump_anim(my, node_name):
'''dump out the animation of a node'''
node_naming = my.app.get_node_naming(node_name)
instance_name = node_naming.get_instance()
# dump out the reference file
my.dump_ref(instance_name, [node_name])
# dump out the animation for each interface
out_file = my._dump_interface(instance_name, node_name, True)
return out_file
# API commands
def checkin_asset_old(namespace, asset_code, instance, options=None, handlers=None):
env = AppEnvironment.get()
ticket = env.get_ticket()
checkin = Checkin()
naming = checkin.app.get_node_naming()
naming.set_namespace(namespace)
naming.set_asset_code(asset_code)
node_name = naming.get_node_name()
if options:
checkin.set_options(options)
if checkin.get_option('clean_up') == 'true':
checkin.clean_up()
if handlers:
checkin.set_handlers(handlers)
export_method = checkin.get_option("export_method")
handler_cls = checkin.get_handler("checkin/pre_export")
if handler_cls:
handler = AppEnvironment.create_from_class_path(handler_cls)
input = {'node_name': node_name}
handler.set_input(input)
handler.execute()
current_path = checkin.app.get_file_path()
checkin.handoff_dir = get_handoff_dir(ticket, env)
checkin.dump_node(node_name, instance)
# rename back to the original path
checkin.app.rename(current_path)
use_handoff_dir = checkin.get_option("use_handoff_dir") == 'true'
if use_handoff_dir:
checkin.handoff_files()
else:
checkin.upload_files()
#def checkin_binary_asset(namespace, asset, instance, options=None):
def checkin_asset(namespace, asset_code, instance, options=None, handlers=None):
'''try checkin in an asset with a binary file format ... this checkin
mode requires the application for inspection of the dependent assets'''
# 1) dump out the ref and checkin all files with placeholder main file
# 2) get all the checked in filenames back
# 3) copy all the dependent paths to the local repo with the new names (if they don't already exist)
# 4) change all of the paths in session
# 5) dump out the node with the new paths
# 6) replace the main file in the repo
# 7) switch to paths in local repo
# HACK: maya only supports ascii files because of textures
# get some info
env = AppEnvironment.get()
app = env.get_app()
if app.APPNAME == "maya":
return checkin_asset_old(namespace, asset_code, instance, options, handlers)
ticket = env.get_ticket()
server = env.get_xmlrpc_server()
project_code = env.get_project_code()
checkin = Checkin()
naming = checkin.app.get_node_naming()
naming.set_namespace(namespace)
naming.set_asset_code(asset_code)
node_name = naming.get_node_name()
if options:
checkin.set_options(options)
if checkin.get_option('clean_up') == 'true':
checkin.clean_up()
if handlers:
checkin.set_handlers(handlers)
# replace local references with lib_path in case loaded thru http mode
swap_ref_path(ticket, env, checkin.app)
# find the dependent files and upload them
file_type = checkin.get_option("file_type")
use_handoff_dir = checkin.get_option("use_handoff_dir") == 'true'
mode = checkin.get_option("texture_match")
dependency = Dependency(node_name, file_type)
handle_texture = checkin.get_option('handle_texture_dependency') =='true'
# check if we want to handle textures
if handle_texture:
dependency.execute()
filtered_texture_paths, filtered_texture_nodes, filtered_texture_attrs, filtered_md5s = [], [], [], []
repo_texture_paths, repo_texture_nodes, repo_texture_attrs, repo_file_ranges, repo_file_codes = [], [], [], [], []
# these original attrs are used at the end, do not alter them
texture_paths, texture_nodes, texture_attrs = dependency.get_texture_info()
# check for existence:
progress = checkin.impl.start_progress('Verifications...', True, 1 + len(texture_paths))
if checkin.app.is_reference(node_name):
checkin.info.report_error(' [%s] is a reference ' %node_name)
else:
progress.increment()
for path in texture_paths:
progress.increment()
# skip checking for file group
if checkin.impl.is_file_group(path):
continue
if not os.path.exists(path):
checkin.info.report_error('Path [%s] does not exist' %path)
progress.stop()
return
progress.stop()
"""
use_handoff_dir = False
if app.name == 'xsi':
use_handoff_dir = True
"""
md5_list = []
if handle_texture:
if mode == 'md5':
title = 'Analyzing file md5...'
else:
title = 'Analyzing file name...'
progress = checkin.impl.start_progress(title, True, len(texture_paths))
# need md5 for both modes
for tex_path in texture_paths:
md5_list.append(Common.get_md5(tex_path))
progress.increment()
checkin.texture_md5_list = md5_list
if use_handoff_dir:
from pyasm.application.common.interpreter.tactic_client_lib import *
client_server = TacticServerStub(setup=False)
project_code = env.get_project_code()
server_name = env.get_server()
client_server.set_server(server_name)
client_server.set_project(project_code)
client_server.set_ticket(ticket)
try:
client_server.start("Transferring Textures")
dir = client_server.get_handoff_dir()
checkin.handoff_dir = dir
# check for already checked in texture and determine what to copy over
#texture_codes = [checkin.impl.get_texture_code(asset_code, x) for x in texture_nodes]
#md5_list = [ None for x in xrange(len(texture_paths))]
# use forward path to avoid auto escaping
forward_texture_paths = [ x.replace('\\','/') for x in texture_paths]
file_group_dict = get_file_group_dict(checkin, forward_texture_paths)
md5_info = client_server.get_md5_info(md5_list, forward_texture_paths, asset_code, 'Texture', file_group_dict, project_code, mode)
for idx, texture_path in enumerate(texture_paths):
#texture_code = texture_codes[idx]
# key contains tex code and path
key = forward_texture_paths[idx]
# the path has to correspond to the corresponding texture code list
sub_info = md5_info.get(key)
is_match = False
if sub_info:
is_match = sub_info.get('is_match')
if not is_match:
filtered_texture_paths.append(texture_path)
filtered_texture_nodes.append(texture_nodes[idx])
filtered_texture_attrs.append(texture_attrs[idx])
filtered_md5s.append(md5_list[idx])
else:
repo_path = md5_info.get(key).get('repo_path')
repo_file_code = md5_info.get(key).get('repo_file_code')
repo_texture_paths.append(repo_path)
repo_file_codes.append(repo_file_code)
repo_texture_nodes.append(texture_nodes[idx])
repo_texture_attrs.append(texture_attrs[idx])
# should check the original path here
if checkin.impl.is_file_group(texture_path):
file_range = md5_info.get(key).get('repo_file_range')
repo_file_ranges.append(file_range)
else:
repo_file_ranges.append(None)
progress.stop()
handoff_texture_paths, file_ranges = copy_file(checkin, filtered_texture_paths, dir)
app.message("[%s] Textures to be checked in: " %len(filtered_texture_paths))
for idx, path in enumerate(filtered_texture_paths):
app.message("%s. (%s)-(%s)" % ( (idx+1), path, filtered_texture_nodes[idx]))
except:
client_server.abort()
raise
else:
# do not finish() here as the CheckinCbk is run right after
if checkin.get_option('use_batch')=='true':
pass
else:
client_server.finish()
else:
progress = checkin.impl.start_progress('Texture Uploading', True, len(texture_paths))
for path in texture_paths:
progress.increment()
env.upload(path)
progress.stop()
# there is no handoff here really
handoff_texture_paths = texture_paths
filtered_texture_nodes = texture_nodes
filtered_texture_attrs = texture_attrs
file_ranges = [None for x in xrange(len(texture_paths))]
# just check in external references, which are checked in separately
new_paths, file_code_list = server.checkin_textures(ticket, project_code, asset_code, handoff_texture_paths, file_ranges, filtered_texture_nodes, filtered_texture_attrs, use_handoff_dir, filtered_md5s)
# combine the list together
checkin.texture_paths = new_paths + repo_texture_paths
checkin.texture_nodes = filtered_texture_nodes + repo_texture_nodes
checkin.texture_attrs = filtered_texture_attrs + repo_texture_attrs
checkin.texture_file_codes = file_code_list + repo_file_codes
whole_file_ranges = file_ranges + repo_file_ranges
# remap the paths according to app
for i, texture_node in enumerate(checkin.texture_nodes):
texture_attr = checkin.texture_attrs[i]
new_path = checkin.texture_paths[i]
file_range = whole_file_ranges[i]
if Common.is_file_group(new_path):
new_path = checkin.impl.get_app_file_group_path(new_path, file_range)
try:
app.set_attr(texture_node, texture_attr, new_path, "string")
except AppException, e:
checkin.info.report_warning('Failed Attribute Setting', str(e))
continue
# provide callback for users to do whatever they wish to the maya file
ClientTrigger.call("pre_asset_export")
# dump node with all of the dependencies
try:
current_path = checkin.app.get_file_path()
app_path = checkin.dump_node(node_name, instance)
if use_handoff_dir:
checkin.handoff_files()
else:
checkin.upload_files()
#Trigger.call("postdump")
finally:
# set this back even if something goes wrong
checkin.app.rename(current_path)
# move the attributes back to what they were before the dump
# TODO: this should be an option
for i, texture_node in enumerate(texture_nodes):
texture_attr = texture_attrs[i]
old_path = texture_paths[i]
try:
app.set_attr(texture_node, texture_attr, old_path, "string")
except AppException, e:
checkin.info.report_warning('Failed Attribute Setting', str(e))
continue
def swap_ref_path(ticket, env, app):
if app.name != 'xsi':
return
ref_nodes = app.get_reference_nodes()
for ref_node in ref_nodes:
node_data= app.get_node_data(ref_node)
snap_code = node_data.get_attr('asset_snapshot', 'code')
from pyasm.application.common.interpreter.tactic_client_lib import *
client_server = TacticServerStub(setup=False)
client_server.set_ticket(ticket)
project = env.get_project_code()
server_name = env.get_server()
client_server.set_server(server_name)
client_server.set_project(project)
lib_path = ''
client_server.start("Retrieving Lib Path")
try:
if not snap_code:
continue
lib_path = client_server.get_path_from_snapshot(snap_code, file_type=app.APPNAME)
except:
client_server.abort()
raise
else:
client_server.finish()
app.message("Replacing path for [" + ref_node + "] with " + lib_path)
app.update_reference(ref_node, lib_path, top_reference=True)
def get_file_group_dict(checkin, file_paths):
'''get a dictionary of <original file path>: tactic_file_path, file_range. It also determines an implicitly
stated range for certain 3d apps'''
file_range = ''
file_group_dict = {}
flex_range = checkin.app.has_flex_range()
for file_path in file_paths:
file_range = ''
if checkin.impl.is_file_group(file_path):
file_range = checkin.impl.get_file_range(file_path)
#file_ranges.append(file_range)
tactic_file_path = checkin.impl.get_tactic_file_group_path(file_path)
file_group = Common.expand_paths(tactic_file_path, file_range)
new_file_range = Common.get_file_range(file_range)
is_start_set = False
start_frame = new_file_range[0]
end_frame = new_file_range[1]
for idx, path in enumerate(file_group):
if flex_range:
# determine the implicit flexible range
if os.path.exists(path):
pat = re.compile('.*\.(\d+)\..*')
m = pat.match(path)
num = int(m.groups()[0])
if not is_start_set and num >= new_file_range[0]:
start_frame = num
is_start_set = True
end_frame = num
else:
continue
if flex_range:
file_range = '%s-%s/%s'%(start_frame, end_frame, new_file_range[2])
file_group_dict[file_path] = tactic_file_path, file_range
return file_group_dict
def copy_file(checkin, file_paths, new_dir):
'''copy file to the handoff dir'''
new_file_paths = []
file_ranges = []
if not file_paths:
return new_file_paths, file_ranges
progress = checkin.impl.start_progress('Texture Copying', True, len(file_paths))
file_group_dict = get_file_group_dict(checkin, file_paths)
for file_path in file_paths:
progress.increment()
if checkin.impl.is_file_group(file_path):