[docs]classAYONOCIOLookFileProcessor(object):"""Class for processing an AYON OCIO Look file. Arguments: filepath (Path): Path to the OCIO Look file. Attributes: operator (AYONOCIOLookProduct): The OCIO Look operator. """filepath:Pathoperator:AYONOCIOLookProductdef__init__(self,filepath:Path)->None:self.filepath=filepathself.load()
[docs]defload(self)->None:"""Load the OCIO Look file. Note: This globs all relative files recursively so we can make sure files in transforms are having correct path. Attention: This method clears the operator before loading the file. """self.operator=None# clear operatorociolook_file_path=self.filepath.resolve().as_posix()# get all relative files recursively so we can make sure files in# transforms are having correct pathall_relative_files={f.name:fforfinPath(self.filepath.parent).rglob("*")}withopen(ociolook_file_path,"r")asf:ops_data=json.load(f)schema_data_version=ops_data.get("version",1)ifschema_data_version!=1:raiseValueError(f"Schema data version {schema_data_version} is not supported")# INFO: This is a temporary fix to handle the case where# the filepath is not found in the data# add all relative files to the dataforiteminops_data["data"]["ocioLookItems"]:self._sanitize_file_path(item,all_relative_files)self.operator=AYONOCIOLookProduct.from_node_data(ops_data["data"])
[docs]defget_oiiotool_cmd(self)->List[str]:"""Get arguments for the OIIO command."""args=[]forxfminself.operator.to_ocio_obj():ifisinstance(xfm,OCIO.FileTransform):lut=Path(xfm.getSrc()).resolve()args.extend(["--ociofiletransform",f"{lut.as_posix()}"])ifisinstance(xfm,OCIO.ColorSpaceTransform):args.extend(["--colorconvert",xfm.getSrc(),xfm.getDst()])returnargs
def_sanitize_file_path(self,repre_data:dict,all_relative_files:dict)->None:# noqa: E501extension=repre_data["ext"]forfile,pathinall_relative_files.items():iffile.endswith(extension):repre_data["file"]=path.resolve().as_posix()breakifnotrepre_data.get("file"):log.warning(f"File not found: {repre_data['name']}.{repre_data['ext']}.")