X-Git-Url: http://users.mur.at/ms/git/gitweb/?p=OpenColorIO-Configs.git;a=blobdiff_plain;f=aces_1.0.0%2Fpython%2Faces_ocio%2Futilities.py;h=1d426d98a659a28a45f09d23040d33ef8f31fbb9;hp=75222f18a87e15fc6b805bcca020dad8afafcbdf;hb=cad9d48a0f1067769435904348e9fffeffd25eb9;hpb=89360f70a6c71121580324ed3c125a83c3973887 diff --git a/aces_1.0.0/python/aces_ocio/utilities.py b/aces_1.0.0/python/aces_ocio/utilities.py index 75222f1..1d426d9 100644 --- a/aces_1.0.0/python/aces_ocio/utilities.py +++ b/aces_1.0.0/python/aces_ocio/utilities.py @@ -7,11 +7,12 @@ Defines various package utilities objects. from __future__ import division +import itertools import os import re from collections import OrderedDict -import PyOpenColorIO as OCIO +import PyOpenColorIO as ocio __author__ = 'ACES Developers' __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers' @@ -26,7 +27,9 @@ __all__ = ['ColorSpace', 'files_walker', 'replace', 'sanitize', - 'compact'] + 'compact', + 'colorspace_prefixed_name', + 'unpack_default'] class ColorSpace(object): @@ -38,14 +41,15 @@ class ColorSpace(object): name, aliases=[], description=None, - bit_depth=OCIO.Constants.BIT_DEPTH_F32, - equality_group=None, + bit_depth=ocio.Constants.BIT_DEPTH_F32, + equality_group='', family=None, is_data=False, to_reference_transforms=[], from_reference_transforms=[], - allocation_type=OCIO.Constants.ALLOCATION_UNIFORM, - allocation_vars=[0, 1]): + allocation_type=ocio.Constants.ALLOCATION_UNIFORM, + allocation_vars=[0, 1], + aces_transform_id=None): """ Object description. @@ -61,7 +65,7 @@ class ColorSpace(object): """ self.name = name - self.aliases = [] + self.aliases = aliases self.bit_depth = bit_depth self.description = description self.equality_group = equality_group @@ -71,6 +75,7 @@ class ColorSpace(object): self.from_reference_transforms = from_reference_transforms self.allocation_type = allocation_type self.allocation_vars = allocation_vars + self.aces_transform_id = aces_transform_id def mat44_from_mat33(mat33): @@ -147,9 +152,8 @@ def files_walker(directory, filters_in=None, filters_out=None, flags=0): Return value description. """ - for parent_directory, directories, files in os.walk(directory, - topdown=False, - followlinks=True): + for parent_directory, directories, files in os.walk( + directory, topdown=False, followlinks=True): for file in files: path = os.path.join(parent_directory, file) if os.path.isfile(path): @@ -233,3 +237,46 @@ def compact(string): ('___', '_'), ('__', '_'), ('_', '')))) + + +def colorspace_prefixed_name(colorspace): + """ + Returns given *OCIO* colorspace prefixed name with its family name. + + Parameters + ---------- + colorspace : Colorspace + Colorspace to prefix. + + Returns + ------- + str or unicode + Family prefixed *OCIO* colorspace name. + """ + prefix = colorspace.family.replace('/', ' - ') + + return '%s - %s' % (prefix, colorspace.name) + + +def unpack_default(iterable, length=3, default=None): + """ + Unpacks given iterable maintaining given length and filling missing + entries with given default. + + Parameters + ---------- + iterable : object + Iterable. + length : int + Iterable length. + default : object + Filling default object. + + Returns + ------- + iterable + """ + + return itertools.islice(itertools.chain(iter(iterable), + itertools.repeat(default)), + length)