aboutsummaryrefslogtreecommitdiffstats
path: root/acispy/manifest.py
diff options
context:
space:
mode:
Diffstat (limited to 'acispy/manifest.py')
-rw-r--r--acispy/manifest.py60
1 files changed, 34 insertions, 26 deletions
diff --git a/acispy/manifest.py b/acispy/manifest.py
index ae013ec..79fbdd5 100644
--- a/acispy/manifest.py
+++ b/acispy/manifest.py
@@ -174,36 +174,43 @@ class Manifest:
del self.manifest[key]
self.save()
+ @classmethod
+ def parse_value(self, value):
+ """
+ Parse the given (list of) value(s) from string.
+
+ If the value list only has length of 1, then just return
+ the only element without list enclosure.
+ """
+ if isinstance(value, list):
+ pv = [self.parse_value_single(v) for v in value]
+ if len(pv) == 1:
+ return pv[0]
+ else:
+ return pv
+ else:
+ return self.parse_value_single(value)
+
@staticmethod
- def parse_value(values):
+ def parse_value_single(value):
"""
- Try to parse the given (list of) value(s) from string to
- integer or float.
+ Try to parse the given value from string to integer, float, boolean
+ or string.
"""
- if not isinstance(values, list):
- values = [values]
- #
- parsed_values = []
- for value in values:
+ try:
+ v = int(value)
+ except ValueError:
try:
- v = int(value)
+ v = float(value)
except ValueError:
- try:
- v = float(value)
- except ValueError:
- # 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:
- return parsed_values[0]
- else:
- return parsed_values
+ # string/boolean
+ if value.lower() in ["true", "yes"]:
+ v = True
+ elif value.lower() in ["false", "no"]:
+ v = False
+ else:
+ v = value # string
+ return v
def find_manifest(filename="manifest.yaml", startdir=os.getcwd()):
@@ -275,7 +282,8 @@ def cmd_get(args, manifest):
if args.field:
print(value[args.field-1])
else:
- print(args.separator.join(value))
+ vs = [str(v) for v in value]
+ print(args.separator.join(vs))
else:
print(value)