Beispiel #1
0
def get_emergency_recipients(recipient_cfg=CFG_SITE_EMERGENCY_EMAIL_ADDRESSES,
                             now=None):
    """Parse a list of appropriate emergency email recipients from
    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES, or from a provided dictionary
    comprised of 'time constraint' => 'comma separated list of addresses'

    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES format example:

    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES = {
        'Sunday 22:00-06:00': '*****@*****.**',
        '06:00-18:00': '[email protected],[email protected]',
        '18:00-06:00': '*****@*****.**',
        '*': '*****@*****.**'}
    """

    from invenio.dateutils import parse_runtime_limit

    if now is None:
        now = datetime.datetime.now()

    recipients = set()
    for time_condition, address_str in recipient_cfg.items():
        if time_condition and time_condition is not '*':
            current_range, dummy_range = parse_runtime_limit(time_condition,
                                                             now=now)
            if not current_range[0] <= now <= current_range[1]:
                continue

        recipients.add(address_str)
    return list(recipients)
Beispiel #2
0
def get_emergency_recipients(recipient_cfg=CFG_SITE_EMERGENCY_EMAIL_ADDRESSES):
    """Parse a list of appropriate emergency email recipients from
    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES, or from a provided dictionary
    comprised of 'time constraint' => 'comma separated list of addresses'

    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES format example:

    CFG_SITE_EMERGENCY_EMAIL_ADDRESSES = {
        'Sunday 22:00-06:00': '*****@*****.**',
        '06:00-18:00': '[email protected],[email protected]',
        '18:00-06:00': '*****@*****.**',
        '*': '*****@*****.**'}
    """

    from invenio.dateutils import parse_runtime_limit

    recipients = set()
    for time_condition, address_str in recipient_cfg.items():
        if time_condition and time_condition is not '*':
            (current_range, future_range) = parse_runtime_limit(time_condition)
            if not current_range[0] <= datetime.datetime.now() <= current_range[1]:
                continue

        recipients.update([address_str])
    return list(recipients)
 def test_parse_runtime_limit_days_only_3(self):
     """dateutils - parse runtime using just at the end of a week range"""
     limit = 'Mon-Fri'
     now = datetime.datetime(year=2000, month=1, day=7)
     present_from = now
     present_to = now + datetime.timedelta(days=1)
     future_from = now + datetime.timedelta(days=3)
     future_to = now + datetime.timedelta(days=4)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit, now=now)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_days_times(self):
     """dateutils - parse runtime using just a week range"""
     limit = 'Mon-Fri 06:00-18:00'
     now = datetime.datetime(year=2000, month=1, day=3)
     day = now.date()
     t = now.time()
     present_from = datetime.datetime.combine(day, t.replace(hour=6))
     present_to = datetime.datetime.combine(day, t.replace(hour=18))
     future_from = present_from + datetime.timedelta(days=1)
     future_to = present_to + datetime.timedelta(days=1)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit, now=now)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_times_only(self):
     """dateutils - parse runtime using just a time range"""
     limit = '06:00-18:00'
     day = datetime.date.today()
     now = datetime.time()
     present_from = datetime.datetime.combine(day, now.replace(hour=6))
     present_to = datetime.datetime.combine(day, now.replace(hour=18))
     if present_to <= datetime.datetime.now():
         present_from += datetime.timedelta(days=1)
         present_to += datetime.timedelta(days=1)
     future_from = present_from + datetime.timedelta(days=1)
     future_to = present_to + datetime.timedelta(days=1)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_times_only(self):
     """dateutils - parse runtime using just a time range"""
     limit = '06:00-18:00'
     day = datetime.date.today()
     now = datetime.time()
     present_from = datetime.datetime.combine(day, now.replace(hour=6))
     present_to = datetime.datetime.combine(day, now.replace(hour=18))
     if present_to <= datetime.datetime.now():
         present_from += datetime.timedelta(days=1)
         present_to += datetime.timedelta(days=1)
     future_from = present_from + datetime.timedelta(days=1)
     future_to = present_to + datetime.timedelta(days=1)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_day_abbr_only(self):
     """dateutils - parse runtime using just a weekday abbreviation"""
     limit = 'Tue'
     day = datetime.date.today()
     now = datetime.time()
     while day.weekday() != calendar.TUESDAY:
         day += datetime.timedelta(1)
     present_from = datetime.datetime.combine(day, now.replace(hour=0))
     present_to = present_from + datetime.timedelta(days=1)
     if datetime.datetime.now() >= present_to:
         present_from += datetime.timedelta(days=7)
         present_to += datetime.timedelta(days=7)
     future_from = present_from + datetime.timedelta(days=7)
     future_to = present_to + datetime.timedelta(days=7)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_day_plus_times(self):
     """dateutils - parse runtime using a weekday plus a time range"""
     limit = 'Thursday 18:00-22:00'
     day = datetime.date.today()
     now = datetime.time()
     while day.weekday() != calendar.THURSDAY:
         day += datetime.timedelta(1)
     present_from = datetime.datetime.combine(day, now.replace(hour=18))
     present_to = datetime.datetime.combine(day, now.replace(hour=22))
     if datetime.datetime.now() >= present_to:
         present_from += datetime.timedelta(days=7)
         present_to += datetime.timedelta(days=7)
     future_from = present_from + datetime.timedelta(days=7)
     future_to = present_to + datetime.timedelta(days=7)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_day_abbr_only(self):
     """dateutils - parse runtime using just a weekday abbreviation"""
     limit = 'Tue'
     day = datetime.date.today()
     now = datetime.time()
     while day.weekday() != calendar.TUESDAY:
         day += datetime.timedelta(1)
     present_from = datetime.datetime.combine(day, now.replace(hour=0))
     present_to = present_from + datetime.timedelta(days=1)
     if datetime.datetime.now() >= present_to:
         present_from += datetime.timedelta(days=7)
         present_to += datetime.timedelta(days=7)
     future_from = present_from + datetime.timedelta(days=7)
     future_to = present_to + datetime.timedelta(days=7)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
 def test_parse_runtime_limit_day_plus_times(self):
     """dateutils - parse runtime using a weekday plus a time range"""
     limit = 'Thursday 18:00-22:00'
     day = datetime.date.today()
     now = datetime.time()
     while day.weekday() != calendar.THURSDAY:
         day += datetime.timedelta(1)
     present_from = datetime.datetime.combine(day, now.replace(hour=18))
     present_to = datetime.datetime.combine(day, now.replace(hour=22))
     if datetime.datetime.now() >= present_to:
         present_from += datetime.timedelta(days=7)
         present_to += datetime.timedelta(days=7)
     future_from = present_from + datetime.timedelta(days=7)
     future_to = present_to + datetime.timedelta(days=7)
     expected = (
         (present_from, present_to),
         (future_from, future_to),
     )
     result = dateutils.parse_runtime_limit(limit)
     self.assertEqual(expected, result)
