2 # -*- coding: utf-8 -*-
5 Defines various package utilities objects.
10 from collections import OrderedDict
12 import PyOpenColorIO as OCIO
14 __author__ = 'ACES Developers'
15 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
17 __maintainer__ = 'ACES Developers'
18 __email__ = 'aces@oscars.org'
19 __status__ = 'Production'
21 __all__ = ['ColorSpace',
30 class ColorSpace(object):
32 A container for data needed to define an *OCIO* *ColorSpace*.
39 bit_depth=OCIO.Constants.BIT_DEPTH_F32,
43 to_reference_transforms=[],
44 from_reference_transforms=[],
45 allocation_type=OCIO.Constants.ALLOCATION_UNIFORM,
46 allocation_vars=[0.0, 1.0]):
53 Parameter description.
58 Return value description.
63 self.bit_depth = bit_depth
64 self.description = description
65 self.equality_group = equality_group
67 self.is_data = is_data
68 self.to_reference_transforms = to_reference_transforms
69 self.from_reference_transforms = from_reference_transforms
70 self.allocation_type = allocation_type
71 self.allocation_vars = allocation_vars
74 def mat44_from_mat33(mat33):
76 Creates a 4x4 matrix from given 3x3 matrix.
81 Parameter description.
86 Return value description.
89 return [mat33[0], mat33[1], mat33[2], 0.0,
90 mat33[3], mat33[4], mat33[5], 0.0,
91 mat33[6], mat33[7], mat33[8], 0.0,
95 def filter_words(words, filters_in=None, filters_out=None, flags=0):
102 Parameter description.
107 Return value description.
113 filter_matched = False
114 for filter in filters_in:
115 if re.search(filter, word, flags):
116 filter_matched = True
118 if not filter_matched:
122 filter_matched = False
123 for filter in filters_out:
124 if re.search(filter, word, flags):
125 filter_matched = True
129 filtered_words.append(word)
130 return filtered_words
133 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
140 Parameter description.
145 Return value description.
148 for parent_directory, directories, files in os.walk(directory,
152 path = os.path.join(parent_directory, file)
153 if os.path.isfile(path):
154 if not filter_words((path,), filters_in, filters_out, flags):
160 def replace(string, data):
162 Replaces the data occurrences in the string.
166 string : str or unicode
167 String to manipulate.
169 Replacement occurrences.
178 >>> patterns = {"John" : "Luke",
179 ... "Jane" : "Anakin",
180 ... "Doe" : "Skywalker",
182 >>> data = "Users are: John Doe, Jane Doe, Z6PO."
183 >>> replace(data,patterns )
184 u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
187 for old, new in data.iteritems():
188 string = string.replace(old, new)
199 Parameter description.
204 Return value description.
207 return replace(path, {' ': '_', ')': '_', '(': '_'})
212 Removes blanks, underscores, dashes and parentheses.
216 string : str or unicode
222 A compact version of that string.
225 return replace(string.lower(),
226 OrderedDict(((' ', '_'),