diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-11 14:51:55 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-11 14:51:55 +0800 |
commit | 5973ff9d9ebfc60b922ffbe5278b4c3d25695a10 (patch) | |
tree | bd70d310eb2e34e0c60ce06767256854856e515e /scripts/manifest.py | |
parent | 50259703f19bdec23cfa2b9f07098661a928c370 (diff) | |
download | chandra-acis-analysis-5973ff9d9ebfc60b922ffbe5278b4c3d25695a10.tar.bz2 |
manifest.py: Try to parse given value to integer or float
Diffstat (limited to 'scripts/manifest.py')
-rwxr-xr-x | scripts/manifest.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py index bee8e5c..aba7a64 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -55,7 +55,7 @@ class Manifest: Set the value of the specified item in the manifest. (Will add a new item or update an existing item.) """ - self.manifest[key] = value + self.manifest[key] = self.parse_value(value) self.save() def add(self, key, value): @@ -67,7 +67,7 @@ class Manifest: if key in self.manifest: raise KeyError("manifest already has item: '%s'" % key) else: - self.manifest[key] = value + self.manifest[key] = self.parse_value(value) self.save() def update(self, key, value): @@ -77,7 +77,7 @@ class Manifest: If the specified item doesn't exist, raise a ``KeyError``. """ if key in self.manifest: - self.manifest[key] = value + self.manifest[key] = self.parse_value(value) self.save() else: raise KeyError("manifest doesn't have item: '%s'" % key) @@ -89,6 +89,20 @@ class Manifest: del self.manifest[key] self.save() + @staticmethod + def parse_value(value): + """ + Try to parse the value from string to integer or float. + """ + try: + v = int(value) + except ValueError: + try: + v = float(value) + except ValueError: + v = value + return v + def find_manifest(filename="manifest.yaml"): """ |