Add main module attributes.
[OpenColorIO-Configs.git] / aces_1.0.0 / python / aces_ocio / util.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import os
5 import re
6
7 import PyOpenColorIO as OCIO
8
9 __author__ = 'ACES Developers'
10 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
11 __license__ = ''
12 __maintainer__ = 'ACES Developers'
13 __email__ = 'aces@oscars.org'
14 __status__ = 'Production'
15
16 __all__ = ['ColorSpace',
17            'mat44FromMat33',
18            'filter_words',
19            'files_walker']
20
21 #
22 # Utility classes and functions
23 #
24
25 class ColorSpace:
26     """
27     A container for data needed to define an OCIO 'Color Space'
28     """
29
30     def __init__(self,
31                  name,
32                  description=None,
33                  bitDepth=OCIO.Constants.BIT_DEPTH_F32,
34                  equalityGroup=None,
35                  family=None,
36                  isData=False,
37                  toReferenceTransforms=[],
38                  fromReferenceTransforms=[],
39                  allocationType=OCIO.Constants.ALLOCATION_UNIFORM,
40                  allocationVars=[0.0, 1.0]):
41         """
42         Initialize the standard class variables
43         """
44         self.name = name
45         self.bitDepth = bitDepth
46         self.description = description
47         self.equalityGroup = equalityGroup
48         self.family = family
49         self.isData = isData
50         self.toReferenceTransforms = toReferenceTransforms
51         self.fromReferenceTransforms = fromReferenceTransforms
52         self.allocationType = allocationType
53         self.allocationVars = allocationVars
54
55
56 # Create a 4x4 matrix (list) based on a 3x3 matrix (list) input
57 def mat44FromMat33(mat33):
58     return [mat33[0], mat33[1], mat33[2], 0.0,
59             mat33[3], mat33[4], mat33[5], 0.0,
60             mat33[6], mat33[7], mat33[8], 0.0,
61             0, 0, 0, 1.0]
62
63
64 # TODO: Worth moving to *util.py*.
65 def filter_words(words, filters_in=None, filters_out=None, flags=0):
66     """
67     """
68
69     filtered_words = []
70     for word in words:
71         if filters_in:
72             filter_matched = False
73             for filter in filters_in:
74                 if re.search(filter, word, flags):
75                     filter_matched = True
76                     break
77             if not filter_matched:
78                 continue
79
80         if filters_out:
81             filter_matched = False
82             for filter in filters_out:
83                 if re.search(filter, word, flags):
84                     filter_matched = True
85                     break
86             if filter_matched:
87                 continue
88         filtered_words.append(word)
89     return filtered_words
90
91
92 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
93     """
94     """
95
96     for parent_directory, directories, files in os.walk(directory,
97                                                         topdown=False,
98                                                         followlinks=True):
99         for file in files:
100             path = os.path.join(parent_directory, file)
101             if os.path.isfile(path):
102                 if not filter_words((path,), filters_in, filters_out, flags):
103                     continue
104
105                 yield path
106
107
108
109