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],
49 aces_transform_id=None):
56 Parameter description.
61 Return value description.
65 self.aliases = aliases
66 self.bit_depth = bit_depth
67 self.description = description
68 self.equality_group = equality_group
70 self.is_data = is_data
71 self.to_reference_transforms = to_reference_transforms
72 self.from_reference_transforms = from_reference_transforms
73 self.allocation_type = allocation_type
74 self.allocation_vars = allocation_vars
75 self.aces_transform_id = aces_transform_id
77 def mat44_from_mat33(mat33):
79 Creates a 4x4 matrix from given 3x3 matrix.
84 Parameter description.
89 Return value description.
92 return [mat33[0], mat33[1], mat33[2], 0,
93 mat33[3], mat33[4], mat33[5], 0,
94 mat33[6], mat33[7], mat33[8], 0,
98 def filter_words(words, filters_in=None, filters_out=None, flags=0):
105 Parameter description.
110 Return value description.
116 filter_matched = False
117 for filter in filters_in:
118 if re.search(filter, word, flags):
119 filter_matched = True
121 if not filter_matched:
125 filter_matched = False
126 for filter in filters_out:
127 if re.search(filter, word, flags):
128 filter_matched = True
132 filtered_words.append(word)
133 return filtered_words
136 def files_walker(directory, filters_in=None, filters_out=None, flags=0):
143 Parameter description.
148 Return value description.
151 for parent_directory, directories, files in os.walk(
152 directory, topdown=False, followlinks=True):
154 path = os.path.join(parent_directory, file)
155 if os.path.isfile(path):
156 if not filter_words((path,), filters_in, filters_out, flags):
162 def replace(string, data):
164 Replaces the data occurrences in the string.
168 string : str or unicode
169 String to manipulate.
171 Replacement occurrences.
180 >>> patterns = {"John" : "Luke",
181 ... "Jane" : "Anakin",
182 ... "Doe" : "Skywalker",
184 >>> data = "Users are: John Doe, Jane Doe, Z6PO."
185 >>> replace(data,patterns )
186 u'Users are: Luke Skywalker, Anakin Skywalker, R2D2.'
189 for old, new in data.iteritems():
190 string = string.replace(old, new)
201 Parameter description.
206 Return value description.
209 return replace(path, {' ': '_', ')': '_', '(': '_'})
214 Removes blanks, underscores, dashes and parentheses.
218 string : str or unicode
224 A compact version of that string.
227 return replace(string.lower(),
228 OrderedDict(((' ', '_'),