Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
python-handel
Commits
af054e37
Commit
af054e37
authored
Aug 30, 2017
by
Vincent Michel
Browse files
Add file interface
parent
cde1223f
Pipeline
#888
failed with stages
in 1 minute and 10 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
handel/interface.py
View file @
af054e37
...
...
@@ -2,6 +2,9 @@
from
__future__
import
absolute_import
import
os
import
configparser
import
numpy
from
.error
import
check_error
...
...
@@ -346,3 +349,21 @@ def get_handel_version():
# int xiaMemStatistics(unsigned long *total, unsigned long *current, unsigned long *peak);
# void xiaMemSetCheckpoint(void);
# void xiaMemLeaks(char *);
# Files
def
get_config_files
(
path
):
"""Return all the ini files in path (including subdirectories)."""
return
[
os
.
path
.
join
(
dp
,
f
)
for
dp
,
dn
,
fn
in
os
.
walk
(
path
)
for
f
in
fn
if
f
.
endswith
(
'.ini'
)]
def
get_config
(
filename
):
"""Read and return the given config file as a dictionary."""
config
=
configparser
.
ConfigParser
(
comment_prefixes
=
[
'START'
,
'END'
,
'#'
,
'*****'
])
config
.
read
(
filename
)
return
{
key
:
dict
(
section
)
for
key
,
section
in
config
.
items
()}
tests/test_interface.py
View file @
af054e37
...
...
@@ -456,3 +456,15 @@ def test_get_handel_version(interface):
assert
interface
.
get_handel_version
()
==
(
1
,
2
,
3
)
m
.
assert_called_once
()
# xiaGetVersionInfo does not return an error code
# Files
def
test_get_config_files
(
interface
):
assert
interface
.
get_config_files
(
'.'
)
==
[
'./xmap.ini'
]
def
test_get_config
(
interface
):
filename
=
interface
.
get_config_files
(
'.'
)[
0
]
d
=
interface
.
get_config
(
filename
)
assert
d
[
'detector definitions'
][
'alias'
]
==
'detector1'
Write
Preview
Supports
Markdown
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