aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-12 17:57:18 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-12 17:57:18 +0800
commit310e81171ab82738d1cd9f03e2b23327c42355a0 (patch)
tree88855286a9b961509ad387ac18dbc00fe7636396 /scripts
parent007df7d07a85eac30dde8018241b3e16dfac129b (diff)
downloadchandra-acis-analysis-310e81171ab82738d1cd9f03e2b23327c42355a0.tar.bz2
manifest.py: Add method "gets()" to get values of a list of items
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/manifest.py34
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.