Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jean-Paul Smets
slapos
Commits
287bb50b
Commit
287bb50b
authored
Nov 27, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dcron: fix conversion from systemd timespecs with steps, and add minutely/yearly aliases
parent
2e9f4c82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
slapos/recipe/dcron.py
slapos/recipe/dcron.py
+20
-9
slapos/test/recipe/test_dcron.py
slapos/test/recipe/test_dcron.py
+6
-5
No files found.
slapos/recipe/dcron.py
View file @
287bb50b
...
...
@@ -76,10 +76,12 @@ class Part(GenericBaseRecipe):
day_of_week_dict
=
dict
((
name
,
dow
)
for
dow
,
name
in
enumerate
(
"sunday monday tuesday wednesday thursday friday saturday"
.
split
())
for
name
in
(
name
,
name
[:
3
]))
symbolic_dict
=
dict
(
hourly
=
'0 * * * *'
,
symbolic_dict
=
dict
(
minutely
=
'* * * * *'
,
hourly
=
'0 * * * *'
,
daily
=
'0 0 * * *'
,
weekly
=
'0 0 * * 0'
,
monthly
=
'0 0 1 * *'
,
weekly
=
'0 0 * * 0
'
)
yearly
=
'0 0 1 1 *
'
)
def
systemd_to_cron
(
spec
):
"""Convert from systemd.time(7) calendar spec to crontab spec"""
...
...
@@ -118,13 +120,22 @@ def systemd_to_cron(spec):
raise
ValueError
month
,
day
=
day
hour
,
minute
=
time
spec
=
minute
,
hour
,
day
,
month
,
dow
for
x
,
(
y
,
z
)
in
zip
(
spec
,
((
0
,
60
),
(
0
,
24
),
(
1
,
31
),
(
1
,
12
))):
spec
=
[
minute
,
hour
,
day
,
month
,
dow
]
for
i
,
(
y
,
z
)
in
enumerate
(((
0
,
60
),
(
0
,
24
),
(
1
,
31
),
(
1
,
12
))):
x
=
spec
[
i
]
if
x
!=
'*'
:
for
x
in
x
.
split
(
','
):
x
=
map
(
int
,
x
.
split
(
'/'
,
1
))
x
[
0
]
-=
y
if
x
[
0
]
<
0
or
len
(
x
)
>
1
and
x
[
0
]
>=
x
[
1
]
or
z
<=
sum
(
x
):
a
=
x
[
0
]
-
y
if
0
<=
a
<
z
:
if
len
(
x
)
==
1
:
continue
b
=
x
[
1
]
if
b
>
0
:
a
=
(
z
-
a
-
1
)
//
b
*
b
if
a
:
spec
[
i
]
=
'%s-%s/%s'
%
(
x
[
0
],
x
[
0
]
+
a
,
b
)
continue
raise
ValueError
return
' '
.
join
(
spec
)
slapos/test/recipe/test_dcron.py
View file @
287bb50b
...
...
@@ -13,12 +13,13 @@ class TestDcron(unittest.TestCase):
_
(
"10-15"
,
"0 0 15 10 *"
)
_
(
"monday *-12-* 17:00"
,
"00 17 * 12 1"
)
_
(
"12,14,13,12:20,10,30"
,
"20,10,30 12,14,13,12 * * *"
)
# TODO: sort
_
(
"*-1/2-1,3 *:30"
,
"30 * 1,3 1/2 *"
)
_
(
"*-1/2-1,3 *:30"
,
"30 * 1,3 1
-11
/2 *"
)
_
(
"03-05 08:05"
,
"05 08 05 03 *"
)
_
(
"08:05:00"
,
"05 08 * * *"
)
_
(
"05:40"
,
"40 05 * * *"
)
_
(
"Sat,Sun 12-* 08:05"
,
"05 08 * 12 0,6"
)
_
(
"Sat,Sun 08:05"
,
"05 08 * * 0,6"
)
_
(
"*:25/20"
,
"25-45/20 * * * *"
)
def
_
(
systemd
):
self
.
assertRaises
(
Exception
,
systemd_to_cron
,
systemd
)
...
...
@@ -31,7 +32,7 @@ class TestDcron(unittest.TestCase):
_
(
"08:05:40"
)
_
(
"2003-03-05"
)
_
(
"0-1"
);
_
(
"13-1"
);
_
(
"
6/4-1"
);
_
(
"5/8
-1"
)
_
(
"1-0"
);
_
(
"1-32"
);
_
(
"1-
4/3"
);
_
(
"1-
14/18"
)
_
(
"24:0"
);
_
(
"9/9:0"
);
_
(
"8/16:0"
)
_
(
"0:60"
);
_
(
"0:
22/22"
);
_
(
"0:
15/45"
)
_
(
"0-1"
);
_
(
"13-1"
);
_
(
"
8/5
-1"
)
_
(
"1-0"
);
_
(
"1-32"
);
_
(
"1-14/18"
)
_
(
"24:0"
);
_
(
"8/16:0"
)
_
(
"0:60"
);
_
(
"0:15/45"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment