Beispiel #1
0
def coerce_interval(value, keys, args, back_comp_unit_factor=1,
                    check_syntax_version=True):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    try:
        backwards_compat_value = float(value) * back_comp_unit_factor
    except (TypeError, ValueError):
        pass
    else:
        if check_syntax_version:
            set_syntax_version(VERSION_PREV,
                               "integer interval: %s" % itemstr(
                                   keys[:-1], keys[-1], value))
        return backwards_compat_value
    try:
        interval = interval_parser.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    if check_syntax_version:
        try:
            set_syntax_version(VERSION_NEW,
                               "ISO 8601 interval: %s" % itemstr(
                                   keys[:-1], keys[-1], value))
        except SyntaxVersionError as exc:
            raise Exception(str(exc))
    days, seconds = interval.get_days_and_seconds()
    seconds += days * Calendar.default().SECONDS_IN_DAY
    return seconds
Beispiel #2
0
def _coerce_cycletime_format( value, keys, args ):
    """Coerce value to a cycle point format (either CCYYMM... or %Y%m...)."""
    value = _strip_and_unquote( keys, value )
    set_syntax_version(VERSION_NEW,
                       "use of [cylc]cycle point format",
                       exc_class=IllegalValueError,
                       exc_args=("cycle point format", keys, value))
    test_timepoint = TimePoint(year=2001, month_of_year=3, day_of_month=1,
                               hour_of_day=4, minute_of_hour=30,
                               second_of_minute=54)
    if "/" in value or ":" in value:
        raise IllegalValueError("cycle point format", keys, value)
    if "%" in value:
        try:
            TimePointDumper().strftime(test_timepoint, value)
        except ValueError:
            raise IllegalValueError("cycle point format", keys, value)
        return value
    if "X" in value:
        for i in range(1, 101):
            dumper = TimePointDumper(num_expanded_year_digits=i)
            try:
                dumper.dump(test_timepoint, value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point format", keys, value)
    dumper = TimePointDumper()
    try:
        dumper.dump(test_timepoint, value)
    except ValueError:
        raise IllegalValueError("cycle point format", keys, value)
    return value
Beispiel #3
0
def _coerce_cycletime_format(value, keys, _):
    """Coerce value to a cycle point format (either CCYYMM... or %Y%m...)."""
    value = _strip_and_unquote(keys, value)
    if not value:
        return None
    test_timepoint = TimePoint(year=2001,
                               month_of_year=3,
                               day_of_month=1,
                               hour_of_day=4,
                               minute_of_hour=30,
                               second_of_minute=54)
    if "/" in value:
        raise IllegalValueError("cycle point format", keys, value)
    if "%" in value:
        try:
            TimePointDumper().strftime(test_timepoint, value)
        except ValueError:
            raise IllegalValueError("cycle point format", keys, value)
        return value
    if "X" in value:
        for i in range(1, 101):
            dumper = TimePointDumper(num_expanded_year_digits=i)
            try:
                dumper.dump(test_timepoint, value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point format", keys, value)
    dumper = TimePointDumper()
    try:
        dumper.dump(test_timepoint, value)
    except ValueError:
        raise IllegalValueError("cycle point format", keys, value)
    return value
Beispiel #4
0
def coerce_interval(value,
                    keys,
                    _,
                    back_comp_unit_factor=1,
                    check_syntax_version=True):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    if not value:
        # Allow explicit empty values.
        return None
    try:
        backwards_compat_value = float(value) * back_comp_unit_factor
    except (TypeError, ValueError):
        pass
    else:
        if check_syntax_version:
            set_syntax_version(
                VERSION_PREV,
                "integer interval: %s" % itemstr(keys[:-1], keys[-1], value))
        return DurationFloat(backwards_compat_value)
    try:
        interval = DURATION_PARSER.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    if check_syntax_version:
        set_syntax_version(
            VERSION_NEW,
            "ISO 8601 interval: %s" % itemstr(keys[:-1], keys[-1], value))
    days, seconds = interval.get_days_and_seconds()
    return DurationFloat(days * CALENDAR.SECONDS_IN_DAY + seconds)
Beispiel #5
0
def _coerce_cycletime(value, keys, _):
    """Coerce value to a cycle point."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    if value == "now":
        # Handle this later in config.py when the suite UTC mode is known.
        return value
    if re.match(r"\d+$", value):
        # Could be an old date-time cycle point format, or integer format.
        return value
    if value.startswith("-") or value.startswith("+"):
        # We don't know the value given for num expanded year digits...
        for i in range(1, 101):
            parser = TimePointParser(num_expanded_year_digits=i)
            try:
                parser.parse(value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point", keys, value)
    parser = TimePointParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("cycle point", keys, value)
    return value
Beispiel #6
0
def coerce_interval(value, keys, _):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    if not value:
        # Allow explicit empty values.
        return None
    return DurationFloat(get_interval_as_seconds(value, keys))
Beispiel #7
0
def _coerce_cycleinterval(value, keys, _):
    """Coerce value to a cycle interval."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    if value.isdigit():
        # Old runahead limit format.
        set_syntax_version(VERSION_PREV,
                           "integer interval for %s" % itemstr(
                               keys[:-1], keys[-1], value))
        return value
    if REC_INTEGER_INTERVAL.match(value):
        # New integer cycling format.
        set_syntax_version(VERSION_NEW,
                           "integer interval for %s" % itemstr(
                               keys[:-1], keys[-1], value))
        return value
    parser = DurationParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("interval", keys, value)
    set_syntax_version(VERSION_NEW,
                       "ISO 8601 interval for %s" % itemstr(
                           keys[:-1], keys[-1], value))
    return value
Beispiel #8
0
def coerce_interval(value,
                    keys,
                    args,
                    back_comp_unit_factor=1,
                    check_syntax_version=True):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    try:
        backwards_compat_value = float(value) * back_comp_unit_factor
    except (TypeError, ValueError):
        pass
    else:
        if check_syntax_version:
            set_syntax_version(
                VERSION_PREV,
                "integer interval: %s" % itemstr(keys[:-1], keys[-1], value))
        return backwards_compat_value
    try:
        interval = interval_parser.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    if check_syntax_version:
        try:
            set_syntax_version(
                VERSION_NEW,
                "ISO 8601 interval: %s" % itemstr(keys[:-1], keys[-1], value))
        except SyntaxVersionError as exc:
            raise Exception(str(exc))
    days, seconds = interval.get_days_and_seconds()
    seconds += days * Calendar.default().SECONDS_IN_DAY
    return seconds
Beispiel #9
0
def _coerce_cycleinterval(value, keys, _):
    """Coerce value to a cycle interval."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    if value.isdigit():
        # Old runahead limit format.
        set_syntax_version(
            VERSION_PREV,
            "integer interval for %s" % itemstr(keys[:-1], keys[-1], value))
        return value
    if REC_INTEGER_INTERVAL.match(value):
        # New integer cycling format.
        set_syntax_version(
            VERSION_NEW,
            "integer interval for %s" % itemstr(keys[:-1], keys[-1], value))
        return value
    parser = DurationParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("interval", keys, value)
    set_syntax_version(
        VERSION_NEW,
        "ISO 8601 interval for %s" % itemstr(keys[:-1], keys[-1], value))
    return value
Beispiel #10
0
def coerce_interval(value, keys, _, back_comp_unit_factor=1,
                    check_syntax_version=True):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    if not value:
        # Allow explicit empty values.
        return None
    try:
        backwards_compat_value = float(value) * back_comp_unit_factor
    except (TypeError, ValueError):
        pass
    else:
        if check_syntax_version:
            set_syntax_version(
                VERSION_PREV,
                "integer interval: %s" % itemstr(keys[:-1], keys[-1], value))
        return DurationFloat(backwards_compat_value)
    try:
        interval = DURATION_PARSER.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    if check_syntax_version:
        set_syntax_version(
            VERSION_NEW,
            "ISO 8601 interval: %s" % itemstr(keys[:-1], keys[-1], value))
    days, seconds = interval.get_days_and_seconds()
    return DurationFloat(days * CALENDAR.SECONDS_IN_DAY + seconds)
Beispiel #11
0
def _coerce_cycletime_time_zone(value, keys, _):
    """Coerce value to a cycle point time zone format - Z, +13, -0800..."""
    value = _strip_and_unquote(keys, value)
    if not value:
        return None
    try:
        set_syntax_version(VERSION_NEW,
                           "use of [cylc]cycle point time zone format")
    except SyntaxVersionError:
        raise IllegalValueError("cycle point time zone format", keys, value)
    test_timepoint = TimePoint(year=2001,
                               month_of_year=3,
                               day_of_month=1,
                               hour_of_day=4,
                               minute_of_hour=30,
                               second_of_minute=54)
    dumper = TimePointDumper()
    test_timepoint_string = dumper.dump(test_timepoint, "CCYYMMDDThhmmss")
    test_timepoint_string += value
    parser = TimePointParser(allow_only_basic=True)
    try:
        parser.parse(test_timepoint_string)
    except ValueError:
        raise IllegalValueError("cycle point time zone format", keys, value)
    return value
Beispiel #12
0
def _coerce_cycletime(value, keys, _):
    """Coerce value to a cycle point."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    if value == "now":
        # Handle this later in config.py when the suite UTC mode is known.
        return value
    if re.match(r"\d+$", value):
        # Could be an old date-time cycle point format, or integer format.
        return value
    if value.startswith("-") or value.startswith("+"):
        # We don't know the value given for num expanded year digits...
        for i in range(1, 101):
            parser = TimePointParser(num_expanded_year_digits=i)
            try:
                parser.parse(value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point", keys, value)
    parser = TimePointParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("cycle point", keys, value)
    return value
Beispiel #13
0
def _coerce_cycletime_format(value, keys, _):
    """Coerce value to a cycle point format (either CCYYMM... or %Y%m...)."""
    value = _strip_and_unquote(keys, value)
    if not value:
        return None
    test_timepoint = TimePoint(year=2001, month_of_year=3, day_of_month=1,
                               hour_of_day=4, minute_of_hour=30,
                               second_of_minute=54)
    if "/" in value:
        raise IllegalValueError("cycle point format", keys, value)
    if "%" in value:
        try:
            TimePointDumper().strftime(test_timepoint, value)
        except ValueError:
            raise IllegalValueError("cycle point format", keys, value)
        return value
    if "X" in value:
        for i in range(1, 101):
            dumper = TimePointDumper(num_expanded_year_digits=i)
            try:
                dumper.dump(test_timepoint, value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point format", keys, value)
    dumper = TimePointDumper()
    try:
        dumper.dump(test_timepoint, value)
    except ValueError:
        raise IllegalValueError("cycle point format", keys, value)
    return value
Beispiel #14
0
def _coerce_cycletime( value, keys, args ):
    """Coerce value to a cycle point."""
    value = _strip_and_unquote( keys, value )
    if re.match(r"\d+$", value):
        # Could be an old date-time cycle point format, or integer format.
        return value
    if value.startswith("-") or value.startswith("+"):
        # We don't know the value given for num expanded year digits...
        for i in range(1, 101):
            parser = TimePointParser(num_expanded_year_digits=i)
            try:
                parser.parse(value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point", keys, value)
    parser = TimePointParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("cycle point", keys, value)
    set_syntax_version(VERSION_NEW,
                       "cycle point: %s" % itemstr(
                           keys[:-1], keys[-1], value))
    return value
Beispiel #15
0
def _coerce_cycletime( value, keys, args ):
    """Coerce value to a cycle time."""
    value = _strip_and_unquote( keys, value )
    try:
        return ct( value ).get()
    except:
        #raise
        raise IllegalValueError( 'cycle time', keys, value )
Beispiel #16
0
def _coerce_cycleinterval(value, keys, _):
    """Coerce value to a cycle interval."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    parser = DurationParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("interval", keys, value)
    return value
Beispiel #17
0
def _coerce_cycleinterval(value, keys, _):
    """Coerce value to a cycle interval."""
    if not value:
        return None
    value = _strip_and_unquote(keys, value)
    parser = DurationParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("interval", keys, value)
    return value
def coerce_interval(value, keys, _):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    if not value:
        # Allow explicit empty values.
        return None
    try:
        interval = DURATION_PARSER.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    days, seconds = interval.get_days_and_seconds()
    return DurationFloat(days * CALENDAR.SECONDS_IN_DAY + seconds)
Beispiel #19
0
def coerce_interval(value, keys, _):
    """Coerce an ISO 8601 interval (or number: back-comp) into seconds."""
    value = _strip_and_unquote(keys, value)
    if not value:
        # Allow explicit empty values.
        return None
    try:
        interval = DURATION_PARSER.parse(value)
    except ValueError:
        raise IllegalValueError("ISO 8601 interval", keys, value)
    days, seconds = interval.get_days_and_seconds()
    return DurationFloat(days * CALENDAR.SECONDS_IN_DAY + seconds)
Beispiel #20
0
def coerce_xtrig(value, keys, _):
    """Coerce a string into an xtrigger function context object.

    func_name(*func_args, **func_kwargs)
    Checks for legal string templates in arg values too.

    """

    def coerce_type(in_str):
        """Convert in_str to int, float, or bool, if possible."""
        try:
            val = int(in_str)
        except ValueError:
            try:
                val = float(in_str)
            except ValueError:
                if in_str == 'False':
                    val = False
                elif in_str == 'True':
                    val = True
                else:
                    # Leave as string.
                    val = _strip_and_unquote([], in_str)
        return val

    label = keys[-1]
    value = _strip_and_unquote(keys, value)
    if not value:
        raise IllegalValueError("xtrigger", keys, value)
    fname = None
    args = []
    kwargs = {}
    m = RE_TRIG_FUNC.match(value)
    if m is None:
        raise IllegalValueError("xtrigger", keys, value)
    fname, fargs, intvl = m.groups()
    if intvl is None:
        seconds = DEFAULT_XTRIG_INTVL_SECS
    else:
        seconds = float(coerce_interval(intvl, keys, None))

    if fargs:
        # Extract function args and kwargs.
        for farg in re.split(r'\s*,\s*', fargs):
            try:
                key, val = re.split(r'\s*=\s*', farg)
            except ValueError:
                args.append(coerce_type(farg.strip()))
            else:
                kwargs[key.strip()] = coerce_type(val)

    return SuiteFuncContext(label, fname, args, kwargs, seconds)
Beispiel #21
0
 def coerce_type(in_str):
     """Convert in_str to int, float, or bool, if possible."""
     try:
         val = int(in_str)
     except ValueError:
         try:
             val = float(in_str)
         except ValueError:
             if in_str == 'False':
                 val = False
             elif in_str == 'True':
                 val = True
             else:
                 # Leave as string.
                 val = _strip_and_unquote([], in_str)
     return val
Beispiel #22
0
def _coerce_cycletime_time_zone(value, keys, _):
    """Coerce value to a cycle point time zone format - Z, +13, -0800..."""
    value = _strip_and_unquote(keys, value)
    if not value:
        return None
    test_timepoint = TimePoint(year=2001, month_of_year=3, day_of_month=1,
                               hour_of_day=4, minute_of_hour=30,
                               second_of_minute=54)
    dumper = TimePointDumper()
    test_timepoint_string = dumper.dump(test_timepoint, "CCYYMMDDThhmmss")
    test_timepoint_string += value
    parser = TimePointParser(allow_only_basic=True)
    try:
        parser.parse(test_timepoint_string)
    except ValueError:
        raise IllegalValueError("cycle point time zone format", keys, value)
    return value
Beispiel #23
0
def _coerce_cycletime_time_zone( value, keys, args ):
    """Coerce value to a cycle point time zone format - Z, +13, -0800..."""
    value = _strip_and_unquote( keys, value )
    set_syntax_version(VERSION_NEW,
                       "use of [cylc]cycle point time zone format",
                       exc_class=IllegalValueError,
                       exc_args=("cycle point time zone format", keys, value))
    test_timepoint = TimePoint(year=2001, month_of_year=3, day_of_month=1,
                               hour_of_day=4, minute_of_hour=30,
                               second_of_minute=54)
    dumper = TimePointDumper()
    test_timepoint_string = dumper.dump(test_timepoint, "CCYYMMDDThhmmss")
    test_timepoint_string += value
    parser = TimePointParser(allow_only_basic=True)
    try:
        parser.parse(test_timepoint_string)
    except ValueError:
        raise IllegalValueError("cycle point time zone format", keys, value)
    return value
Beispiel #24
0
def _coerce_cycletime(value, keys, args):
    """Coerce value to a cycle point."""
    value = _strip_and_unquote(keys, value)
    if re.match(r"\d+$", value):
        # Could be an old date-time cycle point format, or integer format.
        return value
    if value.startswith("-") or value.startswith("+"):
        # We don't know the value given for num expanded year digits...
        for i in range(1, 101):
            parser = TimePointParser(num_expanded_year_digits=i)
            try:
                parser.parse(value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point", keys, value)
    parser = TimePointParser()
    try:
        parser.parse(value)
    except ValueError:
        raise IllegalValueError("cycle point", keys, value)
    set_syntax_version(VERSION_NEW,
                       "cycle point: %s" % itemstr(keys[:-1], keys[-1], value))
    return value
Beispiel #25
0
def _coerce_cycletime_format(value, keys, args):
    """Coerce value to a cycle point format (either CCYYMM... or %Y%m...)."""
    value = _strip_and_unquote(keys, value)
    set_syntax_version(VERSION_NEW,
                       "use of [cylc]cycle point format",
                       exc_class=IllegalValueError,
                       exc_args=("cycle point format", keys, value))
    test_timepoint = TimePoint(year=2001,
                               month_of_year=3,
                               day_of_month=1,
                               hour_of_day=4,
                               minute_of_hour=30,
                               second_of_minute=54)
    if "/" in value or ":" in value:
        raise IllegalValueError("cycle point format", keys, value)
    if "%" in value:
        try:
            TimePointDumper().strftime(test_timepoint, value)
        except ValueError:
            raise IllegalValueError("cycle point format", keys, value)
        return value
    if "X" in value:
        for i in range(1, 101):
            dumper = TimePointDumper(num_expanded_year_digits=i)
            try:
                dumper.dump(test_timepoint, value)
            except ValueError:
                continue
            return value
        raise IllegalValueError("cycle point format", keys, value)
    dumper = TimePointDumper()
    try:
        dumper.dump(test_timepoint, value)
    except ValueError:
        raise IllegalValueError("cycle point format", keys, value)
    return value
Beispiel #26
0
def _coerce_final_cycletime( value, keys, args ):
    """Coerce final cycle point."""
    value = _strip_and_unquote( keys, value )
    return value
Beispiel #27
0
def _coerce_final_cycletime(value, keys, _):
    """Coerce final cycle point."""
    return _strip_and_unquote(keys, value)
Beispiel #28
0
def _coerce_final_cycletime(value, keys, _):
    """Coerce final cycle point."""
    return _strip_and_unquote(keys, value)
Beispiel #29
0
def _coerce_final_cycletime(value, keys, args):
    """Coerce final cycle point."""
    value = _strip_and_unquote(keys, value)
    return value