aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/manifest.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-14 16:36:41 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-17 01:16:46 +0800
commitb6f1902c7c767104700ea86896eed9b27d389344 (patch)
tree889d6cbad5b5df3efa0ec06cc0dc8d6aa4695fa9 /scripts/manifest.py
parent9556e0d27b8d592d9d6bba0b423405bf9a44b2b8 (diff)
downloadchandra-acis-analysis-b6f1902c7c767104700ea86896eed9b27d389344.tar.bz2
manifest.py: Add parameter 'splitlist' to gets() for CSV export
Diffstat (limited to 'scripts/manifest.py')
-rwxr-xr-xscripts/manifest.py27
1 files changed, 25 insertions, 2 deletions
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: