summaryrefslogtreecommitdiff
path: root/rtemstoolkit
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2017-10-24 21:35:21 +1100
committerChris Johns <chrisj@rtems.org>2017-10-24 22:21:35 +1100
commitbf58911519afb7ce2117dedadf3d76da436b2361 (patch)
treeaac7608d8153bc72e60164bd2183b8e625dc8730 /rtemstoolkit
parent52513610668b02c2c3991c75946aa3ed2995e206 (diff)
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.
Diffstat (limited to 'rtemstoolkit')
-rw-r--r--rtemstoolkit/configuration.py32
-rw-r--r--rtemstoolkit/macros.py37
-rw-r--r--rtemstoolkit/path.py6
3 files changed, 56 insertions, 19 deletions
diff --git a/rtemstoolkit/configuration.py b/rtemstoolkit/configuration.py
index 71ab3ca..a03b4cc 100644
--- a/rtemstoolkit/configuration.py
+++ b/rtemstoolkit/configuration.py
@@ -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']
diff --git a/rtemstoolkit/macros.py b/rtemstoolkit/macros.py
index 31f5a7e..ed8cd96 100644
--- a/rtemstoolkit/macros.py
+++ b/rtemstoolkit/macros.py
@@ -134,18 +134,19 @@ class macros:
for f in self.files:
text += '> %s%s' % (f, os.linesep)
for map in self.macros:
- if map in self.read_maps:
- if self.read_map_locked:
- rm = 'R'
- else:
- rm = 'r'
- else:
- rm = '-'
+ rm = '-'
+ for rmap in self.read_maps:
+ if rmap[4:] == '___%s' % (map):
+ if self.read_map_locked:
+ rm = 'R[%s]' % (rmap[:4])
+ else:
+ rm = 'r[%s]' % (rmap[:4])
+ break
if map == self.write_map:
wm = 'w'
else:
wm = '-'
- text += '[%s] %s%s%s' % (map, rm, wm, os.linesep)
+ text += '[%s] %s,%s%s' % (map, wm, rm, os.linesep)
for k in sorted(self.macros[map].keys()):
d = self.macros[map][k]
text += " %s:%s '%s'%s '%s'%s" % \
@@ -250,7 +251,7 @@ class macros:
return self.macros.keys()
def get_read_maps(self):
- return [rm[5:] for rm in self.read_maps]
+ return [rm[7:] for rm in self.read_maps]
def key_filter(self, key):
if key.startswith('%{') and key[-1] is '}':
@@ -493,7 +494,7 @@ class macros:
if not self.read_map_locked:
if _map in self.macros:
if _map not in self.get_read_maps():
- rm = '%04d_%s' % (len(self.read_maps), _map)
+ rm = '%04d___%s' % (len(self.read_maps), _map)
self.read_maps = sorted(self.read_maps + [rm])
return True
return False
@@ -502,17 +503,25 @@ class macros:
if not self.read_map_locked:
if _map in self.get_read_maps():
for i in range(0, len(self.read_maps)):
- if '%04d_%s' % (i, _map) == self.read_maps[i]:
+ if '%04d___%s' % (i, _map) == self.read_maps[i]:
self.read_maps.pop(i)
return True
return False
- def set_write_map(self, map):
- if map in self.macros:
- self.write_map = map
+ def set_write_map(self, _map, add = False):
+ if _map in self.macros:
+ self.write_map = _map
+ return True
+ elif add:
+ self.write_map = _map
+ self.macros[_map] = {}
return True
return False
+ def unset_write_map(self):
+ self.write_map = 'global'
+ return True
+
def lock_read_map(self):
self.read_map_locked = True
diff --git a/rtemstoolkit/path.py b/rtemstoolkit/path.py
index 15dad1b..760f4bd 100644
--- a/rtemstoolkit/path.py
+++ b/rtemstoolkit/path.py
@@ -153,7 +153,6 @@ def removeall(path):
path = host(path)
shutil.rmtree(path, onerror = _onerror)
- return
def expand(name, paths):
l = []
@@ -161,6 +160,11 @@ def expand(name, paths):
l += [join(p, name)]
return l
+def expanduser(path):
+ path = host(path)
+ path = os.path.expanduser(path)
+ return shell(path)
+
def collect_files(path_):
#
# Convert to shell paths and return shell paths.