diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/collect_yaml.py | 2 | ||||
-rwxr-xr-x | scripts/manifest.py | 27 |
2 files changed, 26 insertions, 3 deletions
diff --git a/scripts/collect_yaml.py b/scripts/collect_yaml.py index 0fb5ee6..05d4684 100755 --- a/scripts/collect_yaml.py +++ b/scripts/collect_yaml.py @@ -50,7 +50,7 @@ def main(): results = [] for fp in args.infile: manifest = Manifest(fp) - res = manifest.gets(keys) + res = manifest.gets(keys, splitlist=True) if args.verbose: print("FILE:{0}: {1}".format(fp, list(res.values())), file=sys.stderr) diff --git a/scripts/manifest.py b/scripts/manifest.py index 937cb43..74e737e 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -66,14 +66,21 @@ class Manifest: else: raise KeyError("manifest doesn't have item: '%s'" % key) - def gets(self, keys, default=None): + def gets(self, keys, default=None, splitlist=False): """ Get the value of the specified item in the manifest. + TODO: splitlist + Parameters ---------- keys : list[str] A list of keys specifying the items to be requested. + default : optional + The default value to return if the item not exists. + splitlist : bool, optional + Split the item value if it is a list, making it is easier + to export as CSV format. Returns ------- @@ -86,6 +93,16 @@ class Manifest: data = OrderedDict([ (key, self.manifest.get(key, default)) for key in keys ]) + if splitlist: + ds = OrderedDict() + for k, v in data.items(): + if isinstance(v, list): + for i, vi in enumerate(v): + ki = "{0}[{1}]".format(k, i) + ds[ki] = vi + else: + ds[k] = v + data = ds return data def getpath(self, key): @@ -155,7 +172,13 @@ class Manifest: try: v = float(value) except ValueError: - v = value + # string/boolean + if value.lower() in ["true", "yes"]: + v = True + elif value.lower() in ["false", "no"]: + v = False + else: + v = value # string parsed_values.append(v) # if len(parsed_values) == 1: |