diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-12 17:57:18 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-12 17:57:18 +0800 |
commit | 310e81171ab82738d1cd9f03e2b23327c42355a0 (patch) | |
tree | 88855286a9b961509ad387ac18dbc00fe7636396 | |
parent | 007df7d07a85eac30dde8018241b3e16dfac129b (diff) | |
download | chandra-acis-analysis-310e81171ab82738d1cd9f03e2b23327c42355a0.tar.bz2 |
manifest.py: Add method "gets()" to get values of a list of items
-rwxr-xr-x | scripts/manifest.py | 34 |
1 files changed, 33 insertions, 1 deletions
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. |