clusterjob/utils.py
def time_to_seconds(time_str):
    """Convert a string describing a time duration into seconds. The supported
    formats are::

        minutes
        minutes:seconds
        hours:minutes:seconds
        days-hours
        days-hours:minutes
        days-hours:minutes:seconds
        days:hours:minutes:seconds

    Raises:
        ValueError: if `time_str` has an invalid format.

    Examples:
        >>> time_to_seconds('10')
        600
        >>> time_to_seconds('10:00')
        600
        >>> time_to_seconds('10:30')
        630
        >>> time_to_seconds('1:10:30')
        4230
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1-0')
        86400
        >>> time_to_seconds('1-10')
        122400
        >>> time_to_seconds('1-1:10')
        90600
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1:1:10:30')
        90630
        >>> time_to_seconds('1 1:10:30')
        Traceback (most recent call last):
        ...
        ValueError: '1 1:10:30' has invalid pattern
    """
    patterns = [
        re.compile(r'^(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(r'^(?P<days>\d+)-(?P<hours>\d+)$'),
        re.compile(r'^(?P<minutes>\d+)$'),
        re.compile(r'^(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+)$'),
        re.compile(
          r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(
          r'^(?P<days>\d+):(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
    ]
    seconds = 0
    for pattern in patterns:
        match = pattern.match(str(time_str).strip())
        if match:
            if 'seconds' in match.groupdict():
                seconds += int(match.group('seconds'))
            if 'minutes' in match.groupdict():
                seconds += 60*int(match.group('minutes'))
            if 'hours' in match.groupdict():
                seconds += 3600*int(match.group('hours'))
            if 'days' in match.groupdict():
                seconds += 86400*int(match.group('days'))
            return seconds
    raise ValueError("'%s' has invalid pattern" % time_str)
Convert a string describing a time duration into seconds. The supported
    formats are::

        minutes
        minutes:seconds
        hours:minutes:seconds
        days-hours
        days-hours:minutes
        days-hours:minutes:seconds
        days:hours:minutes:seconds

    Raises:
        ValueError: if `time_str` has an invalid format.

    Examples:
        >>> time_to_seconds('10')
        600
        >>> time_to_seconds('10:00')
        600
        >>> time_to_seconds('10:30')
        630
        >>> time_to_seconds('1:10:30')
        4230
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1-0')
        86400
        >>> time_to_seconds('1-10')
        122400
        >>> time_to_seconds('1-1:10')
        90600
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1:1:10:30')
        90630
        >>> time_to_seconds('1 1:10:30')
        Traceback (most recent call last):
        ...
        ValueError: '1 1:10:30' has invalid pattern
    
Convert a string describing a time duration into seconds. The supported
formats are:.


Convert a string describing a time duration into seconds . The supported formats are : .
def time_to_seconds(time_str):
    patterns = [
        re.compile(r'^(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(r'^(?P<days>\d+)-(?P<hours>\d+)$'),
        re.compile(r'^(?P<minutes>\d+)$'),
        re.compile(r'^(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+)$'),
        re.compile(
          r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
        re.compile(
          r'^(?P<days>\d+):(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$'),
    ]
    seconds = 0
    for pattern in patterns:
        match = pattern.match(str(time_str).strip())
        if match:
            if 'seconds' in match.groupdict():
                seconds += int(match.group('seconds'))
            if 'minutes' in match.groupdict():
                seconds += 60*int(match.group('minutes'))
            if 'hours' in match.groupdict():
                seconds += 3600*int(match.group('hours'))
            if 'days' in match.groupdict():
                seconds += 86400*int(match.group('days'))
            return seconds
    raise ValueError("'%s' has invalid pattern" % time_str)
def time_to_seconds ( time_str ) : patterns = [ re . compile ( r'^(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$' ) , re . compile ( r'^(?P<days>\d+)-(?P<hours>\d+)$' ) , re . compile ( r'^(?P<minutes>\d+)$' ) , re . compile ( r'^(?P<minutes>\d+):(?P<seconds>\d+)$' ) , re . compile ( r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+)$' ) , re . compile ( r'^(?P<days>\d+)-(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$' ) , re . compile ( r'^(?P<days>\d+):(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)$' ) , ] seconds = 0 for pattern in patterns : match = pattern . match ( str ( time_str ) . strip ( ) ) if match : if 'seconds' in match . groupdict ( ) : seconds += int ( match . group ( 'seconds' ) ) if 'minutes' in match . groupdict ( ) : seconds += 60 * int ( match . group ( 'minutes' ) ) if 'hours' in match . groupdict ( ) : seconds += 3600 * int ( match . group ( 'hours' ) ) if 'days' in match . groupdict ( ) : seconds += 86400 * int ( match . group ( 'days' ) ) return seconds raise ValueError ( "'%s' has invalid pattern" % time_str )
Convert a string describing a time duration into seconds.
Convert a string describing a time duration into seconds .
"""Convert a string describing a time duration into seconds. The supported
    formats are::

        minutes
        minutes:seconds
        hours:minutes:seconds
        days-hours
        days-hours:minutes
        days-hours:minutes:seconds
        days:hours:minutes:seconds

    Raises:
        ValueError: if `time_str` has an invalid format.

    Examples:
        >>> time_to_seconds('10')
        600
        >>> time_to_seconds('10:00')
        600
        >>> time_to_seconds('10:30')
        630
        >>> time_to_seconds('1:10:30')
        4230
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1-0')
        86400
        >>> time_to_seconds('1-10')
        122400
        >>> time_to_seconds('1-1:10')
        90600
        >>> time_to_seconds('1-1:10:30')
        90630
        >>> time_to_seconds('1:1:10:30')
        90630
        >>> time_to_seconds('1 1:10:30')
        Traceback (most recent call last):
        ...
        ValueError: '1 1:10:30' has invalid pattern
    """
if `time_str` has an invalid format.
if ` time_str ` has an invalid format .
ValueError
time_str
examples
None