Beispiel #11
0
         elif opt[0] in ("-u", "--user"):
             _TASK_PARAMS["user"] = opt[1]
         elif opt[0] in ("-v", "--verbose"):
             _TASK_PARAMS["verbose"] = int(opt[1])
         elif opt[0] in ("-s", "--sleeptime"):
             if task_name not in CFG_TASK_IS_NOT_A_DEAMON:
                 get_datetime(opt[1])  # see if it is a valid shift
                 _TASK_PARAMS["sleeptime"] = opt[1]
         elif opt[0] in ("-t", "--runtime"):
             _TASK_PARAMS["runtime"] = get_datetime(opt[1])
         elif opt[0] in ("-P", "--priority"):
             _TASK_PARAMS["priority"] = int(opt[1])
         elif opt[0] in ("-N", "--name"):
             _TASK_PARAMS["task_specific_name"] = opt[1]
         elif opt[0] in ("-L", "--limit"):
             _TASK_PARAMS["runtime_limit"] = parse_runtime_limit(opt[1])
         elif opt[0] in ("--profile", ):
             _TASK_PARAMS["profile"] += opt[1].split(',')
         elif not callable(task_submit_elaborate_specific_parameter_fnc) or \
             not task_submit_elaborate_specific_parameter_fnc(opt[0],
                 opt[1], opts, args):
             _usage(1,
                    help_specific_usage=help_specific_usage,
                    description=description)
 except StandardError, e:
     _usage(e,
            help_specific_usage=help_specific_usage,
            description=description)
 if callable(task_submit_check_options_fnc):
     if not task_submit_check_options_fnc():
         _usage(1,
Beispiel #12
0
            elif opt[0] in ("-u", "--user"):
                _TASK_PARAMS["user"] = opt[1]
            elif opt[0] in ("-v", "--verbose"):
                _TASK_PARAMS["verbose"] = int(opt[1])
            elif opt[0] in ("-s", "--sleeptime"):
                if task_name not in CFG_TASK_IS_NOT_A_DEAMON:
                    get_datetime(opt[1])  # see if it is a valid shift
                    _TASK_PARAMS["sleeptime"] = opt[1]
            elif opt[0] in ("-t", "--runtime"):
                _TASK_PARAMS["runtime"] = get_datetime(opt[1])
            elif opt[0] in ("-P", "--priority"):
                _TASK_PARAMS["priority"] = int(opt[1])
            elif opt[0] in ("-N", "--name"):
                _TASK_PARAMS["task_specific_name"] = opt[1]
            elif opt[0] in ("-L", "--limit"):
                _TASK_PARAMS["runtime_limit"] = parse_runtime_limit(opt[1])
            elif opt[0] in ("--profile",):
                _TASK_PARAMS["profile"] += opt[1].split(",")
            elif not callable(
                task_submit_elaborate_specific_parameter_fnc
            ) or not task_submit_elaborate_specific_parameter_fnc(opt[0], opt[1], opts, args):
                _usage(1, help_specific_usage=help_specific_usage, description=description)
    except StandardError, e:
        _usage(e, help_specific_usage=help_specific_usage, description=description)
    if callable(task_submit_check_options_fnc):
        if not task_submit_check_options_fnc():
            _usage(1, help_specific_usage=help_specific_usage, description=description)


def task_set_option(key, value):
    """Set an value to key in the option dictionary of the task"""