From 310e81171ab82738d1cd9f03e2b23327c42355a0 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 12 Feb 2017 17:57:18 +0800 Subject: manifest.py: Add method "gets()" to get values of a list of items --- scripts/manifest.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'scripts/manifest.py') diff --git a/scripts/manifest.py b/scripts/manifest.py index 5b476f8..7ca8695 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -20,6 +20,8 @@ and other structures in the YAML file. import os import argparse +from collections import OrderedDict + import ruamel.yaml @@ -49,13 +51,43 @@ class Manifest: """ Get the value of the specified item in the manifest. - If the specified item doesn't exist, raise a ``KeyError``. + Parameters + ---------- + key : str + The key of the item to be requested. + + Raises + ------ + KeyError : + If the specified item doesn't exist. """ if key in self.manifest: return self.manifest[key] else: raise KeyError("manifest doesn't have item: '%s'" % key) + def gets(self, keys, default=None): + """ + Get the value of the specified item in the manifest. + + Parameters + ---------- + keys : list[str] + A list of keys specifying the items to be requested. + + Returns + ------- + data : `~OrderedDict` + Ordered dictionary containing the requested items. + + Returns + ------- + """ + data = OrderedDict([ + (key, self.manifest.get(key, default)) for key in keys + ]) + return data + def set(self, key, value): """ Set the value of the specified item in the manifest. -- cgit v1.2.2