Commit af054e37 authored by Vincent Michel's avatar Vincent Michel
Browse files

Add file interface

parent cde1223f
Pipeline #888 failed with stages
in 1 minute and 10 seconds
......@@ -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', '#', '*****'])
return {key: dict(section) for key, section in config.items()}
......@@ -456,3 +456,15 @@ def test_get_handel_version(interface):
assert interface.get_handel_version() == (1, 2, 3)
# 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'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment