Add shebang to modules.
[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 #
10 # Utility classes and functions
11 #
12 class ColorSpace:
13     "A container for data needed to define an OCIO 'Color Space' "
14
15     def __init__(self,
16         name,
17         description=None,
18         bitDepth=OCIO.Constants.BIT_DEPTH_F32,
19         equalityGroup=None,
20         family=None,
21         isData=False,
22         toReferenceTransforms=[],
23         fromReferenceTransforms=[],
24         allocationType=OCIO.Constants.ALLOCATION_UNIFORM,
25         allocationVars=[0.0, 1.0]):
26         "Initialize the standard class variables"
27         self.name = name
28         self.bitDepth=bitDepth
29         self.description = description
30         self.equalityGroup=equalityGroup
31         self.family=family
32         self.isData=isData
33         self.toReferenceTransforms=toReferenceTransforms
34         self.fromReferenceTransforms=fromReferenceTransforms
35         self.allocationType=allocationType
36         self.allocationVars=allocationVars
37
38 # Create a 4x4 matrix (list) based on a 3x3 matrix (list) input
39 def mat44FromMat33(mat33):
40     return [mat33[0], mat33[1], mat33[2], 0.0,
41             mat33[3], mat33[4], mat33[5], 0.0,
42             mat33[6], mat33[7], mat33[8], 0.0,
43             0,0,0,1.0]
44
45 # TODO: Worth moving to *util.py*.
46 def filter_words(words, filters_in=None, filters_out=None, flags=0):
47     """
48     """
49
50     filtered_words = []
51     for word in words:
52         if filters_in:
53             filter_matched = False
54             for filter in filters_in:
55                 if re.search(filter, word, flags):
56                     filter_matched = True
57                     break
58             if not filter_matched:
59                 continue
60
61         if filters_out:
62             filter_matched = False
63             for filter in filters_out:
64                 if re.search(filter, word, flags):
65                     filter_matched = True
66                     break
67             if filter_matched:
68                 continue
69         filtered_words.append(word)
70     return filtered_words
71
72
73 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
74     """
75     """
76
77     for parent_directory, directories, files in os.walk(directory,
78                                                         topdown=False,
79                                                         followlinks=True):
80         for file in files:
81             path = os.path.join(parent_directory, file)
82             if os.path.isfile(path):
83                 if not filter_words((path,), filters_in, filters_out, flags):
84                     continue
85
86                 yield path
87
88
89
90