forked from liorbenhorin/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.py
6277 lines (4603 loc) · 258 KB
/
pipeline.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
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
'''
PIPELINE
1.0.0-beta
Project manager for Maya
Ahutor: Lior Ben Horin
All rights reserved (c) 2016
liorbenhorin.ghost.io
liorbenhorin@gmail.com
---------------------------------------------------------------------------------------------
install:
Place the pipeline folder in your maya scripts folder. Run these lines in a python tab in the script editor:
from pipeline import pipeline
reload(pipeline)
pipeline.show()
---------------------------------------------------------------------------------------------
You are using PIPELINE on you own risk.
Things can allways go wrong, and under no circumstances the author
would be responsible for any damages cuesed from the use of this software.
When using this beta program you hearby agree to allow this program to collect
and send usage data to the author.
---------------------------------------------------------------------------------------------
The coded instructions, statements, computer programs, and/or related
material (collectively the "Data") in these files are subject to the terms
and conditions defined by
Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License:
http://creativecommons.org/licenses/by-nc-nd/4.0/
http://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
http://creativecommons.org/licenses/by-nc-nd/4.0/legalcode.txt
---------------------------------------------------------------------------------------------
'''
# from PySide import QtCore, QtGui
# from shiboken import wrapInstance
import maya.OpenMayaUI as omui
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
import os
from modules.Qt import QtGui, QtWidgets, QtCore, QtCompat
# from PySide2 import QtGui, QtWidgets, QtCore
import logging
try:
import pysideuic
from shiboken import wrapInstance
logging.Logger.manager.loggerDict["pysideuic.uiparser"].setLevel(logging.CRITICAL)
logging.Logger.manager.loggerDict["pysideuic.properties"].setLevel(logging.CRITICAL)
except ImportError:
import pyside2uic as pysideuic
from shiboken2 import wrapInstance
logging.Logger.manager.loggerDict["pyside2uic.uiparser"].setLevel(logging.CRITICAL)
logging.Logger.manager.loggerDict["pyside2uic.properties"].setLevel(logging.CRITICAL)
import xml.etree.ElementTree as xml
from cStringIO import StringIO
import pymel.core as pm
import maya.mel as mel
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from maya.app.general.mayaMixin import MayaQDockWidget
from maya.OpenMayaUI import MQtUtil
import operator
import warnings
import time
from timeit import default_timer as timer
import collections
import webbrowser
import glob
import sys
import inspect
'''
log_file = os.path.join(os.path.dirname(__file__), 'pipeline_log.txt')
log = logging.getLogger(__name__)
hdlr = logging.FileHandler(log_file, mode = 'w')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
log.handlers[:] = [hdlr]
log.setLevel(logging.DEBUG)
'''
global start_time
global end_time
start_time = timer()
import modules.data as data
reload(data)
import modules.files as files
reload(files)
import modules.maya_warpper as maya
reload(maya)
import dialogue as dlg
reload(dlg)
log_file = os.path.join(os.path.dirname(__file__), 'pipeline_log.txt')
log = logging.getLogger(__name__)
hdlr = logging.StreamHandler(stream=sys.stdout)
hdlr = logging.FileHandler(log_file, mode = 'w')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
log.handlers[:] = [hdlr]
log.setLevel(logging.DEBUG)
def general_log():
if 'UiWindow' in globals():
UiWindow.log()
UiWindow.log_settings()
else:
log.info("cannot log anything - ui is not loaded")
# def standard_error_report_handler():
#
# py_file_dir = os.path.dirname(__file__)
# log_file = os.path.join(py_file_dir, 'error_reports','ERROR REPORT - %s.txt'%(time.strftime("%Y-%m-%d %H-%M-%S")))
# files.assure_path_exists(log_file)
# exp_hdlr = logging.StreamHandler(stream=sys.stdout)
# exp_hdlr = logging.FileHandler(log_file, mode = 'w')
# formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
# exp_hdlr.setFormatter(formatter)
# log.addHandler(exp_hdlr)
# log.info('ERROR REPORT - %s.txt'%(time.strftime("%Y-%m-%d %H-%M-%S")))
# log.info('Platform - %s'%(files.os_qeury()))
# log.info('Maya version - %s'%maya.maya_version())
# log.info('Pipeline version - %s'%version)
# py_file = os.path.realpath(__file__)
# log.info('pipeline.py path - %s'%py_file)
# return exp_hdlr, log_file
#
#
# def exception_report(file=None,settings_file=None):
# if file:
# string = files.read(file)
# errorDlg = dlg.ErrorReport(plainText = string)
# note = errorDlg.exec_()
# text, usertext, dont_ask = errorDlg.result()
# try:
# if dont_ask:
# UiWindow.ui.actionBug_reports.setChecked(False)
# else:
# UiWindow.ui.actionBug_reports.setChecked(True)
# except:
# log.info("ui is not loaded - 'don't show this again' settings is not saved")
#
# if note == QtWidgets.QDialog.Accepted:
# import modules.email as email
# body = usertext + '\n\n\n' + text
# email.mailto('liorbenhorin@gmail.com', subject='Pipeline error report - %s.txt'%(time.strftime("%Y-%m-%d %H-%M-%S")), body=body)
#
# def try_execpt(fn):
#
# def wrapped(self,*args,**kwargs):
# try:
# return fn(self,*args,**kwargs)
#
# except StandardError:
# exc_info = sys.exc_info()
# exp_hdlr, log_file = standard_error_report_handler()
#
# if 'UiWindow' in globals():
# try:
# UiWindow.log_settings()
# except:
# log.info("unable to log the settings")
# else:
# log.info("cannot log anything - ui is not loaded")
#
# try:
#
# self.log()
# log.info("exception at %s.%s"%(self.__class__.__name__, fn.__name__), exc_info=True)
# log.removeHandler(exp_hdlr)
# except:
# log.info("exception at %s - faild to log more information"%(fn.__name__), exc_info=True)
# log.removeHandler(exp_hdlr)
#
# try:
# if UiWindow.ui.actionBug_reports.isChecked():
# exception_report(log_file)
# except:
# exception_report(log_file)
#
# raise StopIteration
#
# return wrapped
#
#
# def exceptions_handler(decorator):
# def decorate(cls):
# for name, fn in inspect.getmembers(cls, inspect.ismethod):
# if name is not 'log':
# setattr(cls, name, decorator(fn))
#
# return cls
# return decorate
#
# def handle_uncaught_exception(exc_type, exc_value, exc_traceback):
#
# if issubclass(exc_type, KeyboardInterrupt):
# sys.__excepthook__(exc_type, exc_value, exc_traceback)
# return
#
# # this will prevent for loop error from getting printed to screen
# if issubclass(exc_type, StopIteration):
# log.info("quitting iteration")
# return
#
# exp_hdlr, log_file = standard_error_report_handler()
# general_log()
# log.info("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
# log.removeHandler(exp_hdlr)
# exception_report(log_file)
#
#
# sys.excepthook = handle_uncaught_exception
def loadUiType(uiFile):
"""
:author: Jason Parks
Pyside lacks the "loadUiType" command, so we have to convert the ui file to py code in-memory first
and then execute it in a special frame to retrieve the form_class.
"""
parsed = xml.parse(uiFile)
widget_class = parsed.find('widget').get('class')
form_class = parsed.find('class').text
with open(uiFile, 'r') as f:
o = StringIO()
frame = {}
pysideuic.compileUi(f, o, indent=0)
pyc = compile(o.getvalue(), '<string>', 'exec')
exec pyc in frame
#Fetch the base_class and form class based on their type in the xml from designer
form_class = frame['Ui_%s'%form_class]
base_class = getattr(QtWidgets, widget_class)
return form_class, base_class
def maya_main_window():
main_window_ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(main_window_ptr), QtWidgets.QWidget)
# def maya_main_window():
# for widget in QtWidgets.QApplication.topLevelWidgets():
# if widget.objectName() == 'MayaWindow':
# return widget
'''
global variables setup
'''
main_uiFile = os.path.join(os.path.dirname(__file__), 'ui', 'pipeline_main_UI.ui')
main_form_class, main_base_class = loadUiType(main_uiFile)
projects_uiFile = os.path.join(os.path.dirname(__file__), 'ui', 'pipeline_projects_UI.ui')
projects_form_class, projects_base_class = loadUiType(projects_uiFile)
create_edit_project_uiFile = os.path.join(os.path.dirname(__file__), 'ui', 'pipeline_create_edit_project_UI.ui')
create_edit_project_form_class, create_edit_project_base_class = loadUiType(create_edit_project_uiFile)
__version__ = '1.0.3'
def set_icons():
global localIconPath
localIconPath = os.path.join(os.path.dirname(__file__), 'icons')
if not os.path.exists(localIconPath):
log.info("icons folder not found: %s"%localIconPath)
return
global offline_icon
global catagory_icon
global asset_icon
global component_icon
global new_icon
global delete_icon
global load_icon
global unload_icon
global project_icon
global users_icon
global settings_icon
global set_icon
global yes_icon
global no_icon
global search_icon
global edit_icon
global delete_folder_icon
global new_folder_icon
global open_icon
global save_icon
global save_master_icon
global add_icon
global down_arrow_icon
global import_icon
global export_icon
global help_icon
global anim_icon
global asset_mode_icon
global reload_icon
global shutter_icon
global camrea_icon
global play_icon
global comment_icon
global large_image_icon
global large_image_icon_dark
global large_image_icon_click
global large_image_icon_click_dark
global wide_image_icon
global wide_image_icon_click
global wide_image_icon_dark
global wide_image_icon_click_dark
offline_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"offline"))
catagory_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"catagory"))
asset_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"asset"))
component_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"component"))
new_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"new"))
delete_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"delete"))
load_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"load"))
unload_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"unload"))
project_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"project"))
users_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"users"))
settings_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"settings"))
set_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"set"))
yes_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"yes"))
no_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"no"))
search_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"search"))
edit_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"edit"))
delete_folder_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"delete_folder"))
new_folder_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"new_folder"))
open_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"open"))
save_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"save"))
save_master_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"save_master"))
add_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"add"))
down_arrow_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"down_arrow"))
import_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"import"))
export_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"export"))
help_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"help"))
anim_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"anim"))
asset_mode_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"asset_mode"))
reload_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"reload"))
shutter_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"shutter"))
camrea_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"camera"))
play_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"play"))
comment_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"comment"))
large_image_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"large_image"))
large_image_icon_dark = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"large_image_dark"))
large_image_icon_click = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"large_image_click"))
large_image_icon_click_dark = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"large_image_click_dark"))
wide_image_icon = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"wide_image"))
wide_image_icon_click = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"wide_image_click"))
wide_image_icon_dark = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"wide_image_dark"))
wide_image_icon_click_dark = QtGui.QPixmap(os.path.join(localIconPath, "%s.svg"%"wide_image_click_dark"))
# declare all the global icons variables
set_icons()
def set_padding(int, padding):
return str(int).zfill(padding)
class QLabelButton(QtWidgets.QLabel):
'''
custom QLbael the can send clicked signal
'''
def __init(self, parent):
QtWidgets.QLabel.__init__(self, parent)
def mouseReleaseEvent(self, ev):
click = ev.pos()
if self.mask().contains(click):
self.emit(QtCore.SIGNAL('clicked()'))
class alpha_button(QtWidgets.QWidget):
'''
custom QLbael the can send clicked signal, only from the pixmap are that has 100% alpha
used for the thumbnail transperent icon button
'''
def __init__(self, parent, alpha):
super(alpha_button, self).__init__(parent)
self.pixmap = alpha
self.button = QLabelButton(self)
self.button.setPixmap(self.pixmap)
self.button.setScaledContents(True)
self.button.setMask(self.pixmap.mask())
self.connect(self.button, QtCore.SIGNAL('clicked()'), self.onClick)
def onClick(self):
self.emit(QtCore.SIGNAL('clicked()'))
def set_pixmap(self, pixmap):
self.button.setPixmap(pixmap)
self.button.setScaledContents(True)
self.button.setMask(pixmap.mask())
class pipeline_data(object):
def __init__(self,**kwargs):
self.data_file = None
self.data_file_path = None
for key in kwargs:
if key == "path":
self.data_file_path = kwargs[key]
if self.data_file_path:
self.set_data_file(self.data_file_path)
def set_data_file(self,path):
if os.path.isfile(path):
self.data_file = data.pickleDict(path = path)
return True
else:
log.debug ("Invalid path to data file")
# @exceptions_handler(try_execpt)
class pipeline_component(pipeline_data):
def __init__(self,**kwargs):
pipeline_data.__init__(self, **kwargs)
self.project = None
for key in kwargs:
if key == "project":
self.project = kwargs[key]
self.settings = None
for key in kwargs:
if key == "settings":
self.settings = kwargs[key]
self.component_file = None
if self.data_file:
self.component_file = self.data_file.read()
def create(self, path, catagory_name, asset_name, component_name, project, settings, create_from):
self.project = project
self.settings = settings
versions_path = os.path.join(path, "versions")
masters_path = os.path.join(path, "masters")
tumbnails_path = os.path.join(path, "tumbnails")
for folder_path in [versions_path, masters_path, tumbnails_path]:
files.create_directory(folder_path)
if not create_from:
maya.new_scene()
maya.set_fps(self.project.project_fps)
maya.rewind()
elif create_from == "current_scene":
pass
version_number = set_padding(1,self.project.project_padding)
file_name = "%s_%s_%s.%s"%(asset_name,component_name,version_number,"ma")
scene_path = maya.save_scene_as(path = versions_path, file_name = file_name )
first_version = {}
first_version["path"] = scene_path
first_version["date_created"] = "%s %s"%(time.strftime("%d/%m/%Y"),time.strftime("%H:%M:%S"))
first_version["author"] = self.settings.user[0]
first_version["note"] = "No notes"
versions = {}
versions[version_number] = first_version
masters = {}
component_data = {}
component_data["component_name"] = component_name
component_data["asset_name"] = asset_name
component_data["catagory_name"] = catagory_name
component_data["versions"] = versions
component_data["masters"] = masters
path = os.path.join(path,"%s.%s"%(component_name,"pipe"))
self.component_file = data.pickleDict().create(path, component_data)
self.component_file = self.component_file.read()
return self
@property
def component_path(self):
if self.component_file:
if self.settings:
return os.path.join(self.settings.current_project_path, self.project.assets_dir,self.catagory_name,self.asset_name,self.component_name)
else:
return None
@property
def versions_path(self):
if self.component_file:
if self.settings:
return os.path.join(self.component_path, "versions")
else:
return None
@property
def masters_path(self):
if self.component_file:
if self.settings:
return os.path.join(self.component_path, "masters")
else:
return None
@property
def tumbnails_path(self):
if self.component_file:
if self.settings:
return os.path.join(self.component_path, "tumbnails")
else:
return None
@property
def versions_(self):
if self.component_file:
return self.component_file["versions"]
@versions_.setter
def versions_(self,versions):
if self.data_file:
data = {}
data["versions"] = versions
self.data_file.edit(data)
self.component_file = self.data_file.read()
@property
def masters_(self):
if self.component_file:
return self.component_file["masters"]
@masters_.setter
def masters_(self,masters):
if self.data_file:
data = {}
data["masters"] = masters
self.data_file.edit(data)
self.component_file = self.data_file.read()
@property
def component_name(self):
if self.component_file:
try:
return self.component_file["component_name"]
except:
return None
else:
return None
@component_name.setter
def component_name(self,name):
if self.data_file:
data = {}
data["component_name"] = name
self.data_file.edit(data)
self.component_file = self.data_file.read()
else:
return None
@property
def catagory_name(self):
if self.component_file:
return self.component_file["catagory_name"]
else:
return None
@catagory_name.setter
def catagory_name(self,name):
if self.data_file:
data = {}
data["catagory_name"] = name
self.data_file.edit(data)
self.component_file = self.data_file.read()
else:
return None
@property
def asset_name(self):
if self.component_file:
return self.component_file["asset_name"]
else:
return None
@asset_name.setter
def asset_name(self,name):
if self.data_file:
data = {}
data["asset_name"] = name
self.data_file.edit(data)
self.component_file = self.data_file.read()
else:
return None
@property
def component_public_state(self):
if self.component_file:
if "component_public_state" in self.component_file:
return self.component_file["component_public_state"]
else:
# for legacy components, if no public state key exists, then the component is public
return True
else:
return None
@component_public_state.setter
def component_public_state(self,state):
if self.data_file:
data = {}
data["component_public_state"] = state
self.data_file.edit(data)
self.component_file = self.data_file.read()
else:
return None
def path(self, type, version):
if self.component_file:
try:
version_data = self.component_file[type][version]
return version_data["path"]
except:
return None
else:
return None
def author(self, type, version):
if self.component_file:
try:
version_data = self.component_file[type][version]
return version_data["author"]
except:
return None
else:
return None
def date_created(self, type, version):
if self.component_file:
try:
version_data = self.component_file[type][version]
return version_data["date_created"]
except:
return None
else:
return None
def note(self, type, version, **kwargs):
if self.component_file:
note = None
for key in kwargs:
if key == "note":
note = kwargs[key]
if note:
data = self.data_file.read()
data[type][version]["note"] = note
self.data_file.edit(data)
self.component_file = self.data_file.read()
return True
else:
try:
version_data = self.component_file[type][version]
return version_data["note"]
except:
return None
else:
return None
def size(self, type, version):
if self.component_file:
size_mb = files.file_size_mb(self.file_path(type, version))
if size_mb:
return ("{0:.1f}".format(size_mb))
else:
# maybe this is the master file
size_mb = files.file_size_mb(self.master)
if size_mb:
return ("{0:.1f}".format(size_mb))
else:
return None
def file_path(self, type, version):
if self.component_file:
if self.settings:
if type == "masters" and version == str(set_padding(0,self.project.project_padding)):
return self.master
versions_path = os.path.join(self.settings.current_project_path, self.project.assets_dir,self.catagory_name,self.asset_name,self.component_name,type)
version_file = "%s_%s_%s.%s"%(self.asset_name,self.component_name,version,"ma") if type == "versions" else "%s_%s_%s_%s.%s"%(self.asset_name,self.component_name,"MASTER",version,"ma")
return os.path.join(versions_path, version_file)
else:
return None
@property
def versions(self):
if self.project:
if self.component_file:
versions = files.list_directory(self.versions_path,self.project.project_file_type)
versions_dict = files.dict_versions(versions,self.project.project_padding)
sorted_versions = files.sort_version(versions_dict)
return sorted_versions
def last_version(self):
if self.project:
if self.component_file:
if self.settings:
sorted_versions = self.versions
if sorted_versions:
return sorted_versions[-1]
def new_version(self):
if self.project:
if self.component_file:
versions = self.versions
versions = self.versions
if versions:
last = versions[-1]
else:
last = 0
version_number = set_padding(last+1,self.project.project_padding)
file_name = "%s_%s_%s.%s"%(self.asset_name,self.component_name,version_number,"ma")
scene_path = maya.save_scene_as(path = self.versions_path, file_name = file_name )
new_version = {}
new_version["path"] = scene_path
new_version["date_created"] = "%s %s"%(time.strftime("%d/%m/%Y"),time.strftime("%H:%M:%S"))
new_version["author"] = self.settings.user[0]#"USER"
new_version["note"] = "No notes"
versions = self.versions_
versions[version_number] = new_version
self.versions_ = versions
def delete_version(self, type, version):
if self.component_file:
if self.settings:
versions = self.versions_ if type == "versions" else self.masters_
if not isinstance(version, list):
files.delete(self.file_path(type, version))
if version in versions:
del versions[version]
if type == "versions":
self.versions_ = versions
else:
self.masters_ = versions
else:
for v in version:
files.delete(self.file_path(type, v))
if v in versions:
del versions[v]
if type == "versions":
self.versions_ = versions
else:
self.masters_ = versions
return True
else:
return None
@property
def masters(self):
if self.project:
if self.component_file:
if self.settings:
masters = files.list_directory(self.masters_path,self.project.project_file_type)
if masters:
masters_dict = files.dict_versions(masters,self.project.project_padding)
sorted_masters = files.sort_version(masters_dict)
return sorted_masters
else:
return None
@property
def master(self):
if self.project:
if self.component_file:
if self.settings:
master_name = "%s_%s_%s.%s"%(self.asset_name,self.component_name,"MASTER","ma")
master_file = os.path.join(self.component_path,master_name)
if os.path.isfile(master_file):
return master_file
return None
'''
@property
def thumbnail(self):
if self.project:
if self.component_file:
if self.settings:
thumbnail_name = os.path.join(self.tumbnails_path,"%s.%s"%(self.component_name,"png"))
if os.path.isfile(thumbnail_name):
return QtGui.QPixmap(thumbnail_name)
return large_image_icon
'''
@property
def thumbnail(self):
file = self.thumbnail_path
if file:
return QtGui.QPixmap(file)
return large_image_icon
@property
def thumbnail_path(self):
if self.project:
if self.component_file:
if self.settings:
thumbnail_name = os.path.join(self.tumbnails_path,"%s.%s"%(self.component_name,"png"))
if os.path.isfile(thumbnail_name):
return thumbnail_name
return None
def new_master(self, from_file = False):
if self.project:
if self.component_file:
if self.settings:
new_master = {}
new_master["date_created"] = "%s %s"%(time.strftime("%d/%m/%Y"),time.strftime("%H:%M:%S"))
new_master["author"] = self.settings.user[0]
new_master["note"] = "No notes"
if self.masters:
# master versions existst
masters = self.masters
last = masters[len(masters)-1]
version_number = set_padding(last+1,self.project.project_padding)
else:
# this will be the first master
version_number = set_padding(1,self.project.project_padding)
maya.clean_up_file()
file_name = "%s_%s_%s_%s.%s"%(self.asset_name,self.component_name,"MASTER",version_number,"ma")
if not from_file:
scene_path = maya.save_scene_as(path = self.masters_path, file_name = file_name )
else:
scene_path = os.path.join(self.masters_path,file_name)
files.file_copy(from_file, scene_path )
new_master["path"] = scene_path
masters = self.masters_
masters[str(set_padding(0,self.project.project_padding))] = new_master
masters[version_number] = new_master
self.masters_ = masters
master_name = "%s_%s_%s.%s"%(self.asset_name,self.component_name,"MASTER","ma")
master_file = os.path.join(self.settings.current_project_path,self.project.assets_dir,self.catagory_name,self.asset_name,self.component_name,master_name)
files.file_copy(scene_path, master_file)
maya.open_scene(master_file)
def make_master(self, version):
source = self.file_path("masters",version)
if source:
files.file_copy(source, self.master)
new_master = {}
new_master["date_created"] = self.date_created("masters",version)
new_master["author"] = self.author("masters",version)
new_master["note"] = self.note("masters",version)
masters = self.masters_
masters[str(set_padding(0,self.project.project_padding))] = new_master
self.masters_ = masters
return True
return False
def rename(self, new_name):
#asset_path = os.path.dirname(files.dir_rename(os.path.dirname(self.data_file_path),new_name))
#componentes = files.list_dir_folders(asset_path)
#if new_name in componentes:
# dlg.massage("critical", "Sorry", "This Component exsists" )
# return False
versions = {}
for version in self.versions:
version_number = set_padding(version,self.project.project_padding)
versions[version] = [self.file_path("versions",version_number), "%s_%s_%s"%(self.asset_name,new_name,version_number)]
files.file_rename(versions[version][0],versions[version][1])
if self.master:
masters = {}
for version in self.masters:
version_number = set_padding(version,self.project.project_padding)
masters[version] = [self.file_path("masters",version_number), "%s_%s_%s_%s"%(self.asset_name,new_name,"MASTER",version_number)]
files.file_rename(masters[version][0],masters[version][1])
master = [self.master, "%s_%s_%s"%(self.asset_name,new_name,"MASTER")]
files.file_rename(master[0],master[1])
thumb_path = os.path.join(self.tumbnails_path,"%s.%s"%(self.component_name,"png"))
if os.path.isfile(thumb_path):
files.file_rename(thumb_path,new_name)
self.component_name = new_name
path = files.file_rename(self.data_file_path,new_name)