Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mkexp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esmenv
mkexp
Commits
2f08a592
Commit
2f08a592
authored
3 months ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
Config: add function to convert ISO periods to seconds (period2sec)
parent
680c949e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGES.rst
+8
-0
8 additions, 0 deletions
CHANGES.rst
doc/mkexp.fodt
+880
-884
880 additions, 884 deletions
doc/mkexp.fodt
expconfig.py
+21
-0
21 additions, 0 deletions
expconfig.py
test.py
+9
-0
9 additions, 0 deletions
test.py
with
918 additions
and
884 deletions
CHANGES.rst
+
8
−
0
View file @
2f08a592
...
...
@@ -6,6 +6,14 @@ Make Experiments!
Release Changes
---------------
Release 1.4.2
=============
Config
------
* Add function to convert ISO periods to seconds (period2sec)
Release 1.4.1
=============
...
...
This diff is collapsed.
Click to expand it.
doc/mkexp.fodt
+
880
−
884
View file @
2f08a592
This diff is collapsed.
Click to expand it.
expconfig.py
+
21
−
0
View file @
2f08a592
...
...
@@ -283,6 +283,23 @@ class ExpConfig(ConfigObj):
h
,
m
=
divmod
(
minutes
,
60
)
return
"
{0:02}:{1:02}:{2:02}
"
.
format
(
h
,
m
,
s
)
def
period2sec
(
stamp
):
# Do not support years and months for now
match
=
re
.
fullmatch
(
r
"
P(?:(?P<days>\d+)D)?
"
r
"
(?:T(?:(?P<hours>\d+)H)?
"
r
"
(?:(?P<minutes>\d+)M)?
"
r
"
(?:(?P<seconds>\d+)S)?)?
"
,
stamp
)
if
match
:
values
=
match
.
groupdict
(
0
)
return
str
(
((
int
(
values
[
'
days
'
])
*
24
+
int
(
values
[
'
hours
'
])
)
*
60
+
int
(
values
[
'
minutes
'
])
)
*
60
+
int
(
values
[
'
seconds
'
])
)
raise
ValueError
(
f
"
unsupported period
'
{
stamp
}
'"
)
def
split_date
(
value
):
'''
Re-format datetime string to list for use in namelists
'''
match
=
re
.
match
(
r
'
^0*(\d+)-0*(\d+)-0*(\d+)
'
...
...
@@ -392,6 +409,10 @@ class ExpConfig(ConfigObj):
if
match
:
return
sec2time
(
match
.
group
(
1
))
match
=
re
.
match
(
r
'
^period2sec\((.*)\)$
'
,
value
,
re
.
S
)
if
match
:
return
period2sec
(
match
.
group
(
1
))
match
=
re
.
match
(
r
'
^read\((.*)\)$
'
,
value
,
re
.
S
)
if
match
:
return
read_value
(
match
.
group
(
1
))
...
...
This diff is collapsed.
Click to expand it.
test.py
+
9
−
0
View file @
2f08a592
...
...
@@ -456,6 +456,15 @@ class ContentTestCase(MkexpSimpleTestCase):
FALSE = eval(is_set(
'
F
'
))
"""
)
def
test_period2sec
(
self
):
self
.
run_test
(
u
"""
%{VALUE}
"""
,
u
"""
93784
"""
,
u
"""
VALUE = period2sec(P1DT2H3M4S)
"""
)
def
test_initial_comment_boilerplate
(
self
):
writeconfig
(
self
.
exp_id
,
u
"""
######
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment