Skip to content

Commit bb4e8b6

Browse files
Merge pull request #113 from seibert-media/type_conversion_from_csv
Convert string bolean values to boolean data types
2 parents 65bac67 + 5c7cbaa commit bb4e8b6

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

automatix/command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .colors import italic, yellow
1010
from .environment import PipelineEnvironment, AttributedDict, AttributedDummyDict
1111
from .progress_bar import draw_progress_bar
12+
from .config import convert_boolean_from_input
1213

1314
PERSISTENT_VARS = PVARS = AttributedDict()
1415

@@ -434,9 +435,10 @@ def _run_local_command(self, cmd: str) -> int:
434435
stdout=subprocess.PIPE,
435436
)
436437
output = proc.stdout.decode(self.env.config["encoding"])
437-
self.env.vars[self.assignment_var] = assigned_value = output.rstrip('\r\n')
438+
assigned_value = output.rstrip('\r\n')
439+
self.env.vars[self.assignment_var] = convert_boolean_from_input(assigned_value)
438440
hint = ' (trailing newline removed)' if (output.endswith('\n') or output.endswith('\r')) else ''
439-
self.env.LOG.info(f'Variable {self.assignment_var} = "{assigned_value}"{hint}')
441+
self.env.LOG.info(f'Variable {self.assignment_var} = "{self.env.vars[self.assignment_var]}"{hint}')
440442
else:
441443
proc = subprocess.run(
442444
cmd,

automatix/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def _overwrite(script: dict, key: str, data: list[str]):
166166
script.setdefault(key, {})
167167
for item in data:
168168
k, v = item.split('=')
169-
script[key][k] = v
169+
# Only convert booleans in vars, not in systems or secrets
170+
if key == 'vars':
171+
script[key][k] = convert_boolean_from_input(v)
172+
else:
173+
script[key][k] = v
170174

171175

172176
def _tupelize(string) -> tuple:
@@ -375,8 +379,12 @@ def update_script_from_row(row: dict, script: dict, index: int):
375379
key_type, key_name = key.split(':')
376380
assert key_type in SCRIPT_FIELDS.keys(), \
377381
f'First row in CSV: Field name is \'{key_type}\', but has to be one of {list(SCRIPT_FIELDS.keys())}.'
378-
script[key_type][key_name] = value
382+
script[key_type][key_name] = convert_boolean_from_input(value=value)
379383

384+
def convert_boolean_from_input(value: str) -> bool | str: #Convert "true"/"false" strings to boolean, leave everything else as is.
385+
if isinstance(value, str) and value.lower() in ('false', 'true'):
386+
return value.lower() == 'true'
387+
return value
380388

381389
class UnknownSecretTypeException(Exception):
382390
pass

0 commit comments

Comments
 (0)