@@ -419,14 +419,14 @@ def _get_item_context_from_path(self, work_path_template, path, parent_item, def
419
419
else :
420
420
return parent_item .context
421
421
422
- def _collect_file (self , settings , parent_item , path ):
422
+ def _collect_file (self , settings , parent_item , path , creation_properties = None ):
423
423
"""
424
424
Process the supplied file path.
425
425
426
426
:param dict settings: Configured settings for this collector
427
427
:param parent_item: parent item instance
428
428
:param path: Path to analyze
429
- :param frame_sequence: Treat the path as a part of a sequence
429
+ :param creation_properties: The dict of initial properties for the item
430
430
431
431
:returns: The item that was created
432
432
"""
@@ -470,7 +470,8 @@ def _collect_file(self, settings, parent_item, path):
470
470
)
471
471
return
472
472
473
- file_item = self ._add_file_item (settings , parent_item , path , is_sequence , seq_files )
473
+ file_item = self ._add_file_item (settings , parent_item , path , is_sequence , seq_files ,
474
+ creation_properties = creation_properties )
474
475
if file_item :
475
476
if is_sequence :
476
477
# include an indicator that this is an image sequence and the known
@@ -498,13 +499,14 @@ def _collect_file(self, settings, parent_item, path):
498
499
499
500
return file_item
500
501
501
- def _collect_folder (self , settings , parent_item , folder ):
502
+ def _collect_folder (self , settings , parent_item , folder , creation_properties = None ):
502
503
"""
503
504
Process the supplied folder path.
504
505
505
506
:param dict settings: Configured settings for this collector
506
507
:param parent_item: parent item instance
507
508
:param folder: Path to analyze
509
+ :param creation_properties: The dict of initial properties for the item
508
510
509
511
:returns: The item that was created
510
512
"""
@@ -519,7 +521,8 @@ def _collect_folder(self, settings, parent_item, folder):
519
521
520
522
file_items = []
521
523
for path , seq_files in frame_sequences :
522
- file_item = self ._add_file_item (settings , parent_item , path , True , seq_files )
524
+ file_item = self ._add_file_item (settings , parent_item , path , True , seq_files ,
525
+ creation_properties = creation_properties )
523
526
if file_item :
524
527
# include an indicator that this is an image sequence and the known
525
528
# file that belongs to this sequence
@@ -545,8 +548,8 @@ def _collect_folder(self, settings, parent_item, folder):
545
548
546
549
return file_items
547
550
548
- def _add_file_item (self , settings , parent_item , path , is_sequence = False , seq_files = None ,
549
- item_name = None , item_type = None , context = None , properties = None ):
551
+ def _add_file_item (self , settings , parent_item , path , is_sequence = False , seq_files = None , item_name = None ,
552
+ item_type = None , context = None , creation_properties = None ):
550
553
"""
551
554
Creates a file item
552
555
@@ -558,7 +561,7 @@ def _add_file_item(self, settings, parent_item, path, is_sequence=False, seq_fil
558
561
:param item_name: The name of the item instance
559
562
:param item_type: The type of the item instance
560
563
:param context: The :class:`sgtk.Context` to set for the item
561
- :param properties : The dict of initial properties for the item
564
+ :param creation_properties : The dict of initial properties for the item
562
565
563
566
:returns: The item that was created
564
567
"""
@@ -568,19 +571,22 @@ def _add_file_item(self, settings, parent_item, path, is_sequence=False, seq_fil
568
571
if not item_name :
569
572
item_name = publisher .util .get_publish_name (path )
570
573
571
- # Lookup this item's item_type from the settings object
572
- if not item_type :
573
- item_type = self ._get_item_type_from_settings (settings , path , is_sequence )
574
-
575
- type_info = self ._get_item_type_info (settings , item_type )
576
- ignore_sequence = type_info ["ignore_sequences" ]
577
574
# Define the item's properties
578
- properties = properties or {}
575
+ properties = creation_properties or {}
579
576
580
577
# set the path and is_sequence properties for the plugins to use
581
578
properties ["path" ] = path
582
579
properties ["is_sequence" ] = is_sequence
583
580
581
+ # Lookup this item's item_type from the settings object
582
+ if not item_type :
583
+ # use the properties dict here, in case user doesn't use the creation_properties arg
584
+ item_type = self ._get_item_type_from_settings (settings , path , is_sequence ,
585
+ creation_properties = properties )
586
+
587
+ type_info = self ._get_item_type_info (settings , item_type )
588
+ ignore_sequence = type_info ["ignore_sequences" ]
589
+
584
590
# item intentionally ignores sequences
585
591
if ignore_sequence :
586
592
properties ["is_sequence" ] = False
@@ -620,22 +626,16 @@ def _add_file_item(self, settings, parent_item, path, is_sequence=False, seq_fil
620
626
621
627
return file_item
622
628
623
- def _get_item_type_from_settings (self , settings , path , is_sequence ):
624
- """
625
- Return the item type for the given filename from the settings object.
629
+ def _get_filtered_item_types_from_settings (self , settings , path , is_sequence , creation_properties ):
626
630
627
- The method will try to identify the file as a common file type. If not,
628
- it will use the mimetype category. If the file still cannot be
629
- identified, it will fallback to a generic file type .
631
+ """
632
+ Returns a list of tuples containing (resolution_order, work_path_template, item_type).
633
+ This filtered list of item types can then be passed down to resolve the correct item_type .
630
634
631
635
:param dict settings: Configured settings for this collector
632
636
:param path: The file path to identify type info for
633
637
:param is_sequence: Bool whether or not path is a sequence path
634
-
635
- :return: A string representing the item_type::
636
-
637
- The item type will be of the form `file.<type>` where type is a specific
638
- common type or a generic classification of the file.
638
+ :param creation_properties: The dict of initial properties for the item
639
639
"""
640
640
publisher = self .parent
641
641
@@ -644,12 +644,6 @@ def _get_item_type_from_settings(self, settings, path, is_sequence):
644
644
extension = file_info ["extension" ]
645
645
filename = file_info ["filename" ]
646
646
647
- # default values used if no specific type can be determined
648
- item_type = "file.unknown"
649
-
650
- # keep track if a common type was identified for the extension
651
- common_type_found = False
652
-
653
647
# tuple of resolution_order, work_path_template and item_type
654
648
template_item_type_mapping = list ()
655
649
@@ -678,9 +672,6 @@ def _get_item_type_from_settings(self, settings, path, is_sequence):
678
672
# we have a match! update the work_path_template
679
673
matched_work_path_template = template .name
680
674
681
- # found the extension in the common types lookup.
682
- common_type_found = True
683
-
684
675
ignore_sequences = type_info ["ignore_sequences" ]
685
676
# If we are dealing with a sequence, first check if we have a
686
677
# separate definition for a sequence of this type specifically,
@@ -697,13 +688,58 @@ def _get_item_type_from_settings(self, settings, path, is_sequence):
697
688
template_item_type_mapping .append ((matched_resolution_order , matched_work_path_template ,
698
689
current_item_type ))
699
690
700
- # sort the list on resolution_order, giving preference to a matching template
701
- template_item_type_mapping .sort (key = lambda elem : elem [0 ] if not elem [1 ] else - 1 )
691
+ max_resolution_order = max (
692
+ [resolution_order for resolution_order , work_path_template , item_type in template_item_type_mapping ]
693
+ )
694
+
695
+ # sort the list on resolution_order, giving preference to a matching template
696
+ template_item_type_mapping .sort (
697
+ key = lambda elem : elem [0 ] if not elem [1 ] else elem [0 ]- max_resolution_order )
698
+
699
+ return template_item_type_mapping
700
+
701
+ def _get_item_type_from_settings (self , settings , path , is_sequence , creation_properties ):
702
+ """
703
+ Return the item type for the given filename from the settings object.
704
+
705
+ The method will try to identify the file as a common file type. If not,
706
+ it will use the mimetype category. If the file still cannot be
707
+ identified, it will fallback to a generic file type.
708
+
709
+ :param dict settings: Configured settings for this collector
710
+ :param path: The file path to identify type info for
711
+ :param is_sequence: Bool whether or not path is a sequence path
712
+ :param creation_properties: The dict of initial properties for the item
713
+
714
+ :return: A string representing the item_type::
715
+
716
+ The item type will be of the form `file.<type>` where type is a specific
717
+ common type or a generic classification of the file.
718
+ """
719
+ publisher = self .parent
720
+
721
+ # extract the components of the supplied path
722
+ file_info = publisher .util .get_file_path_components (path )
723
+ extension = file_info ["extension" ]
724
+ filename = file_info ["filename" ]
725
+
726
+ # default values used if no specific type can be determined
727
+ item_type = "file.unknown"
728
+
729
+ # keep track if a common type was identified for the extension
730
+ common_type_found = False
731
+
732
+ # tuple of resolution_order, work_path_template and item_type
733
+ template_item_type_mapping = self ._get_filtered_item_types_from_settings (settings , path ,
734
+ is_sequence , creation_properties )
702
735
703
736
# this should work fine in case there is no work path template defined too
704
737
# this method gives preference to the first match that we get for any template
705
738
# also, there should never be a match with more than one templates, since template_from_path will fail too.
706
739
if len (template_item_type_mapping ):
740
+ # found the extension in the item types lookup.
741
+ common_type_found = True
742
+
707
743
resolution_order , work_path_template , item_type = template_item_type_mapping [0 ]
708
744
# 0 index contains a matching work_path_template if any.
709
745
# if there is no match that means we need to ask the user
0 commit comments