示例#1
0
    def _get_conf(self, conf_tree, key, arg_ok=False):
        """Get a list of cycles from a configuration setting.

        key -- An option key in self.SECTION to locate the setting.
        arg_ok -- A boolean to indicate whether an item in the list can have
                  extra arguments or not.

        The value of the setting is expected to be split by shlex.split into a
        list of items. If arg_ok is False, an item should be a string
        representing a cycle or an cycle offset. If arg_ok is True, the cycle
        or cycle offset string can, optionally, have an argument after a colon.
        E.g.:

        prune-remote-logs-at=-6h -12h
        prune-datac-at=-6h:foo/* -12h:'bar/* baz/*' -1d

        If arg_ok is False, return a list of cycles.
        If arg_ok is True, return a list of (cycle, arg)

        """
        items_str = conf_tree.node.get_value([self.SECTION, key])
        if items_str is None:
            return []
        try:
            items_str = env_var_process(items_str)
        except UnboundEnvironmentVariableError as e:
            raise ConfigValueError([self.SECTION, key], items_str, e)
        items = []
        ds = RoseDateShifter(task_cycle_time_mode=True)
        for item_str in shlex.split(items_str):
            if arg_ok and ":" in item_str:
                item, arg = item_str.split(":", 1)
            else:
                item, arg = (item_str, None)
            if ds.is_task_cycle_time_mode() and ds.is_offset(item):
                cycle = ds.date_shift(offset=item)
            else:
                cycle = item
            if arg_ok:
                items.append((cycle, arg))
            else:
                items.append(cycle)
        return items