tester: Refactor to use INI format files for BSP configurations.

- Add support for user condfigurations files with the --user-config.
- Add support for a $HOME/.rtemstesterrc for a user configuration.

Closes #3204.
This commit is contained in:
Chris Johns
2017-10-24 21:35:21 +11:00
parent 5251361066
commit bf58911519
105 changed files with 1577 additions and 2588 deletions

View File

@@ -36,6 +36,7 @@ from __future__ import print_function
import os
import re
import yaml
try:
import configparser
@@ -52,6 +53,23 @@ class configuration:
self.ini = None
self.macro_filter = re.compile('\$\{.+\}')
def __str__(self):
if self.ini is None:
return 'empty'
s = ['Base: %s' % (self.ini['base'])]
s += ['Files:']
for f in self.ini['files']:
s += [' %s' % (f)]
s += ['Defaults:']
for default in self.config.defaults():
s += ' ' + default
s += ['Sections:']
for section in self.config.sections():
s += [' [%s]' % (section)]
for option in self.config.options(section):
s += [' %s = %s' % (option, self.config.get(section, option))]
return os.linesep.join(s)
def get_item(self, section, label, err = True):
try:
rec = self.config.get(section, label).replace(os.linesep, ' ')
@@ -78,10 +96,14 @@ class configuration:
pass
return rec
def get_items(self, section, err = True):
def get_items(self, section, err = True, flatten = True):
try:
items = [(name, key.replace(os.linesep, ' ')) \
for name, key in self.config.items(section)]
items = []
for name, key in self.config.items(section):
if flatten:
items += [(name, key.replace(os.linesep, ' '))]
else:
items += [(name, key)]
return items
except:
if err:
@@ -102,6 +124,9 @@ class configuration:
raise error.general('config: section "%s" not found' % (section))
return []
def has_section(self, section):
return self.config.has_section(section)
def load(self, name):
#
# Load all the files.
@@ -132,6 +157,5 @@ class configuration:
for section in self.config.sections():
includes += self.comma_list(section, 'include', err = False)
def files(self):
return self.ini['files']