mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 06:51:10 +03:00
Merge pull request #4494 from kdelee/awxkit_remove_dateutil
Remove this dependency that we don't need Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
commit
89c41a5931
@ -1,54 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from dateutil import rrule
|
|
||||||
|
|
||||||
from awxkit.utils import to_ical
|
|
||||||
|
|
||||||
|
|
||||||
class RRule(rrule.rrule):
|
|
||||||
|
|
||||||
@property
|
|
||||||
def next_run(self):
|
|
||||||
after = self.after(datetime.utcnow())
|
|
||||||
if after is None:
|
|
||||||
return after
|
|
||||||
return after.isoformat() + 'Z'
|
|
||||||
|
|
||||||
def next_runs(self, count=1):
|
|
||||||
return [a.isoformat() + 'Z' for a in self.xafter(datetime.utcnow(),
|
|
||||||
count=count)]
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
dstart = 'DTSTART:{}'.format(to_ical(self._dtstart))
|
|
||||||
rules = []
|
|
||||||
if self._freq not in range(len(rrule.FREQNAMES)):
|
|
||||||
raise Exception('Invalid freq "{}"'.format(self._freq))
|
|
||||||
rules.append('FREQ=' + rrule.FREQNAMES[self._freq])
|
|
||||||
|
|
||||||
for name, value in [('INTERVAL', self._interval),
|
|
||||||
('WKST', self._wkst),
|
|
||||||
('COUNT', self._count)]:
|
|
||||||
if value is not None:
|
|
||||||
if name == 'WKST':
|
|
||||||
value = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'][value]
|
|
||||||
rules.append('{}={}'.format(name, value))
|
|
||||||
|
|
||||||
if self._until:
|
|
||||||
rules.append('UNTIL={}'.format(to_ical(self._until)))
|
|
||||||
|
|
||||||
for name, value in [('BYSETPOS', self._bysetpos),
|
|
||||||
('BYMONTH', self._bymonth),
|
|
||||||
('BYMONTHDAY', self._bymonthday),
|
|
||||||
('BYYEARDAY', self._byyearday),
|
|
||||||
('BYWEEKNO', self._byweekno),
|
|
||||||
('BYWEEKDAY', self._byweekday),
|
|
||||||
('BYHOUR', self._byhour),
|
|
||||||
('BYMINUTE', self._byminute),
|
|
||||||
('BYSECOND', self._bysecond), ]:
|
|
||||||
if name == "BYWEEKDAY" and value:
|
|
||||||
value = (rrule.weekdays[num] for num in value)
|
|
||||||
if value:
|
|
||||||
rules.append(name + '=' + ','.join(str(v) for v in value))
|
|
||||||
|
|
||||||
return '{0} RRULE:{1}'.format(dstart, ';'.join(rules))
|
|
||||||
|
|
||||||
__repr__ = __str__
|
|
@ -1,3 +1,2 @@
|
|||||||
PyYAML>=5.1
|
PyYAML>=5.1
|
||||||
python-dateutil
|
|
||||||
requests
|
requests
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from dateutil import rrule
|
|
||||||
from datetime import datetime
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from awxkit.rrule import RRule
|
|
||||||
from awxkit.utils import to_ical
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('frequency,expected_rrule',
|
|
||||||
[('YEARLY', 'RRULE:FREQ=YEARLY;INTERVAL=1;WKST=MO;BYMONTH={0.month};'
|
|
||||||
'BYMONTHDAY={0.day};BYHOUR={0.hour};BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
('MONTHLY', 'RRULE:FREQ=MONTHLY;INTERVAL=1;WKST=MO;BYMONTHDAY={0.day};BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
('WEEKLY', 'RRULE:FREQ=WEEKLY;INTERVAL=1;WKST=MO;BYWEEKDAY={1};BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
('DAILY', 'RRULE:FREQ=DAILY;INTERVAL=1;WKST=MO;BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
('HOURLY', 'RRULE:FREQ=HOURLY;INTERVAL=1;WKST=MO;BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
('MINUTELY', 'RRULE:FREQ=MINUTELY;INTERVAL=1;WKST=MO;BYSECOND={0.second}'),
|
|
||||||
('SECONDLY', 'RRULE:FREQ=SECONDLY;INTERVAL=1;WKST=MO')],
|
|
||||||
ids=('yearly', 'monthly', 'weekly', 'daily', 'hourly', 'minutely', 'secondly'))
|
|
||||||
def test_string_frequency(frequency, expected_rrule):
|
|
||||||
dtstart = datetime.utcnow()
|
|
||||||
rule = RRule(freq=getattr(rrule, frequency), dtstart=dtstart)
|
|
||||||
weekday_str = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'][dtstart.weekday()]
|
|
||||||
assert str(rule) == 'DTSTART:{0} {1}'.format(to_ical(dtstart), expected_rrule.format(dtstart, weekday_str))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('frequency,expected_rrule',
|
|
||||||
[(0, 'RRULE:FREQ=YEARLY;INTERVAL=1;WKST=MO;BYMONTH={0.month};'
|
|
||||||
'BYMONTHDAY={0.day};BYHOUR={0.hour};BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
(1, 'RRULE:FREQ=MONTHLY;INTERVAL=1;WKST=MO;BYMONTHDAY={0.day};BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
(2, 'RRULE:FREQ=WEEKLY;INTERVAL=1;WKST=MO;BYWEEKDAY={1};BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
(3, 'RRULE:FREQ=DAILY;INTERVAL=1;WKST=MO;BYHOUR={0.hour};'
|
|
||||||
'BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
(4, 'RRULE:FREQ=HOURLY;INTERVAL=1;WKST=MO;BYMINUTE={0.minute};BYSECOND={0.second}'),
|
|
||||||
(5, 'RRULE:FREQ=MINUTELY;INTERVAL=1;WKST=MO;BYSECOND={0.second}'),
|
|
||||||
(6, 'RRULE:FREQ=SECONDLY;INTERVAL=1;WKST=MO')],
|
|
||||||
ids=('0-yearly', '1-monthly', '2-weekly', '3-daily', '4-hourly', '5-minutely', '6-secondly'))
|
|
||||||
def test_int_frequency(frequency, expected_rrule):
|
|
||||||
dtstart = datetime.utcnow()
|
|
||||||
rule = RRule(freq=frequency, dtstart=dtstart)
|
|
||||||
weekday_str = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'][dtstart.weekday()]
|
|
||||||
assert str(rule) == 'DTSTART:{0} {1}'.format(to_ical(dtstart), expected_rrule.format(dtstart, weekday_str))
|
|
||||||
|
|
||||||
|
|
||||||
def test_count():
|
|
||||||
dtstart = datetime.utcnow()
|
|
||||||
rule = RRule(freq=rrule.YEARLY, dtstart=dtstart, count=10)
|
|
||||||
expected_rrule = ('RRULE:FREQ=YEARLY;INTERVAL=1;WKST=MO;COUNT=10;BYMONTH={0.month};'
|
|
||||||
'BYMONTHDAY={0.day};BYHOUR={0.hour};BYMINUTE={0.minute};BYSECOND={0.second}')
|
|
||||||
assert str(rule) == 'DTSTART:{0} {1}'.format(to_ical(dtstart), expected_rrule.format(dtstart))
|
|
||||||
|
|
||||||
|
|
||||||
def test_until():
|
|
||||||
dtstart = datetime.utcnow()
|
|
||||||
until = dtstart + relativedelta(years=100)
|
|
||||||
rule = RRule(freq=rrule.YEARLY, dtstart=dtstart, until=until)
|
|
||||||
expected_rrule = ('RRULE:FREQ=YEARLY;INTERVAL=1;WKST=MO;UNTIL={1};BYMONTH={0.month};'
|
|
||||||
'BYMONTHDAY={0.day};BYHOUR={0.hour};BYMINUTE={0.minute};BYSECOND={0.second}')
|
|
||||||
assert str(rule) == 'DTSTART:{0} {1}'.format(to_ical(dtstart), expected_rrule.format(dtstart, to_ical(until)))
|
|
Loading…
Reference in New Issue
Block a user