diff --git a/cuesubmit/cuesubmit/Config.py b/cuesubmit/cuesubmit/Config.py index 3bfb443a7..b06a07ec8 100644 --- a/cuesubmit/cuesubmit/Config.py +++ b/cuesubmit/cuesubmit/Config.py @@ -35,19 +35,61 @@ def getConfigValues(): """Reads the config file from disk and returns the values it defines.""" - configData = {} - configFile = os.environ.get(CONFIG_FILE_ENV_VAR) - if not configFile: - configFile = os.path.join(opencue.config.config_base_directory(), 'cuesubmit.yaml') - if os.path.exists(configFile): - with open(configFile, 'r', encoding='utf-8') as data: - try: - configData = yaml.load(data, Loader=yaml.SafeLoader) - except yaml.YAMLError: - raise CuesubmitConfigError("Could not load yaml file: {}. Please check its " - "formatting".format(configFile)) + configFile = os.environ.get(CONFIG_FILE_ENV_VAR)\ + or os.path.join(opencue.config.config_base_directory(), + 'cuesubmit.yaml') + if not os.path.exists(configFile): + return {} + configData = _loadYamlFile(yaml_file=configFile) + if 'RENDER_CMDS' in configData: + # look for any sub-config files and load them + configData['RENDER_CMDS'] = _expandRenderConfigValues(configData['RENDER_CMDS']) return configData +def _loadYamlFile(yaml_file): + """ Load config yaml as dict + :param yaml_file: path to a config.yaml file (path can be an env var) + :type yaml_file: str + :returns: yaml content + :rtype: dict + """ + _yaml_file = os.path.expandvars(yaml_file) + if not os.path.exists(_yaml_file): + raise FileNotFoundError(f"yaml_file:{_yaml_file} not found") + config_data = {} + with open(_yaml_file, 'r', encoding='utf-8') as data: + try: + config_data = yaml.load(data, Loader=yaml.SafeLoader) + except yaml.YAMLError: + raise CuesubmitConfigError("Could not load yaml file: {}. Please check its " + "formatting".format(_yaml_file)) + return config_data + + +def _expandRenderConfigValues(RENDER_CMDS): + """ Looks through each render command and loads their 'config_file' if any + If 'config_file' is set but does not exist, replace its content with error for proper feedback + + :param RENDER_CMDS: all render commands from the cuesubmit_config.yaml file + :type RENDER_CMDS: dict + :returns: Updated RENDER_CMDS + :rtype: dict + """ + for job_type, _options in RENDER_CMDS.items(): + _sub_config_file = _options.get('config_file') + if not _sub_config_file: + continue + try: + RENDER_CMDS[job_type] = _loadYamlFile(yaml_file=_sub_config_file) + except FileNotFoundError as error: + RENDER_CMDS[job_type] = { + 'command': 'error', + 'options': { + '{ERROR}': error} + } + return RENDER_CMDS + + class CuesubmitConfigError(Exception): """Thrown when an error occurs reading the config file.""" diff --git a/cuesubmit/cuesubmit/Constants.py b/cuesubmit/cuesubmit/Constants.py index 89bbbea51..832e8fe25 100644 --- a/cuesubmit/cuesubmit/Constants.py +++ b/cuesubmit/cuesubmit/Constants.py @@ -36,6 +36,10 @@ MAYA_RENDER_CMD = config.get('MAYA_RENDER_CMD', 'Render') NUKE_RENDER_CMD = config.get('NUKE_RENDER_CMD', 'nuke') BLENDER_RENDER_CMD = config.get('BLENDER_RENDER_CMD', 'blender') +RENDER_CMDS = config.get('RENDER_CMDS', {}) + +DEFAULT_SHOW = config.get('DEFAULT_SHOW') or os.environ.get('PROJECT', 'default') + FRAME_TOKEN = config.get('FRAME_TOKEN', '#IFRAME#') FRAME_START_TOKEN = config.get('FRAME_START', '#FRAME_START#') FRAME_END_TOKEN = config.get('FRAME_END', '#FRAME_END#') @@ -68,6 +72,16 @@ BLENDER_OUTPUT_OPTIONS_URL = \ 'https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html#render-options' +REGEX_CUETOKEN = r'^#.*#$' #FRAME_START# +REGEX_COMMAND_OPTIONS = (r'(?P-+\w*)?' # -optionFlag + r'(?P\~)?' # -hiddenFlag~ + r'\s?' + r'({' + r'(?P\!)?' # {!Mandatory argument} + r'(?P