2 # -*- coding: utf-8 -*-
5 Defines various package utilities objects.
8 from __future__ import division
12 from collections import OrderedDict
14 import PyOpenColorIO as ocio
16 __author__ = 'ACES Developers'
17 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
19 __maintainer__ = 'ACES Developers'
20 __email__ = 'aces@oscars.org'
21 __status__ = 'Production'
23 __all__ = ['ColorSpace',
32 class ColorSpace(object):
34 A container for data needed to define an *OCIO* *ColorSpace*.
41 bit_depth=ocio.Constants.BIT_DEPTH_F32,
45 to_reference_transforms=[],
46 from_reference_transforms=[],
47 allocation_type=ocio.Constants.ALLOCATION_UNIFORM,
48 allocation_vars=[0, 1]):
55 Parameter description.
60 Return value description.
64 self.aliases = aliases
65 self.bit_depth = bit_depth
66 self.description = description
67 self.equality_group = equality_group
69 self.is_data = is_data
70 self.to_reference_transforms = to_reference_transforms
71 self.from_reference_transforms = from_reference_transforms
72 self.allocation_type = allocation_type
73 self.allocation_vars = allocation_vars
76 def mat44_from_mat33(mat33):
78 Creates a 4x4 matrix from given 3x3 matrix.
83 Parameter description.
88 Return value description.
91 return [mat33[0], mat33[1], mat33[2], 0,
92 mat33[3], mat33[4], mat33[5], 0,
93 mat33[6], mat33[7], mat33[8], 0,
97 def filter_words(words, filters_in=None, filters_out=None, flags=0):
104 Parameter description.
109 Return value description.
115 filter_matched = False
116 for filter in filters_in:
117 if re.search(filter, word, flags):
118 filter_matched = True
120 if not filter_matched:
124 filter_matched = False
125 for filter in filters_out:
126 if re.search(filter, word, flags):
127 filter_matched = True
131 filtered_words.append(word)
132 return filtered_words
135 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
142 Parameter description.
147 Return value description.
150 for parent_directory, directories, files in os.walk(
151 directory, topdown=False, followlinks=True):
153 path = os.path.join(parent_directory, file)
154 if os.path.isfile(path):
155 if not filter_words((path,), filters_in, filters_out, flags):
161 def replace(string, data):
163 Replaces the data occurrences in the string.
167 string : str or unicode
168 String to manipulate.
170 Replacement occurrences.
179 >>> patterns = {"John" : "Luke",
180 ... "Jane" : "Anakin",
181 ... "Doe" : "Skywalker",
183 >>> data = "Users are: John Doe, Jane Doe, Z6PO."
184 >>> replace(data,patterns )
185 u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
188 for old, new in data.iteritems():
189 string = string.replace(old, new)
200 Parameter description.
205 Return value description.
208 return replace(path, {' ': '_', ')': '_', '(': '_'})
213 Removes blanks, underscores, dashes and parentheses.
217 string : str or unicode
223 A compact version of that string.
226 return replace(string.lower(),
227 OrderedDict(((' ', '_'),